| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.doctype.service.impl; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator; |
| 20 | |
import org.kuali.rice.kew.doctype.DocumentTypePolicyEnum; |
| 21 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 22 | |
import org.kuali.rice.kew.doctype.service.DocumentTypePermissionService; |
| 23 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 24 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 25 | |
import org.kuali.rice.kim.api.group.GroupService; |
| 26 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
| 27 | |
import org.kuali.rice.kim.service.PermissionService; |
| 28 | |
import org.kuali.rice.kim.util.KimConstants; |
| 29 | |
import org.kuali.rice.krad.datadictionary.DocumentEntry; |
| 30 | |
import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry; |
| 31 | |
import org.kuali.rice.krad.document.Document; |
| 32 | |
import org.kuali.rice.krad.document.MaintenanceDocument; |
| 33 | |
import org.kuali.rice.krad.document.authorization.DocumentAuthorizerBase; |
| 34 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
| 35 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 36 | |
import org.kuali.rice.krad.util.KRADUtils; |
| 37 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
| 38 | |
import org.kuali.rice.ksb.api.cache.RiceCacheAdministrator; |
| 39 | |
|
| 40 | |
import java.util.ArrayList; |
| 41 | |
import java.util.HashMap; |
| 42 | |
import java.util.List; |
| 43 | |
import java.util.Map; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 0 | public class DocumentTypePermissionServiceImpl implements DocumentTypePermissionService { |
| 52 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentTypePermissionServiceImpl.class); |
| 53 | |
|
| 54 | |
public static final String DOC_TYPE_PERM_CACHE_PREFIX = DOC_TYPE_PERM_CACHE_GROUP + ":"; |
| 55 | |
public static final String BLANKET_APPROVE_CACHE_PREFIX = DOC_TYPE_PERM_CACHE_PREFIX + "BlanketApprove:"; |
| 56 | |
public static final String PRINCIPAL_ADHOC_CACHE_PREFIX = DOC_TYPE_PERM_CACHE_PREFIX + "PrincipalAdhoc:"; |
| 57 | |
public static final String GROUP_ADHOC_CACHE_PREFIX = DOC_TYPE_PERM_CACHE_PREFIX + "GroupAdhoc:"; |
| 58 | |
public static final String ADMIN_ROUTING_CACHE_PREFIX = DOC_TYPE_PERM_CACHE_PREFIX + "AdminRouting:"; |
| 59 | |
public static final String CANCEL_CACHE_PREFIX = DOC_TYPE_PERM_CACHE_PREFIX + "Cancel:"; |
| 60 | |
|
| 61 | |
private RiceCacheAdministrator cacheAdministrator; |
| 62 | |
|
| 63 | |
protected RiceCacheAdministrator getCacheAdministrator() { |
| 64 | 0 | if ( cacheAdministrator == null ) { |
| 65 | 0 | cacheAdministrator = KsbApiServiceLocator.getCacheAdministrator(); |
| 66 | |
} |
| 67 | 0 | return cacheAdministrator; |
| 68 | |
} |
| 69 | |
|
| 70 | |
public boolean canBlanketApprove(String principalId, DocumentType documentType, String documentStatus, String initiatorPrincipalId) { |
| 71 | 0 | validatePrincipalId(principalId); |
| 72 | 0 | validateDocumentType(documentType); |
| 73 | 0 | validateDocumentStatus(documentStatus); |
| 74 | 0 | validatePrincipalId(initiatorPrincipalId); |
| 75 | |
|
| 76 | 0 | String cacheKey = buildBlanketApproveCacheKey(principalId, documentType, documentStatus, initiatorPrincipalId); |
| 77 | 0 | Boolean result = (Boolean)getCacheAdministrator().getFromCache(cacheKey); |
| 78 | 0 | if ( result == null ) { |
| 79 | 0 | if (documentType.isBlanketApproveGroupDefined()) { |
| 80 | 0 | boolean initiatorAuthorized = true; |
| 81 | 0 | if (documentType.getInitiatorMustBlanketApprovePolicy().getPolicyValue()) { |
| 82 | 0 | initiatorAuthorized = executeInitiatorPolicyCheck(principalId, initiatorPrincipalId, documentStatus); |
| 83 | |
} |
| 84 | 0 | result = initiatorAuthorized && documentType.isBlanketApprover(principalId); |
| 85 | 0 | } else { |
| 86 | 0 | Map<String, String> permissionDetails = buildDocumentTypePermissionDetails(documentType); |
| 87 | 0 | result = getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, KEWConstants.BLANKET_APPROVE_PERMISSION, permissionDetails, new HashMap<String, String>()); |
| 88 | |
} |
| 89 | 0 | getCacheAdministrator().putInCache(cacheKey, result, DOC_TYPE_PERM_CACHE_GROUP); |
| 90 | |
} |
| 91 | 0 | return result; |
| 92 | |
} |
| 93 | |
|
| 94 | |
protected String buildBlanketApproveCacheKey( String principalId, DocumentType documentType, String documentStatus, String initiatorPrincipalId ) { |
| 95 | 0 | return BLANKET_APPROVE_CACHE_PREFIX + documentType.getName() + "/" + documentStatus + "/" + principalId + "/" + initiatorPrincipalId; |
| 96 | |
} |
| 97 | |
|
| 98 | |
public boolean canReceiveAdHocRequest(String principalId, DocumentType documentType, String actionRequestType) { |
| 99 | 0 | validatePrincipalId(principalId); |
| 100 | 0 | validateDocumentType(documentType); |
| 101 | 0 | validateActionRequestType(actionRequestType); |
| 102 | |
|
| 103 | 0 | String cacheKey = buildPrincipalAdhocCacheKey(principalId, documentType, actionRequestType ); |
| 104 | 0 | Boolean result = (Boolean)getCacheAdministrator().getFromCache(cacheKey); |
| 105 | |
|
| 106 | 0 | if ( result == null ) { |
| 107 | 0 | Map<String, String> permissionDetails = buildDocumentTypeActionRequestPermissionDetails(documentType, actionRequestType); |
| 108 | 0 | if (useKimPermission(KEWConstants.KEW_NAMESPACE, KEWConstants.AD_HOC_REVIEW_PERMISSION, permissionDetails)) { |
| 109 | 0 | result = getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, KEWConstants.AD_HOC_REVIEW_PERMISSION, permissionDetails, new HashMap<String, String>()); |
| 110 | |
} else { |
| 111 | 0 | result = Boolean.TRUE; |
| 112 | |
} |
| 113 | 0 | getCacheAdministrator().putInCache(cacheKey, result, DOC_TYPE_PERM_CACHE_GROUP); |
| 114 | |
} |
| 115 | 0 | return result; |
| 116 | |
} |
| 117 | |
|
| 118 | |
protected String buildPrincipalAdhocCacheKey( String principalId, DocumentType documentType, String actionRequestType ) { |
| 119 | 0 | return PRINCIPAL_ADHOC_CACHE_PREFIX + documentType.getName() + "/" + actionRequestType + "/" + principalId; |
| 120 | |
} |
| 121 | |
|
| 122 | |
public boolean canGroupReceiveAdHocRequest(String groupId, DocumentType documentType, String actionRequestType) { |
| 123 | 0 | validateGroupId(groupId); |
| 124 | 0 | validateDocumentType(documentType); |
| 125 | 0 | validateActionRequestType(actionRequestType); |
| 126 | |
|
| 127 | 0 | String cacheKey = buildGroupAdhocCacheKey(groupId, documentType, actionRequestType ); |
| 128 | 0 | Boolean result = (Boolean)getCacheAdministrator().getFromCache(cacheKey); |
| 129 | |
|
| 130 | 0 | if ( result == null ) { |
| 131 | 0 | result = Boolean.TRUE; |
| 132 | 0 | Map<String, String> permissionDetails = buildDocumentTypeActionRequestPermissionDetails(documentType, actionRequestType); |
| 133 | 0 | if (useKimPermission(KEWConstants.KEW_NAMESPACE, KEWConstants.AD_HOC_REVIEW_PERMISSION, permissionDetails)) { |
| 134 | 0 | List<String> principalIds = getGroupService().getMemberPrincipalIds(groupId); |
| 135 | |
|
| 136 | 0 | for (String principalId : principalIds) { |
| 137 | 0 | if (!getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, KEWConstants.AD_HOC_REVIEW_PERMISSION, permissionDetails, new HashMap<String, String>())) { |
| 138 | 0 | result = Boolean.FALSE; |
| 139 | 0 | break; |
| 140 | |
} |
| 141 | |
} |
| 142 | |
} |
| 143 | 0 | getCacheAdministrator().putInCache(cacheKey, result, DOC_TYPE_PERM_CACHE_GROUP); |
| 144 | |
} |
| 145 | 0 | return result; |
| 146 | |
} |
| 147 | |
|
| 148 | |
protected String buildGroupAdhocCacheKey( String groupId, DocumentType documentType, String actionRequestType ) { |
| 149 | 0 | return GROUP_ADHOC_CACHE_PREFIX + documentType.getName() + "/" + actionRequestType + "/" + groupId; |
| 150 | |
} |
| 151 | |
|
| 152 | |
public boolean canAdministerRouting(String principalId, DocumentType documentType) { |
| 153 | 0 | validatePrincipalId(principalId); |
| 154 | 0 | validateDocumentType(documentType); |
| 155 | |
|
| 156 | 0 | String cacheKey = buildAdminRoutingCacheKey(principalId, documentType ); |
| 157 | 0 | Boolean result = (Boolean)getCacheAdministrator().getFromCache(cacheKey); |
| 158 | |
|
| 159 | 0 | if ( result == null ) { |
| 160 | 0 | if (documentType.isSuperUserGroupDefined()) { |
| 161 | 0 | result = documentType.isSuperUser(principalId); |
| 162 | |
} else { |
| 163 | 0 | Map<String, String> permissionDetails = buildDocumentTypePermissionDetails(documentType); |
| 164 | 0 | result = getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, KEWConstants.ADMINISTER_ROUTING_PERMISSION, permissionDetails, new HashMap<String, String>()); |
| 165 | |
} |
| 166 | 0 | getCacheAdministrator().putInCache(cacheKey, result, DOC_TYPE_PERM_CACHE_GROUP); |
| 167 | |
} |
| 168 | |
|
| 169 | 0 | return result; |
| 170 | |
} |
| 171 | |
|
| 172 | |
protected String buildAdminRoutingCacheKey( String principalId, DocumentType documentType ) { |
| 173 | 0 | return ADMIN_ROUTING_CACHE_PREFIX + documentType.getName() + "/" + principalId; |
| 174 | |
} |
| 175 | |
|
| 176 | |
public boolean canCancel(String principalId, String documentId, DocumentType documentType, List<String> routeNodeNames, String documentStatus, String initiatorPrincipalId) { |
| 177 | 0 | validatePrincipalId(principalId); |
| 178 | 0 | validateDocumentType(documentType); |
| 179 | 0 | validateRouteNodeNames(routeNodeNames); |
| 180 | 0 | validateDocumentStatus(documentStatus); |
| 181 | 0 | validatePrincipalId(initiatorPrincipalId); |
| 182 | |
|
| 183 | 0 | if (!documentType.isPolicyDefined(DocumentTypePolicyEnum.INITIATOR_MUST_CANCEL)) { |
| 184 | 0 | List<Map<String, String>> permissionDetailList = buildDocumentTypePermissionDetails(documentType, routeNodeNames, documentStatus); |
| 185 | |
|
| 186 | 0 | boolean foundAtLeastOnePermission = false; |
| 187 | |
|
| 188 | 0 | for (Map<String, String> permissionDetails : permissionDetailList) { |
| 189 | 0 | Map<String, String> roleQualifiers = buildDocumentIdRoleDocumentTypeDocumentStatusQualifiers(documentType, documentStatus, documentId, permissionDetails.get(KEWConstants.ROUTE_NODE_NAME_DETAIL)); |
| 190 | 0 | if (useKimPermission(KEWConstants.KEW_NAMESPACE, KEWConstants.CANCEL_PERMISSION, permissionDetails)) { |
| 191 | 0 | foundAtLeastOnePermission = true; |
| 192 | 0 | if (getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, KEWConstants.CANCEL_PERMISSION, permissionDetails, roleQualifiers)) { |
| 193 | 0 | return true; |
| 194 | |
} |
| 195 | |
} |
| 196 | 0 | } |
| 197 | |
|
| 198 | 0 | if (foundAtLeastOnePermission) { |
| 199 | 0 | return false; |
| 200 | |
} |
| 201 | |
} |
| 202 | |
|
| 203 | 0 | if (documentType.getInitiatorMustCancelPolicy().getPolicyValue()) { |
| 204 | 0 | return executeInitiatorPolicyCheck(principalId, initiatorPrincipalId, documentStatus); |
| 205 | |
} else { |
| 206 | 0 | return true; |
| 207 | |
} |
| 208 | |
} |
| 209 | |
|
| 210 | |
public boolean canInitiate(String principalId, DocumentType documentType) { |
| 211 | 0 | validatePrincipalId(principalId); |
| 212 | 0 | validateDocumentType(documentType); |
| 213 | |
|
| 214 | 0 | Map<String, String> permissionDetails = buildDocumentTypePermissionDetails(documentType); |
| 215 | 0 | if (useKimPermission(KRADConstants.KUALI_RICE_SYSTEM_NAMESPACE, KEWConstants.INITIATE_PERMISSION, permissionDetails)) { |
| 216 | 0 | return getPermissionService().isAuthorizedByTemplateName(principalId, KRADConstants.KUALI_RICE_SYSTEM_NAMESPACE, KEWConstants.INITIATE_PERMISSION, permissionDetails, new HashMap<String, String>()); |
| 217 | |
} |
| 218 | 0 | return true; |
| 219 | |
} |
| 220 | |
|
| 221 | |
public boolean canRoute(String principalId, DocumentRouteHeaderValue documentRouteHeaderValue) { |
| 222 | 0 | return canRoute(principalId, documentRouteHeaderValue.getDocumentId(), documentRouteHeaderValue.getDocumentType(), |
| 223 | |
documentRouteHeaderValue.getDocRouteStatus(), documentRouteHeaderValue.getInitiatorWorkflowId()); |
| 224 | |
} |
| 225 | |
|
| 226 | |
public boolean canRoute(String principalId, String documentId, DocumentType documentType, String documentStatus, String initiatorPrincipalId) { |
| 227 | 0 | validatePrincipalId(principalId); |
| 228 | 0 | validateDocumentType(documentType); |
| 229 | 0 | validateDocumentStatus(documentStatus); |
| 230 | 0 | validatePrincipalId(initiatorPrincipalId); |
| 231 | |
|
| 232 | 0 | if (!documentType.isPolicyDefined(DocumentTypePolicyEnum.INITIATOR_MUST_ROUTE)) { |
| 233 | 0 | Map<String, String> permissionDetails = buildDocumentTypeDocumentStatusPermissionDetails(documentType, documentStatus); |
| 234 | 0 | Map<String, String> roleQualifiers = buildDocumentIdRoleDocumentTypeDocumentStatusQualifiers(documentType, documentStatus, documentId, permissionDetails.get(KEWConstants.ROUTE_NODE_NAME_DETAIL)); |
| 235 | |
|
| 236 | 0 | if (LOG.isDebugEnabled()) { |
| 237 | 0 | LOG.debug("Permission details values: " + permissionDetails); |
| 238 | 0 | LOG.debug("Role qualifiers values: " + roleQualifiers); |
| 239 | |
} |
| 240 | 0 | if (useKimPermission(KEWConstants.KEW_NAMESPACE, KEWConstants.ROUTE_PERMISSION, permissionDetails)) { |
| 241 | 0 | return getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, KEWConstants.ROUTE_PERMISSION, permissionDetails, roleQualifiers); |
| 242 | |
} |
| 243 | |
} |
| 244 | |
|
| 245 | 0 | if (documentType.getInitiatorMustRoutePolicy().getPolicyValue()) { |
| 246 | 0 | return executeInitiatorPolicyCheck(principalId, initiatorPrincipalId, documentStatus); |
| 247 | |
} |
| 248 | 0 | return true; |
| 249 | |
} |
| 250 | |
|
| 251 | |
public boolean canAddRouteLogMessage(String principalId, DocumentRouteHeaderValue documentRouteHeaderValue) { |
| 252 | 0 | return canAddRouteLogMessage(principalId, documentRouteHeaderValue.getDocumentId(), |
| 253 | |
documentRouteHeaderValue.getDocumentType(), documentRouteHeaderValue.getDocRouteStatus(), |
| 254 | |
documentRouteHeaderValue.getInitiatorWorkflowId()); |
| 255 | |
} |
| 256 | |
|
| 257 | |
public boolean canAddRouteLogMessage(String principalId, String documentId, DocumentType documentType, |
| 258 | |
String documentStatus, String initiatorPrincipalId) { |
| 259 | 0 | validatePrincipalId(principalId); |
| 260 | 0 | validateDocumentType(documentType); |
| 261 | 0 | validateDocumentStatus(documentStatus); |
| 262 | 0 | validatePrincipalId(initiatorPrincipalId); |
| 263 | |
|
| 264 | 0 | Map<String, String> permissionDetails = buildDocumentTypeDocumentStatusPermissionDetails(documentType, documentStatus); |
| 265 | 0 | Map<String, String> roleQualifiers = buildDocumentIdRoleDocumentTypeDocumentStatusQualifiers(documentType, |
| 266 | |
documentStatus, documentId, permissionDetails.get(KEWConstants.ROUTE_NODE_NAME_DETAIL)); |
| 267 | |
|
| 268 | 0 | if (LOG.isDebugEnabled()) { |
| 269 | 0 | LOG.debug("Permission details values: " + permissionDetails); |
| 270 | 0 | LOG.debug("Role qualifiers values: " + roleQualifiers); |
| 271 | |
} |
| 272 | |
|
| 273 | 0 | if (useKimPermission(KEWConstants.KEW_NAMESPACE, KEWConstants.ADD_MESSAGE_TO_ROUTE_LOG, permissionDetails)) { |
| 274 | 0 | return getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, |
| 275 | |
KEWConstants.ADD_MESSAGE_TO_ROUTE_LOG, permissionDetails, roleQualifiers); |
| 276 | |
} |
| 277 | |
|
| 278 | 0 | return false; |
| 279 | |
} |
| 280 | |
|
| 281 | |
public boolean canSave(String principalId, String documentId, DocumentType documentType, List<String> routeNodeNames, String documentStatus, String initiatorPrincipalId) { |
| 282 | 0 | validatePrincipalId(principalId); |
| 283 | 0 | validateDocumentType(documentType); |
| 284 | 0 | validateRouteNodeNames(routeNodeNames); |
| 285 | 0 | validateDocumentStatus(documentStatus); |
| 286 | 0 | validatePrincipalId(initiatorPrincipalId); |
| 287 | |
|
| 288 | 0 | if (!documentType.isPolicyDefined(DocumentTypePolicyEnum.INITIATOR_MUST_SAVE)) { |
| 289 | 0 | List<Map<String, String>> permissionDetailList = buildDocumentTypePermissionDetails(documentType, routeNodeNames, documentStatus); |
| 290 | |
|
| 291 | 0 | boolean foundAtLeastOnePermission = false; |
| 292 | |
|
| 293 | 0 | for (Map<String, String> permissionDetails : permissionDetailList) { |
| 294 | 0 | Map<String, String> roleQualifiers = buildDocumentIdRoleDocumentTypeDocumentStatusQualifiers(documentType, documentStatus, documentId, permissionDetails.get(KEWConstants.ROUTE_NODE_NAME_DETAIL)); |
| 295 | 0 | if (useKimPermission(KEWConstants.KEW_NAMESPACE, KEWConstants.SAVE_PERMISSION, permissionDetails)) { |
| 296 | 0 | foundAtLeastOnePermission = true; |
| 297 | 0 | if (getPermissionService().isAuthorizedByTemplateName(principalId, KEWConstants.KEW_NAMESPACE, KEWConstants.SAVE_PERMISSION, permissionDetails, roleQualifiers)) { |
| 298 | 0 | return true; |
| 299 | |
} |
| 300 | |
} |
| 301 | 0 | } |
| 302 | |
|
| 303 | 0 | if (foundAtLeastOnePermission) { |
| 304 | 0 | return false; |
| 305 | |
} |
| 306 | |
} |
| 307 | |
|
| 308 | 0 | if (documentType.getInitiatorMustSavePolicy().getPolicyValue()) { |
| 309 | 0 | return executeInitiatorPolicyCheck(principalId, initiatorPrincipalId, documentStatus); |
| 310 | |
} |
| 311 | 0 | return true; |
| 312 | |
} |
| 313 | |
|
| 314 | |
protected Map<String, String> buildDocumentTypePermissionDetails(DocumentType documentType) { |
| 315 | 0 | Map<String, String> details = new HashMap<String, String>(); |
| 316 | 0 | details.put(KEWConstants.DOCUMENT_TYPE_NAME_DETAIL, documentType.getName()); |
| 317 | 0 | return details; |
| 318 | |
} |
| 319 | |
|
| 320 | |
protected Map<String, String> buildDocumentTypeActionRequestPermissionDetails(DocumentType documentType, String actionRequestCode) { |
| 321 | 0 | Map<String, String> details = buildDocumentTypePermissionDetails(documentType); |
| 322 | 0 | if (!StringUtils.isBlank(actionRequestCode)) { |
| 323 | 0 | details.put(KEWConstants.ACTION_REQUEST_CD_DETAIL, actionRequestCode); |
| 324 | |
} |
| 325 | 0 | return details; |
| 326 | |
} |
| 327 | |
|
| 328 | |
protected Map<String, String> buildDocumentTypeDocumentStatusPermissionDetails(DocumentType documentType, String documentStatus) { |
| 329 | 0 | Map<String, String> details = buildDocumentTypePermissionDetails(documentType); |
| 330 | 0 | if (!StringUtils.isBlank(documentStatus)) { |
| 331 | 0 | details.put(KEWConstants.DOCUMENT_STATUS_DETAIL, documentStatus); |
| 332 | |
} |
| 333 | 0 | return details; |
| 334 | |
} |
| 335 | |
|
| 336 | |
protected Map<String, String> buildDocumentIdRoleDocumentTypeDocumentStatusQualifiers(DocumentType documentType, String documentStatus, String documentId, String routeNodeName) { |
| 337 | 0 | Map<String, String> qualifiers = new HashMap<String, String>(); |
| 338 | 0 | qualifiers.put(KimConstants.AttributeConstants.DOCUMENT_NUMBER, documentId); |
| 339 | 0 | if (!StringUtils.isBlank(documentStatus)) { |
| 340 | 0 | qualifiers.put(KEWConstants.DOCUMENT_STATUS_DETAIL, documentStatus); |
| 341 | 0 | if (KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(documentStatus) || KEWConstants.ROUTE_HEADER_SAVED_CD.equals(documentStatus)) { |
| 342 | 0 | qualifiers.put(KimConstants.AttributeConstants.ROUTE_NODE_NAME, DocumentAuthorizerBase.PRE_ROUTING_ROUTE_NAME); |
| 343 | |
} |
| 344 | |
else { |
| 345 | 0 | qualifiers.put(KimConstants.AttributeConstants.ROUTE_NODE_NAME, routeNodeName); |
| 346 | |
} |
| 347 | |
} |
| 348 | 0 | qualifiers.put(KEWConstants.DOCUMENT_TYPE_NAME_DETAIL, documentType.getName()); |
| 349 | |
|
| 350 | 0 | DocumentEntry documentEntry = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDocumentEntry(documentType.getName()); |
| 351 | 0 | if (documentEntry != null) { |
| 352 | 0 | Class<? extends Document> documentClass = documentEntry.getDocumentClass(); |
| 353 | |
String namespaceCode; |
| 354 | 0 | if (MaintenanceDocument.class.isAssignableFrom(documentClass)) { |
| 355 | 0 | MaintenanceDocumentEntry maintenanceDocumentEntry = (MaintenanceDocumentEntry) documentEntry; |
| 356 | 0 | namespaceCode = KRADUtils.getNamespaceCode(maintenanceDocumentEntry.getDataObjectClass()); |
| 357 | 0 | } |
| 358 | |
else { |
| 359 | 0 | namespaceCode = KRADUtils.getNamespaceCode(documentClass); |
| 360 | |
} |
| 361 | 0 | qualifiers.put(KimConstants.AttributeConstants.NAMESPACE_CODE, namespaceCode); |
| 362 | |
} |
| 363 | |
|
| 364 | 0 | return qualifiers; |
| 365 | |
} |
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
protected List<Map<String, String>> buildDocumentTypePermissionDetails(DocumentType documentType, |
| 379 | |
List<String> routeNodeNames, String documentStatus) { |
| 380 | 0 | List<Map<String, String>> detailList = new ArrayList<Map<String, String>>(); |
| 381 | |
|
| 382 | 0 | for (String routeNodeName : routeNodeNames) { |
| 383 | 0 | Map<String, String> details = buildDocumentTypePermissionDetails(documentType); |
| 384 | 0 | if (KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(documentStatus) || |
| 385 | |
KEWConstants.ROUTE_HEADER_SAVED_CD.equals(documentStatus)) { |
| 386 | 0 | details.put(KEWConstants.ROUTE_NODE_NAME_DETAIL, DocumentAuthorizerBase.PRE_ROUTING_ROUTE_NAME); |
| 387 | 0 | } else if (!StringUtils.isBlank(routeNodeName)) { |
| 388 | 0 | details.put(KEWConstants.ROUTE_NODE_NAME_DETAIL, routeNodeName); |
| 389 | |
} |
| 390 | 0 | if (!StringUtils.isBlank(documentStatus)) { |
| 391 | 0 | details.put(KEWConstants.DOCUMENT_STATUS_DETAIL, documentStatus); |
| 392 | |
} |
| 393 | 0 | if (null != documentType) { |
| 394 | 0 | details.put(KEWConstants.DOCUMENT_TYPE_NAME_DETAIL, documentType.getName()); |
| 395 | |
} |
| 396 | 0 | detailList.add(details); |
| 397 | 0 | } |
| 398 | 0 | return detailList; |
| 399 | |
} |
| 400 | |
|
| 401 | |
|
| 402 | |
protected boolean useKimPermission(String namespace, String permissionTemplateName, Map<String, String> permissionDetails) { |
| 403 | 0 | Boolean b = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(KEWConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, KEWConstants.KIM_PRIORITY_ON_DOC_TYP_PERMS_IND); |
| 404 | 0 | if (b == null || b) { |
| 405 | 0 | return getPermissionService().isPermissionDefinedForTemplateName(namespace, permissionTemplateName, permissionDetails); |
| 406 | |
} |
| 407 | 0 | return false; |
| 408 | |
} |
| 409 | |
|
| 410 | |
private boolean executeInitiatorPolicyCheck(String principalId, String initiatorPrincipalId, String documentStatus) { |
| 411 | 0 | return principalId.equals(initiatorPrincipalId) || !(KEWConstants.ROUTE_HEADER_SAVED_CD.equals(documentStatus) || KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(documentStatus)); |
| 412 | |
} |
| 413 | |
|
| 414 | |
private void validatePrincipalId(String principalId) { |
| 415 | 0 | if (StringUtils.isBlank(principalId)) { |
| 416 | 0 | throw new IllegalArgumentException("Invalid principal ID, value was empty"); |
| 417 | |
} |
| 418 | 0 | } |
| 419 | |
|
| 420 | |
private void validateGroupId(String groupId) { |
| 421 | 0 | if (StringUtils.isBlank(groupId)) { |
| 422 | 0 | throw new IllegalArgumentException("Invalid group ID, value was empty"); |
| 423 | |
} |
| 424 | 0 | } |
| 425 | |
|
| 426 | |
private void validateDocumentType(DocumentType documentType) { |
| 427 | 0 | if (documentType == null) { |
| 428 | 0 | throw new IllegalArgumentException("DocumentType cannot be null"); |
| 429 | |
} |
| 430 | 0 | } |
| 431 | |
|
| 432 | |
private void validateActionRequestType(String actionRequestType) { |
| 433 | 0 | if (StringUtils.isBlank(actionRequestType)) { |
| 434 | 0 | throw new IllegalArgumentException("Invalid action request type, value was empty"); |
| 435 | |
} |
| 436 | 0 | if (!KEWConstants.ACTION_REQUEST_CODES.containsKey(actionRequestType)) { |
| 437 | 0 | throw new IllegalArgumentException("Invalid action request type was given, value was: " + actionRequestType); |
| 438 | |
} |
| 439 | 0 | } |
| 440 | |
|
| 441 | |
private void validateRouteNodeNames(List<String> routeNodeNames) { |
| 442 | 0 | if (routeNodeNames.isEmpty()) { |
| 443 | 0 | return; |
| 444 | |
|
| 445 | |
} |
| 446 | 0 | for (String routeNodeName : routeNodeNames) { |
| 447 | 0 | if (StringUtils.isBlank(routeNodeName)) { |
| 448 | 0 | throw new IllegalArgumentException("List of route node names contained an invalid route node name, value was empty"); |
| 449 | |
} |
| 450 | |
} |
| 451 | 0 | } |
| 452 | |
|
| 453 | |
private void validateDocumentStatus(String documentStatus) { |
| 454 | 0 | if (StringUtils.isBlank(documentStatus)) { |
| 455 | 0 | throw new IllegalArgumentException("Invalid document status, value was empty"); |
| 456 | |
} |
| 457 | 0 | if (!KEWConstants.DOCUMENT_STATUSES.containsKey(documentStatus)) { |
| 458 | 0 | throw new IllegalArgumentException("Invalid document status was given, value was: " + documentStatus); |
| 459 | |
} |
| 460 | 0 | } |
| 461 | |
|
| 462 | |
protected GroupService getGroupService() { |
| 463 | 0 | return KimApiServiceLocator.getGroupService(); |
| 464 | |
} |
| 465 | |
|
| 466 | |
protected PermissionService getPermissionService() { |
| 467 | 0 | return KimApiServiceLocator.getPermissionService(); |
| 468 | |
} |
| 469 | |
|
| 470 | |
} |