| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.core.framework.persistence.ojb.conversion; |
| 17 | |
|
| 18 | |
import java.security.GeneralSecurityException; |
| 19 | |
|
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.ojb.broker.accesslayer.conversions.FieldConversion; |
| 22 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
| 23 | |
import org.kuali.rice.core.api.encryption.EncryptionService; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 0 | public class OjbKualiHashFieldConversion implements FieldConversion { |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public Object javaToSql(Object source) { |
| 38 | 0 | Object converted = source; |
| 39 | 0 | if ( converted != null ) { |
| 40 | |
|
| 41 | 0 | if ( converted.toString().endsWith( EncryptionService.HASH_POST_PREFIX ) ) { |
| 42 | 0 | converted = StringUtils.stripEnd( converted.toString(), EncryptionService.HASH_POST_PREFIX ); |
| 43 | |
} else { |
| 44 | |
try { |
| 45 | 0 | converted = CoreApiServiceLocator.getEncryptionService().hash(converted); |
| 46 | 0 | } catch (GeneralSecurityException e) { |
| 47 | 0 | throw new RuntimeException("Unable to hash value to db: " + e.getMessage()); |
| 48 | 0 | } |
| 49 | |
} |
| 50 | |
} |
| 51 | |
|
| 52 | 0 | return converted; |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public Object sqlToJava(Object source) { |
| 59 | 0 | if ( source == null ) { |
| 60 | 0 | return ""; |
| 61 | |
} |
| 62 | 0 | return source.toString() + EncryptionService.HASH_POST_PREFIX; |
| 63 | |
} |
| 64 | |
} |