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 return CoreApiServiceLocator.getEncryptionService().encrypt(propertyEditor.getAsText());
49 }
50 return CoreApiServiceLocator.getEncryptionService().encrypt(getValue());
51 } catch (GeneralSecurityException e) {
52 LOG.error("Unable to encrypt value");
53 throw new RuntimeException("Unable to encrypt value.");
54 }
55 }
56
57 @Override
58 public void setAsText(String text) throws IllegalArgumentException {
59 try {
60 String value = CoreApiServiceLocator.getEncryptionService().decrypt(text);
61 if (propertyEditor != null) {
62 propertyEditor.setAsText(value);
63 } else {
64 setValue(value);
65 }
66 } catch (GeneralSecurityException e) {
67 LOG.error("Unable to decrypt value: " + text);
68 throw new RuntimeException("Unable to decrypt value.");
69 }
70 }
71
72 }