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