1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.bind;
17
18 import org.kuali.rice.core.api.CoreApiServiceLocator;
19
20 import java.beans.PropertyEditor;
21 import java.beans.PropertyEditorSupport;
22 import java.security.GeneralSecurityException;
23
24
25
26
27
28
29
30 public class UifEncryptionPropertyEditorWrapper extends PropertyEditorSupport{
31
32 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifEncryptionPropertyEditorWrapper.class);
33
34 PropertyEditor propertyEditor;
35
36
37
38
39 public UifEncryptionPropertyEditorWrapper(PropertyEditor propertyEditor) {
40 super();
41 this.propertyEditor = propertyEditor;
42 }
43
44 @Override
45 public String getAsText() {
46 try {
47 if (propertyEditor != null) {
48 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) {
49 return CoreApiServiceLocator.getEncryptionService().encrypt(propertyEditor.getAsText());
50 }
51 }
52 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) {
53 return CoreApiServiceLocator.getEncryptionService().encrypt(getValue());
54 }
55 return null;
56 } catch (GeneralSecurityException e) {
57 LOG.error("Unable to encrypt value");
58 throw new RuntimeException("Unable to encrypt value.");
59 }
60 }
61
62 @Override
63 public void setAsText(String text) throws IllegalArgumentException {
64 try {
65 String value = "";
66 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) {
67 value = CoreApiServiceLocator.getEncryptionService().decrypt(text);
68 }
69 if (propertyEditor != null) {
70 propertyEditor.setAsText(value);
71 } else {
72 setValue(value);
73 }
74 } catch (GeneralSecurityException e) {
75 LOG.error("Unable to decrypt value: " + text);
76 throw new RuntimeException("Unable to decrypt value.");
77 }
78 }
79
80 }