01: /*
02: * Copyright 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 edu.iu.uis.eden.security;
17:
18: import java.security.GeneralSecurityException;
19:
20: import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
21: import org.kuali.bus.services.KSBServiceLocator;
22:
23: public class OjbEncryptDecryptFieldConversion implements
24: FieldConversion {
25:
26: private static final long serialVersionUID = 5065288024404819443L;
27:
28: /**
29: * @see FieldConversion#javaToSql(Object)
30: */
31: public Object javaToSql(Object source) {
32: String converted = source.toString();
33:
34: try {
35: if (KSBServiceLocator.getEncryptionService().isEnabled()) {
36: converted = KSBServiceLocator.getEncryptionService()
37: .encrypt(converted);
38: }
39: } catch (GeneralSecurityException e) {
40: throw new RuntimeException(
41: "Unable to encrypt value to db: ", e);
42: }
43:
44: return converted;
45: }
46:
47: /**
48: * @see FieldConversion#sqlToJava(Object)
49: */
50: public Object sqlToJava(Object source) {
51: String converted = "";
52:
53: if (source != null) {
54: converted = source.toString();
55: }
56:
57: try {
58: if (KSBServiceLocator.getEncryptionService().isEnabled()) {
59: converted = KSBServiceLocator.getEncryptionService()
60: .decrypt(converted);
61: }
62: } catch (GeneralSecurityException e) {
63: throw new RuntimeException(
64: "Unable to decrypt value from db: ", e);
65: }
66:
67: return converted;
68: }
69:
70: }
|