View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.mask;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  
21  import java.io.Serializable;
22  
23  /**
24   * The displayMask element specifies the type of masking to
25   * be used to hide the value from un-authorized users.
26   * There are three types of masking.
27   */
28  @BeanTag(name = "mask")
29  public class Mask implements Serializable {
30      private static final long serialVersionUID = 4035984416568235531L;
31  
32      protected MaskFormatter maskFormatter;
33      protected Class<? extends MaskFormatter> maskFormatterClass;
34  
35      /**
36       * Masks a data value with the configured maskFormatter;
37       *
38       * @param value of the object
39       * @return string value of the masked object
40       */
41      public String maskValue(Object value) {
42          if (maskFormatter == null) {
43              if (maskFormatterClass != null) {
44                  try {
45                      maskFormatter = maskFormatterClass.newInstance();
46                  } catch (Exception e) {
47                      throw new RuntimeException(
48                              "Unable to create instance of mask formatter class: " + maskFormatterClass.getName());
49                  }
50              } else {
51                  throw new RuntimeException("Mask formatter not set for secure field.");
52              }
53          }
54  
55          return maskFormatter.maskValue(value);
56      }
57  
58      /**
59       * Gets the maskFormatter attribute.
60       *
61       * @return Returns the maskFormatter.
62       */
63      @BeanTagAttribute(name = "maskFormater", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
64      public MaskFormatter getMaskFormatter() {
65          return maskFormatter;
66      }
67  
68      /**
69       * @param maskFormatter instance to be used for masking field values.
70       */
71      public void setMaskFormatter(MaskFormatter maskFormatter) {
72          this.maskFormatter = maskFormatter;
73      }
74  
75      /**
76       * Gets the maskFormatterClass attribute.
77       *
78       * @return Returns the maskFormatterClass.
79       */
80      @BeanTagAttribute(name = "maskFormatterClass", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
81      public Class<? extends MaskFormatter> getMaskFormatterClass() {
82          return maskFormatterClass;
83      }
84  
85      /**
86       * @param maskFormatterClass element is used when a custom masking
87       * algorithm is desired.  This element specifies the name of a
88       * class that will perform the masking for unauthorized users.
89       */
90      public void setMaskFormatterClass(Class<? extends MaskFormatter> maskFormatterClass) {
91          this.maskFormatterClass = maskFormatterClass;
92      }
93  
94  }