| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Mask |
|
| 2.0;2 |
| 1 | /* | |
| 2 | * Copyright 2006-2007 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.kns.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 | 0 | 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 | 0 | if (maskFormatter == null) { |
| 38 | 0 | if (maskFormatterClass != null) { |
| 39 | try { | |
| 40 | 0 | maskFormatter = maskFormatterClass.newInstance(); |
| 41 | 0 | } catch (Exception e) { |
| 42 | 0 | throw new RuntimeException("Unable to create instance of mask formatter class: " + maskFormatterClass.getName()); |
| 43 | 0 | } |
| 44 | } | |
| 45 | else { | |
| 46 | 0 | throw new RuntimeException("Mask formatter not set for secure field."); |
| 47 | } | |
| 48 | } | |
| 49 | ||
| 50 | 0 | return maskFormatter.maskValue(value); |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Gets the maskFormatter attribute. | |
| 55 | * | |
| 56 | * @return Returns the maskFormatter. | |
| 57 | */ | |
| 58 | public MaskFormatter getMaskFormatter() { | |
| 59 | 0 | 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 | 0 | this.maskFormatter = maskFormatter; |
| 68 | 0 | } |
| 69 | ||
| 70 | /** | |
| 71 | * Gets the maskFormatterClass attribute. | |
| 72 | * | |
| 73 | * @return Returns the maskFormatterClass. | |
| 74 | */ | |
| 75 | public Class<? extends MaskFormatter> getMaskFormatterClass() { | |
| 76 | 0 | 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 | 0 | this.maskFormatterClass = maskFormatterClass; |
| 86 | 0 | } |
| 87 | ||
| 88 | } |