Coverage Report - org.kuali.rice.kns.util.OjbKualiEncryptDecryptFieldConversion
 
Classes in this File Line Coverage Branch Coverage Complexity
OjbKualiEncryptDecryptFieldConversion
0%
0/17
0%
0/6
4.5
 
 1  
 /*
 2  
  * Copyright 2006-2008 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 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.rice.kns.util;
 17  
 
 18  
 import java.security.GeneralSecurityException;
 19  
 
 20  
 import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
 21  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 22  
 
 23  
 
 24  
 /**
 25  
  * This class calls core service to encrypt values going to the database and decrypt values coming back from the database.
 26  
  * 
 27  
  * 
 28  
  */
 29  
 
 30  0
 public class OjbKualiEncryptDecryptFieldConversion implements FieldConversion {
 31  
     private static final long serialVersionUID = 2450111778124335242L;
 32  
 
 33  
     /**
 34  
      * @see FieldConversion#javaToSql(Object)
 35  
      */
 36  
     public Object javaToSql(Object source) {
 37  0
         Object converted = source;
 38  
 
 39  
         try {
 40  
                 //check if the encryption service is enable before using it
 41  0
                 if(KNSServiceLocator.getEncryptionService().isEnabled()) {
 42  0
                     converted = KNSServiceLocator.getEncryptionService().encrypt(converted);
 43  
                 }
 44  
         }
 45  0
         catch (GeneralSecurityException e) {
 46  0
             throw new RuntimeException("Unable to encrypt value to db: " + e.getMessage());
 47  0
         }
 48  
 
 49  0
         return converted;
 50  
     }
 51  
 
 52  
     /**
 53  
      * @see FieldConversion#sqlToJava(Object)
 54  
      */
 55  
     public Object sqlToJava(Object source) {
 56  0
         String converted = "";
 57  0
         if (source != null) {
 58  0
             converted = source.toString();
 59  
         }
 60  
 
 61  
         try {
 62  
                 //check if the encryption service is enable before using it
 63  0
                 if(KNSServiceLocator.getEncryptionService().isEnabled()) {
 64  0
                     converted = KNSServiceLocator.getEncryptionService().decrypt(converted);
 65  
                 }
 66  
         }
 67  0
         catch (GeneralSecurityException e) {
 68  0
             throw new RuntimeException("Unable to decrypt value from db: " + e.getMessage());
 69  0
         }
 70  
 
 71  0
         return converted;
 72  
     }
 73  
 }