| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
} |