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 public class UifEncryptionPropertyEditorWrapper extends PropertyEditorSupport {
29 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifKnsFormatterPropertyEditor.class);
30
31 PropertyEditor propertyEditor;
32
33
34
35
36 public UifEncryptionPropertyEditorWrapper(PropertyEditor propertyEditor) {
37 super();
38 this.propertyEditor = propertyEditor;
39 }
40
41 @Override
42 public String getAsText() {
43 try {
44 if (propertyEditor != null) {
45 return CoreApiServiceLocator.getEncryptionService().encrypt(propertyEditor.getAsText());
46 }
47 return CoreApiServiceLocator.getEncryptionService().encrypt(getValue());
48 } catch (GeneralSecurityException e) {
49 LOG.error("Unable to encrypt value");
50 throw new RuntimeException("Unable to encrypt value.");
51 }
52 }
53
54 @Override
55 public void setAsText(String text) throws IllegalArgumentException {
56 try {
57 String value = CoreApiServiceLocator.getEncryptionService().decrypt(text);
58 if (propertyEditor != null) {
59 propertyEditor.setAsText(value);
60 } else {
61 setValue(value);
62 }
63 } catch (GeneralSecurityException e) {
64 LOG.error("Unable to decrypt value: " + text);
65 throw new RuntimeException("Unable to decrypt value.");
66 }
67 }
68
69 }