1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
package org.kuali.rice.kns.service.impl; |
14 | |
|
15 | |
import java.util.HashMap; |
16 | |
import java.util.Set; |
17 | |
|
18 | |
import org.apache.commons.beanutils.PropertyUtils; |
19 | |
import org.apache.ojb.broker.accesslayer.conversions.FieldConversionDefaultImpl; |
20 | |
import org.apache.ojb.broker.metadata.ClassDescriptor; |
21 | |
import org.kuali.rice.core.service.EncryptionService; |
22 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
23 | |
import org.kuali.rice.kns.dao.PostDataLoadEncryptionDao; |
24 | |
import org.kuali.rice.kns.exception.ClassNotPersistableException; |
25 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
26 | |
import org.kuali.rice.kns.service.PostDataLoadEncryptionService; |
27 | |
import org.kuali.rice.kns.util.OjbKualiEncryptDecryptFieldConversion; |
28 | |
|
29 | 0 | public class PostDataLoadEncryptionServiceImpl extends PersistenceServiceImplBase implements PostDataLoadEncryptionService { |
30 | |
private BusinessObjectService businessObjectService; |
31 | |
private EncryptionService encryptionService; |
32 | |
private PostDataLoadEncryptionDao postDataLoadEncryptionDao; |
33 | |
|
34 | |
public void checkArguments(Class businessObjectClass, Set<String> attributeNames) { |
35 | 0 | checkArguments(businessObjectClass, attributeNames, true); |
36 | 0 | } |
37 | |
|
38 | |
public void checkArguments(Class businessObjectClass, Set<String> attributeNames, boolean checkOjbEncryptConfig) { |
39 | 0 | if ((businessObjectClass == null) || (attributeNames == null)) { |
40 | 0 | throw new IllegalArgumentException( |
41 | |
"PostDataLoadEncryptionServiceImpl.encrypt does not allow a null business object Class or attributeNames Set"); |
42 | |
} |
43 | 0 | ClassDescriptor classDescriptor = null; |
44 | |
try { |
45 | 0 | classDescriptor = getClassDescriptor(businessObjectClass); |
46 | 0 | } catch (ClassNotPersistableException e) { |
47 | 0 | throw new IllegalArgumentException( |
48 | |
"PostDataLoadEncryptionServiceImpl.encrypt does not handle business object classes that do not have a corresponding ClassDescriptor defined in the OJB repository", |
49 | |
e); |
50 | 0 | } |
51 | 0 | for (String attributeName : attributeNames) { |
52 | 0 | if (classDescriptor.getFieldDescriptorByName(attributeName) == null) { |
53 | 0 | throw new IllegalArgumentException( |
54 | |
new StringBuffer("Attribute ") |
55 | |
.append(attributeName) |
56 | |
.append( |
57 | |
" specified to PostDataLoadEncryptionServiceImpl.encrypt is not in the OJB repository ClassDescriptor for Class ") |
58 | |
.append(businessObjectClass).toString()); |
59 | |
} |
60 | 0 | if (checkOjbEncryptConfig && !(classDescriptor.getFieldDescriptorByName(attributeName).getFieldConversion() instanceof OjbKualiEncryptDecryptFieldConversion)) { |
61 | 0 | throw new IllegalArgumentException( |
62 | |
new StringBuffer("Attribute ") |
63 | |
.append(attributeName) |
64 | |
.append(" of business object Class ") |
65 | |
.append(businessObjectClass) |
66 | |
.append( |
67 | |
" specified to PostDataLoadEncryptionServiceImpl.encrypt is not configured for encryption in the OJB repository") |
68 | |
.toString()); |
69 | |
} |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
public void createBackupTable(Class businessObjectClass) { |
74 | 0 | postDataLoadEncryptionDao.createBackupTable(getClassDescriptor(businessObjectClass).getFullTableName()); |
75 | 0 | } |
76 | |
|
77 | |
public void prepClassDescriptor(Class businessObjectClass, Set<String> attributeNames) { |
78 | 0 | ClassDescriptor classDescriptor = getClassDescriptor(businessObjectClass); |
79 | 0 | for (String attributeName : attributeNames) { |
80 | 0 | classDescriptor.getFieldDescriptorByName(attributeName).setFieldConversionClassName( |
81 | |
FieldConversionDefaultImpl.class.getName()); |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
public void truncateTable(Class businessObjectClass) { |
86 | 0 | postDataLoadEncryptionDao.truncateTable(getClassDescriptor(businessObjectClass).getFullTableName()); |
87 | 0 | } |
88 | |
|
89 | |
public void encrypt(PersistableBusinessObject businessObject, Set<String> attributeNames) { |
90 | 0 | for (String attributeName : attributeNames) { |
91 | |
try { |
92 | 0 | PropertyUtils.setProperty(businessObject, attributeName, encryptionService.encrypt(PropertyUtils |
93 | |
.getProperty(businessObject, attributeName))); |
94 | 0 | } catch (Exception e) { |
95 | 0 | throw new RuntimeException(new StringBuffer( |
96 | |
"PostDataLoadEncryptionServiceImpl caught exception while attempting to encrypt attribute ").append( |
97 | |
attributeName).append(" of Class ").append(businessObject.getClass()).toString(), e); |
98 | 0 | } |
99 | |
} |
100 | 0 | businessObjectService.save(businessObject); |
101 | 0 | } |
102 | |
|
103 | |
public void restoreClassDescriptor(Class businessObjectClass, Set<String> attributeNames) { |
104 | 0 | ClassDescriptor classDescriptor = getClassDescriptor(businessObjectClass); |
105 | 0 | for (String attributeName : attributeNames) { |
106 | 0 | classDescriptor.getFieldDescriptorByName(attributeName).setFieldConversionClassName( |
107 | |
OjbKualiEncryptDecryptFieldConversion.class.getName()); |
108 | |
} |
109 | 0 | businessObjectService.countMatching(businessObjectClass, new HashMap()); |
110 | 0 | } |
111 | |
|
112 | |
public void restoreTableFromBackup(Class businessObjectClass) { |
113 | 0 | postDataLoadEncryptionDao.restoreTableFromBackup(getClassDescriptor(businessObjectClass).getFullTableName()); |
114 | 0 | } |
115 | |
|
116 | |
public void dropBackupTable(Class businessObjectClass) { |
117 | 0 | postDataLoadEncryptionDao.dropBackupTable(getClassDescriptor(businessObjectClass).getFullTableName()); |
118 | 0 | } |
119 | |
|
120 | |
public void setPostDataLoadEncryptionDao(PostDataLoadEncryptionDao postDataLoadEncryptionDao) { |
121 | 0 | this.postDataLoadEncryptionDao = postDataLoadEncryptionDao; |
122 | 0 | } |
123 | |
|
124 | |
public void setEncryptionService(EncryptionService encryptionService) { |
125 | 0 | this.encryptionService = encryptionService; |
126 | 0 | } |
127 | |
|
128 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
129 | 0 | this.businessObjectService = businessObjectService; |
130 | 0 | } |
131 | |
} |