01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.util;
17:
18: import java.security.GeneralSecurityException;
19:
20: import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
21: import org.kuali.rice.KNSServiceLocator;
22:
23: /**
24: * This class calls core service to encrypt values going to the database and decrypt values coming back from the database.
25: *
26: *
27: */
28:
29: public class OjbKualiEncryptDecryptFieldConversion implements
30: FieldConversion {
31: private static final long serialVersionUID = 2450111778124335242L;
32:
33: /**
34: * @see FieldConversion#javaToSql(Object)
35: */
36: public Object javaToSql(Object source) {
37: Object converted = source;
38:
39: try {
40: converted = KNSServiceLocator.getEncryptionService()
41: .encrypt(converted);
42: } catch (GeneralSecurityException e) {
43: throw new RuntimeException(
44: "Unable to encrypt value to db: " + e.getMessage());
45: }
46:
47: return converted;
48: }
49:
50: /**
51: * @see FieldConversion#sqlToJava(Object)
52: */
53: public Object sqlToJava(Object source) {
54: String converted = "";
55: if (source != null) {
56: converted = source.toString();
57: }
58:
59: try {
60: converted = KNSServiceLocator.getEncryptionService()
61: .decrypt(converted);
62: } catch (GeneralSecurityException e) {
63: throw new RuntimeException(
64: "Unable to decrypt value from db: "
65: + e.getMessage());
66: }
67:
68: return converted;
69: }
70: }
|