Coverage Report - org.kuali.rice.kns.web.spring.UifEncryptionPropertyEditorWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
UifEncryptionPropertyEditorWrapper
0%
0/19
0%
0/4
3.667
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.web.spring;
 17  
 
 18  
 import java.beans.PropertyEditor;
 19  
 import java.beans.PropertyEditorSupport;
 20  
 import java.security.GeneralSecurityException;
 21  
 
 22  
 import org.kuali.rice.core.api.services.CoreApiServiceLocator;
 23  
 
 24  
 /**
 25  
  * A property editor 
 26  
  * 
 27  
  */
 28  
 public class UifEncryptionPropertyEditorWrapper extends PropertyEditorSupport {
 29  0
     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifKnsFormatterPropertyEditor.class);
 30  
 
 31  
         PropertyEditor propertyEditor;
 32  
 
 33  
     /**
 34  
      * @param formatter
 35  
      */
 36  
     public UifEncryptionPropertyEditorWrapper(PropertyEditor propertyEditor) {
 37  0
             super();
 38  0
             this.propertyEditor = propertyEditor;
 39  0
     }
 40  
 
 41  
         @Override
 42  
         public String getAsText() {
 43  
                 try {
 44  0
                         if (propertyEditor != null) {
 45  0
                                 return CoreApiServiceLocator.getEncryptionService().encrypt(propertyEditor.getAsText());
 46  
                         }
 47  0
                         return CoreApiServiceLocator.getEncryptionService().encrypt(getValue());
 48  0
                 } catch (GeneralSecurityException e) {
 49  0
                         LOG.error("Unable to encrypt value");
 50  0
             throw new RuntimeException("Unable to encrypt value.");
 51  
                 }
 52  
         }
 53  
 
 54  
         @Override
 55  
         public void setAsText(String text) throws IllegalArgumentException {
 56  
                 try {
 57  0
                         String value = CoreApiServiceLocator.getEncryptionService().decrypt(text);
 58  0
                         if (propertyEditor != null) {
 59  0
                                 propertyEditor.setAsText(value);
 60  
                         } else {
 61  0
                                 setValue(value);
 62  
                         }
 63  0
                 } catch (GeneralSecurityException e) {
 64  0
                         LOG.error("Unable to decrypt value: " + text);
 65  0
             throw new RuntimeException("Unable to decrypt value.");
 66  0
                 }
 67  0
         }
 68  
 
 69  
 }