View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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       * @see FieldConversion#javaToSql(Object)
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       * @see FieldConversion#sqlToJava(Object)
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  }