1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sec.document.validation.impl;
17
18 import org.kuali.ole.sec.SecKeyConstants;
19 import org.kuali.ole.sec.businessobject.AccessSecurityRestrictionInfo;
20 import org.kuali.ole.sec.service.AccessSecurityService;
21 import org.kuali.ole.sys.businessobject.AccountingLine;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.ole.sys.document.AccountingDocument;
24 import org.kuali.ole.sys.document.validation.event.AccountingLineEvent;
25 import org.kuali.ole.sys.document.validation.event.AddAccountingLineEvent;
26 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27 import org.kuali.ole.sys.document.validation.event.UpdateAccountingLineEvent;
28 import org.kuali.ole.sys.document.validation.impl.AccountingRuleEngineRuleBase;
29 import org.kuali.rice.krad.util.GlobalVariables;
30
31
32
33
34
35 public class AccessSecurityAccountingDocumentRuleBase extends AccountingRuleEngineRuleBase {
36
37
38
39
40
41
42 @Override
43 public boolean validateForEvent(AttributedDocumentEvent event) {
44 boolean isValid = super.validateForEvent(event);
45
46 if (isValid && (event instanceof AddAccountingLineEvent || event instanceof UpdateAccountingLineEvent)) {
47 AccountingLineEvent accountingLineEvent = (AccountingLineEvent) event;
48 isValid = checkEditAccessForAccountingLine((AccountingDocument) accountingLineEvent.getDocument(), accountingLineEvent.getAccountingLine());
49 }
50
51 return isValid;
52 }
53
54
55
56
57
58
59
60
61 protected boolean checkEditAccessForAccountingLine(AccountingDocument document, AccountingLine line) {
62 boolean editAccessAllowed = true;
63
64 AccessSecurityRestrictionInfo restrictionInfo = new AccessSecurityRestrictionInfo();
65 boolean hasEditAccessPermission = getAccessSecurityService().canEditDocumentAccountingLine(document, line, GlobalVariables.getUserSession().getPerson(), restrictionInfo);
66
67 if (!hasEditAccessPermission) {
68 GlobalVariables.getMessageMap().putError(restrictionInfo.getPropertyName(), SecKeyConstants.ERROR_ACCOUNTING_LINE_ADD_OR_UPDATE, restrictionInfo.getPropertyLabel(), restrictionInfo.getRetrictedValue());
69 editAccessAllowed = false;
70 }
71
72 return editAccessAllowed;
73 }
74 private static AccessSecurityService accessSecurityService;
75 protected AccessSecurityService getAccessSecurityService() {
76 if ( accessSecurityService == null ) {
77 accessSecurityService = SpringContext.getBean(AccessSecurityService.class);
78 }
79 return accessSecurityService;
80 }
81 }