View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.ole.sec.service.impl;
17  
18  import org.kuali.ole.sec.document.authorization.SecTransactionalDocumentAuthorizer;
19  import org.kuali.ole.sec.service.AccessSecurityService;
20  import org.kuali.ole.sys.context.SpringContext;
21  import org.kuali.ole.sys.service.impl.DocumentHelperServiceImpl;
22  import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
23  import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizer;
24  
25  
26  /**
27   * Override of document helper service to return a custom document authorizer for document types that have access security restrictions
28   */
29  public class SecDocumentHelperServiceImpl extends DocumentHelperServiceImpl {
30      private AccessSecurityService accessSecurityService;
31  
32      /**
33       * Checks to see if the document type has access security restrictions and if so returns a new SecTransactionalDocumentAuthorizer instance, otherwise returns the document
34       * authorizer configured in the data dictionary
35       * 
36       * @see org.kuali.rice.krad.service.impl.DocumentHelperServiceImpl#getDocumentAuthorizer(java.lang.String)
37       * @see org.kuali.ole.sec.document.authorization.SecTransactionalDocumentAuthorizer
38       */
39      @Override
40      public DocumentAuthorizer getDocumentAuthorizer(String documentType) {
41          // get document authorizer instance configured in data dictionary
42          DocumentAuthorizer configuredDocumentAuthorizer = super.getDocumentAuthorizer(documentType);
43          if (getAccessSecurityService().isAccessSecurityControlledDocumentType(documentType)) {
44              if  ( configuredDocumentAuthorizer instanceof TransactionalDocumentAuthorizer ) {
45              try {
46                      SecTransactionalDocumentAuthorizer secDocumentAuthorizer = SecTransactionalDocumentAuthorizer.class.newInstance();
47                      secDocumentAuthorizer.setDocumentAuthorizer((TransactionalDocumentAuthorizer) configuredDocumentAuthorizer);
48  
49                  return secDocumentAuthorizer;
50                  } catch (Exception e) {
51                      throw new RuntimeException("Unable to create new instance of SecTransactionalDocumentAuthorizer for document type: " + documentType, e);
52              }
53              } else {
54                  throw new RuntimeException( "Original DocumentAuthorizer for " + documentType + " is not an instance of " + TransactionalDocumentAuthorizer.class.getName() + ". It can not be wrapped.  This is a configuration error." );
55              }
56          }
57  
58          return configuredDocumentAuthorizer;
59      }
60  
61      public AccessSecurityService getAccessSecurityService() {
62          if ( accessSecurityService == null ) {
63              accessSecurityService = SpringContext.getBean(AccessSecurityService.class);
64          }
65          return accessSecurityService;
66      }
67  
68  }