001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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     */
016    package org.kuali.kfs.sec.service.impl;
017    
018    import java.util.List;
019    
020    import org.kuali.kfs.sec.SecConstants;
021    import org.kuali.kfs.sec.document.authorization.SecTransactionalDocumentAuthorizer;
022    import org.kuali.kfs.sys.service.impl.DocumentHelperServiceImpl;
023    import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
024    import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizer;
025    import org.kuali.rice.kns.service.ParameterService;
026    
027    
028    /**
029     * Override of document helper service to return a custom document authorizer for document types that have access security restrictions
030     */
031    public class SecDocumentHelperServiceImpl extends DocumentHelperServiceImpl {
032        protected ParameterService parameterService;
033    
034        /**
035         * Checks to see if the document type has access security restrictions and if so returns a new SecTransactionalDocumentAuthorizer instance, otherwise returns the document
036         * authorizer configured in the data dictionary
037         * 
038         * @see org.kuali.rice.kns.service.impl.DocumentHelperServiceImpl#getDocumentAuthorizer(java.lang.String)
039         * @see org.kuali.kfs.sec.document.authorization.SecTransactionalDocumentAuthorizer
040         */
041        @Override
042        public DocumentAuthorizer getDocumentAuthorizer(String documentType) {
043            // get document authorizer instance configured in data dictionary
044            DocumentAuthorizer configuredDocumentAuthorizer = super.getDocumentAuthorizer(documentType);
045    
046            // list of document types configured for access security
047            List<String> documentTypes = parameterService.getParameterValues(SecConstants.ACCESS_SECURITY_NAMESPACE_CODE, SecConstants.ALL_PARAMETER_DETAIL_COMPONENT, SecConstants.SecurityParameterNames.ACCESS_SECURITY_DOCUMENT_TYPES);
048    
049            if (documentTypes.contains(documentType)) {
050                try {
051                    DocumentAuthorizer secDocumentAuthorizer = SecTransactionalDocumentAuthorizer.class.newInstance();
052                    ((SecTransactionalDocumentAuthorizer) secDocumentAuthorizer).setDocumentAuthorizer((TransactionalDocumentAuthorizer) configuredDocumentAuthorizer);
053    
054                    return secDocumentAuthorizer;
055                }
056                catch (Exception e) {
057                    throw new RuntimeException("Unable to create new instance of SecTransactionalDocumentAuthorizer: " + e.getMessage(), e);
058                }
059            }
060    
061            return configuredDocumentAuthorizer;
062        }
063    
064        /**
065         * Sets the parameterService attribute value.
066         * 
067         * @param parameterService The parameterService to set.
068         */
069        public void setParameterService(ParameterService parameterService) {
070            this.parameterService = parameterService;
071        }
072    
073    }