| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| OjbKualiEncryptDecryptFieldConversion |
|
| 4.5;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.core.framework.persistence.ojb.conversion; | |
| 17 | ||
| 18 | import java.security.GeneralSecurityException; | |
| 19 | ||
| 20 | import org.apache.ojb.broker.accesslayer.conversions.FieldConversion; | |
| 21 | import org.kuali.rice.core.api.services.CoreApiServiceLocator; | |
| 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 | 0 | public class OjbKualiEncryptDecryptFieldConversion implements FieldConversion { |
| 30 | private static final long serialVersionUID = 2450111778124335242L; | |
| 31 | ||
| 32 | /** | |
| 33 | * @see FieldConversion#javaToSql(Object) | |
| 34 | */ | |
| 35 | public Object javaToSql(Object source) { | |
| 36 | 0 | Object converted = source; |
| 37 | ||
| 38 | try { | |
| 39 | //check if the encryption service is enable before using it | |
| 40 | 0 | if(CoreApiServiceLocator.getEncryptionService().isEnabled()) { |
| 41 | 0 | converted = CoreApiServiceLocator.getEncryptionService().encrypt(converted); |
| 42 | } | |
| 43 | } | |
| 44 | 0 | catch (GeneralSecurityException e) { |
| 45 | 0 | throw new RuntimeException("Unable to encrypt value to db: " + e.getMessage()); |
| 46 | 0 | } |
| 47 | ||
| 48 | 0 | return converted; |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * @see FieldConversion#sqlToJava(Object) | |
| 53 | */ | |
| 54 | public Object sqlToJava(Object source) { | |
| 55 | 0 | String converted = ""; |
| 56 | 0 | if (source != null) { |
| 57 | 0 | converted = source.toString(); |
| 58 | } | |
| 59 | ||
| 60 | try { | |
| 61 | //check if the encryption service is enable before using it | |
| 62 | 0 | if(CoreApiServiceLocator.getEncryptionService().isEnabled()) { |
| 63 | 0 | converted = CoreApiServiceLocator.getEncryptionService().decrypt(converted); |
| 64 | } | |
| 65 | } | |
| 66 | 0 | catch (GeneralSecurityException e) { |
| 67 | 0 | throw new RuntimeException("Unable to decrypt value from db: " + e.getMessage()); |
| 68 | 0 | } |
| 69 | ||
| 70 | 0 | return converted; |
| 71 | } | |
| 72 | } |