Coverage Report - org.kuali.rice.core.web.format.EncryptionFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
EncryptionFormatter
0%
0/18
0%
0/4
3.333
 
 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.web.format;
 17  
 
 18  
 import java.security.GeneralSecurityException;
 19  
 
 20  
 import org.kuali.rice.core.api.CoreConstants;
 21  
 import org.kuali.rice.core.api.encryption.EncryptionService;
 22  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 23  
 
 24  
 /**
 25  
  * This formatter calls the encryption service to encrypt/decrypt values.
 26  
  */
 27  0
 public class EncryptionFormatter extends Formatter {
 28  
     private static final long serialVersionUID = -4109390572922205211L;
 29  
     private transient EncryptionService encryptionService;
 30  
 
 31  
     protected Object convertToObject(String target) {
 32  0
         if (Formatter.isEmptyValue(target))
 33  0
             return null;
 34  
 
 35  0
         String decryptedValue = null;
 36  
         try {
 37  0
             decryptedValue = getEncryptionFormatter().decrypt(target);
 38  0
         } catch (GeneralSecurityException e) {
 39  0
             throw new RuntimeException("Unable to decrypt value.");
 40  0
         }
 41  
 
 42  0
         return decryptedValue;
 43  
     }
 44  
 
 45  
     public Object format(Object target) {
 46  0
         String encryptedValue = null;
 47  
         try {
 48  0
             encryptedValue = getEncryptionFormatter().encrypt(target);
 49  0
         } catch (GeneralSecurityException e) {
 50  0
             throw new RuntimeException("Unable to encrypt secure field.");
 51  0
         }
 52  
 
 53  0
         return encryptedValue;
 54  
     }
 55  
     
 56  
     protected EncryptionService getEncryptionFormatter() {
 57  0
             if (this.encryptionService == null) {
 58  0
                     this.encryptionService = GlobalResourceLoader.getService(CoreConstants.Services.ENCRYPTION_SERVICE);
 59  
             }
 60  0
             return this.encryptionService;
 61  
     }
 62  
 }