| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.web.format; |
| 17 | |
|
| 18 | |
import java.security.GeneralSecurityException; |
| 19 | |
|
| 20 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | 0 | public class EncryptionFormatter extends Formatter { |
| 28 | |
private static final long serialVersionUID = -4109390572922205211L; |
| 29 | |
|
| 30 | |
protected Object convertToObject(String target) { |
| 31 | 0 | if (Formatter.isEmptyValue(target)) |
| 32 | 0 | return null; |
| 33 | |
|
| 34 | 0 | String decryptedValue = null; |
| 35 | |
try { |
| 36 | 0 | decryptedValue = KNSServiceLocator.getEncryptionService().decrypt(target); |
| 37 | |
} |
| 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 = KNSServiceLocator.getEncryptionService().encrypt(target); |
| 49 | |
} |
| 50 | 0 | catch (GeneralSecurityException e) { |
| 51 | 0 | throw new RuntimeException("Unable to encrypt secure field."); |
| 52 | 0 | } |
| 53 | |
|
| 54 | 0 | return encryptedValue; |
| 55 | |
} |
| 56 | |
} |