001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.datadictionary.mask; 017 018import java.io.Serializable; 019 020/** 021 The displayMask element specifies the type of masking to 022 be used to hide the value from un-authorized users. 023 There are three types of masking. 024 */ 025public class Mask implements Serializable { 026 private static final long serialVersionUID = 4035984416568235531L; 027 028 protected MaskFormatter maskFormatter; 029 protected Class<? extends MaskFormatter> maskFormatterClass; 030 031 /** 032 * Masks a data value with the configured maskFormatter; 033 * @param value of the object 034 * @return string value of the masked object 035 */ 036 public String maskValue(Object value) { 037 if (maskFormatter == null) { 038 if (maskFormatterClass != null) { 039 try { 040 maskFormatter = maskFormatterClass.newInstance(); 041 } catch (Exception e) { 042 throw new RuntimeException("Unable to create instance of mask formatter class: " + maskFormatterClass.getName()); 043 } 044 } 045 else { 046 throw new RuntimeException("Mask formatter not set for secure field."); 047 } 048 } 049 050 return maskFormatter.maskValue(value); 051 } 052 053 /** 054 * Gets the maskFormatter attribute. 055 * 056 * @return Returns the maskFormatter. 057 */ 058 public MaskFormatter getMaskFormatter() { 059 return maskFormatter; 060 } 061 062 /** 063 * 064 * @param maskFormatter instance to be used for masking field values. 065 */ 066 public void setMaskFormatter(MaskFormatter maskFormatter) { 067 this.maskFormatter = maskFormatter; 068 } 069 070 /** 071 * Gets the maskFormatterClass attribute. 072 * 073 * @return Returns the maskFormatterClass. 074 */ 075 public Class<? extends MaskFormatter> getMaskFormatterClass() { 076 return maskFormatterClass; 077 } 078 079 /** 080 * @param maskFormatterClass element is used when a custom masking 081 * algorithm is desired. This element specifies the name of a 082 * class that will perform the masking for unauthorized users. 083 */ 084 public void setMaskFormatterClass(Class<? extends MaskFormatter> maskFormatterClass) { 085 this.maskFormatterClass = maskFormatterClass; 086 } 087 088}