1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.ojb;
18
19 import java.security.GeneralSecurityException;
20
21 import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
22 import org.kuali.rice.kew.service.KEWServiceLocator;
23
24
25 public class OjbEncryptDecryptFieldConversion implements FieldConversion {
26
27 private static final long serialVersionUID = 5065288024404819443L;
28
29
30
31
32 public Object javaToSql(Object source) {
33 String converted = "";
34 if ( source != null ) {
35 converted = source.toString();
36 }
37
38 try {
39 if (KEWServiceLocator.getEncryptionService().isEnabled()) {
40 converted = KEWServiceLocator.getEncryptionService()
41 .encrypt(converted);
42 }
43 } catch (GeneralSecurityException e) {
44 throw new RuntimeException("Unable to encrypt value to db: ", e);
45 }
46
47 return converted;
48 }
49
50
51
52
53 public Object sqlToJava(Object source) {
54 String converted = "";
55
56 if (source != null) {
57 converted = source.toString();
58 }
59
60 try {
61 if (KEWServiceLocator.getEncryptionService().isEnabled()) {
62 converted = KEWServiceLocator.getEncryptionService()
63 .decrypt(converted);
64 }
65 } catch (GeneralSecurityException e) {
66 throw new RuntimeException("Unable to decrypt value from db: ", e);
67 }
68
69 return converted;
70 }
71
72 }