View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.service.impl;
17  
18  import org.kuali.rice.kim.api.identity.Person;
19  import org.kuali.rice.krad.datadictionary.AttributeSecurity;
20  import org.kuali.rice.krad.document.DocumentAuthorizer;
21  import org.kuali.rice.krad.document.DocumentPresentationController;
22  import org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizer;
23  import org.kuali.rice.krad.maintenance.MaintenanceDocumentPresentationController;
24  import org.kuali.rice.krad.service.DataDictionaryService;
25  import org.kuali.rice.krad.service.DataObjectAuthorizationService;
26  import org.kuali.rice.krad.service.DocumentDictionaryService;
27  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
28  
29  /**
30   * Implementation of <code>DataObjectAuthorizationService</code> that uses the
31   * configured <code>AttributeSecurity</code> for a field to determine authorization
32   * checks that need to be performed
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class DataObjectAuthorizationServiceImpl implements DataObjectAuthorizationService {
37  
38      private DataDictionaryService dataDictionaryService;
39      private DocumentDictionaryService documentDictionaryService;
40  
41      /**
42       * @see org.kuali.rice.krad.service.impl.DataObjectAuthorizationServiceImpl#attributeValueNeedsToBeEncryptedOnFormsAndLinks
43       */
44      @Override
45      public boolean attributeValueNeedsToBeEncryptedOnFormsAndLinks(Class<?> dataObjectClass, String attributeName) {
46          AttributeSecurity attributeSecurity =
47                  getDataDictionaryService().getAttributeSecurity(dataObjectClass.getName(), attributeName);
48  
49          return attributeSecurity != null && attributeSecurity.hasRestrictionThatRemovesValueFromUI();
50      }
51  
52      /**
53       * @see org.kuali.rice.krad.service.impl.DataObjectAuthorizationServiceImpl#canCreate
54       */
55      @Override
56      public boolean canCreate(Class<?> dataObjectClass, Person user, String docTypeName) {
57          DocumentPresentationController documentPresentationController =
58                  getDocumentDictionaryService().getDocumentPresentationController(docTypeName);
59          boolean canCreate =
60                  ((MaintenanceDocumentPresentationController) documentPresentationController).canCreate(dataObjectClass);
61          if (canCreate) {
62              DocumentAuthorizer documentAuthorizer = getDocumentDictionaryService().getDocumentAuthorizer(docTypeName);
63              canCreate = ((MaintenanceDocumentAuthorizer) documentAuthorizer).canCreate(dataObjectClass, user);
64          }
65          return canCreate;
66      }
67  
68      /**
69       * @see org.kuali.rice.krad.service.impl.DataObjectAuthorizationServiceImpl#canMaintain
70       */
71      @Override
72      public boolean canMaintain(Object dataObject, Person user, String docTypeName) {
73          return ((MaintenanceDocumentAuthorizer) getDocumentDictionaryService().getDocumentAuthorizer(docTypeName))
74                  .canMaintain(dataObject, user);
75      }
76  
77      protected DataDictionaryService getDataDictionaryService() {
78          if (dataDictionaryService == null) {
79              this.dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
80          }
81          return dataDictionaryService;
82      }
83  
84      public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
85          this.dataDictionaryService = dataDictionaryService;
86      }
87  
88      protected DocumentDictionaryService getDocumentDictionaryService() {
89          if (documentDictionaryService == null) {
90              documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService();
91          }
92          return documentDictionaryService;
93      }
94  
95      public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) {
96          this.documentDictionaryService = documentDictionaryService;
97      }
98  }