1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.lookup;
17
18 import org.kuali.rice.core.api.exception.RiceRuntimeException;
19 import org.kuali.rice.kim.api.KimConstants;
20 import org.kuali.rice.kim.api.identity.Person;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.uif.view.View;
23 import org.kuali.rice.krad.uif.view.ViewAuthorizerBase;
24 import org.kuali.rice.krad.uif.view.ViewModel;
25 import org.kuali.rice.krad.util.KRADConstants;
26 import org.kuali.rice.krad.util.KRADUtils;
27 import org.kuali.rice.krad.web.form.LookupForm;
28
29 import java.util.Map;
30
31
32
33
34
35
36
37 public class LookupViewAuthorizerBase extends ViewAuthorizerBase {
38 private static final long serialVersionUID = 3755133641536256283L;
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupViewAuthorizerBase.class);
40
41
42
43
44
45 @Override
46 public boolean canOpenView(View view, ViewModel model, Person user) {
47 boolean canOpen = super.canOpenView(view, model, user);
48
49 if (canOpen) {
50 LookupForm lookupForm = (LookupForm) model;
51
52 Map<String, String> additionalPermissionDetails;
53 try {
54 additionalPermissionDetails = KRADUtils.getNamespaceAndComponentSimpleName(Class.forName(
55 lookupForm.getDataObjectClassName()));
56 } catch (ClassNotFoundException e) {
57 throw new RiceRuntimeException(
58 "Unable to create class for lookup class name: " + lookupForm.getDataObjectClassName());
59 }
60
61 if (permissionExistsByTemplate(model, KRADConstants.KNS_NAMESPACE,
62 KimConstants.PermissionTemplateNames.LOOK_UP_RECORDS, additionalPermissionDetails)) {
63 canOpen = isAuthorizedByTemplate(model, KRADConstants.KNS_NAMESPACE,
64 KimConstants.PermissionTemplateNames.LOOK_UP_RECORDS, user.getPrincipalId(),
65 additionalPermissionDetails, null);
66 }
67 }
68
69 return canOpen;
70 }
71
72
73
74
75
76
77
78
79 public boolean canInitiateDocument(LookupForm lookupForm, Person user) {
80 boolean canInitiateDocument = false;
81
82 try {
83 Class<?> dataObjectClass = Class.forName(lookupForm.getDataObjectClassName());
84
85 String documentTypeName = KRADServiceLocatorWeb.getDocumentDictionaryService()
86 .getMaintenanceDocumentTypeName(dataObjectClass);
87 if ((documentTypeName != null) &&
88 KRADServiceLocatorWeb.getDocumentDictionaryService().getDocumentAuthorizer(documentTypeName)
89 .canInitiate(documentTypeName, user)) {
90 canInitiateDocument = true;
91 }
92 } catch (ClassNotFoundException e) {
93 LOG.warn("Unable to load Data Object Class: " + lookupForm.getDataObjectClassName(), e);
94 }
95
96 return canInitiateDocument;
97 }
98 }