001/* 002 * Copyright 2009 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 1.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl1.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.sec.service.impl; 017 018import org.kuali.ole.sec.document.authorization.SecTransactionalDocumentAuthorizer; 019import org.kuali.ole.sec.service.AccessSecurityService; 020import org.kuali.ole.sys.context.SpringContext; 021import org.kuali.ole.sys.service.impl.DocumentHelperServiceImpl; 022import org.kuali.rice.kns.document.authorization.DocumentAuthorizer; 023import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizer; 024 025 026/** 027 * Override of document helper service to return a custom document authorizer for document types that have access security restrictions 028 */ 029public class SecDocumentHelperServiceImpl extends DocumentHelperServiceImpl { 030 private AccessSecurityService accessSecurityService; 031 032 /** 033 * Checks to see if the document type has access security restrictions and if so returns a new SecTransactionalDocumentAuthorizer instance, otherwise returns the document 034 * authorizer configured in the data dictionary 035 * 036 * @see org.kuali.rice.krad.service.impl.DocumentHelperServiceImpl#getDocumentAuthorizer(java.lang.String) 037 * @see org.kuali.ole.sec.document.authorization.SecTransactionalDocumentAuthorizer 038 */ 039 @Override 040 public DocumentAuthorizer getDocumentAuthorizer(String documentType) { 041 // get document authorizer instance configured in data dictionary 042 DocumentAuthorizer configuredDocumentAuthorizer = super.getDocumentAuthorizer(documentType); 043 if (getAccessSecurityService().isAccessSecurityControlledDocumentType(documentType)) { 044 if ( configuredDocumentAuthorizer instanceof TransactionalDocumentAuthorizer ) { 045 try { 046 SecTransactionalDocumentAuthorizer secDocumentAuthorizer = SecTransactionalDocumentAuthorizer.class.newInstance(); 047 secDocumentAuthorizer.setDocumentAuthorizer((TransactionalDocumentAuthorizer) configuredDocumentAuthorizer); 048 049 return secDocumentAuthorizer; 050 } catch (Exception e) { 051 throw new RuntimeException("Unable to create new instance of SecTransactionalDocumentAuthorizer for document type: " + documentType, e); 052 } 053 } else { 054 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." ); 055 } 056 } 057 058 return configuredDocumentAuthorizer; 059 } 060 061 public AccessSecurityService getAccessSecurityService() { 062 if ( accessSecurityService == null ) { 063 accessSecurityService = SpringContext.getBean(AccessSecurityService.class); 064 } 065 return accessSecurityService; 066 } 067 068}