View Javadoc

1   /**
2    * Copyright 2005-2014 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 java.io.Serializable;
19  
20  /**
21      The displayMask element specifies the type of masking to
22      be used to hide the value from un-authorized users.
23      There are three types of masking.
24   */
25  public class Mask implements Serializable {   
26      private static final long serialVersionUID = 4035984416568235531L;
27      
28  	protected MaskFormatter maskFormatter;
29      protected Class<? extends MaskFormatter> maskFormatterClass;
30  
31      /**
32       * Masks a data value with the configured maskFormatter;
33       * @param value of the object
34       * @return string value of the masked object 
35       */
36      public String maskValue(Object value) {
37          if (maskFormatter == null) {
38              if (maskFormatterClass != null) {
39                  try {
40                      maskFormatter = maskFormatterClass.newInstance();
41                  } catch (Exception e) {
42                      throw new RuntimeException("Unable to create instance of mask formatter class: " + maskFormatterClass.getName());
43                  }
44              }
45              else {
46                  throw new RuntimeException("Mask formatter not set for secure field.");
47              }
48          }
49  
50          return maskFormatter.maskValue(value);
51      }
52  
53      /**
54       * Gets the maskFormatter attribute.
55       * 
56       * @return Returns the maskFormatter.
57       */
58      public MaskFormatter getMaskFormatter() {
59          return maskFormatter;
60      }
61  
62      /**
63       *
64       * @param maskFormatter instance to be used for masking field values.
65       */
66      public void setMaskFormatter(MaskFormatter maskFormatter) {
67          this.maskFormatter = maskFormatter;
68      }
69  
70      /**
71       * Gets the maskFormatterClass attribute.
72       * 
73       * @return Returns the maskFormatterClass.
74       */
75      public Class<? extends MaskFormatter> getMaskFormatterClass() {
76          return maskFormatterClass;
77      }
78  
79      /**
80       * @param maskFormatterClass element is used when a custom masking
81       * algorithm is desired.  This element specifies the name of a
82       * class that will perform the masking for unauthorized users.
83       */
84      public void setMaskFormatterClass(Class<? extends MaskFormatter> maskFormatterClass) {
85          this.maskFormatterClass = maskFormatterClass;
86      }
87  
88  }