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.document.authorization;
017    
018    import java.util.List;
019    import java.util.Set;
020    
021    import org.kuali.kfs.sec.service.AccessSecurityService;
022    import org.kuali.kfs.sys.businessobject.AccountingLine;
023    import org.kuali.kfs.sys.context.SpringContext;
024    import org.kuali.kfs.sys.document.AccountingDocument;
025    import org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizer;
026    import org.kuali.kfs.sys.document.web.AccountingLineRenderingContext;
027    import org.kuali.kfs.sys.document.web.AccountingLineViewAction;
028    import org.kuali.rice.kim.bo.Person;
029    
030    
031    /**
032     * AccountingLineAuthorizer that wraps access security checks around another AccountingLineAuthorizer configured for the document type
033     */
034    public class SecAccountingLineAuthorizer implements AccountingLineAuthorizer {
035        protected AccountingLineAuthorizer lineAuthorizer;
036    
037        public List<AccountingLineViewAction> getActions(AccountingDocument accountingDocument, AccountingLineRenderingContext accountingLineRenderingContext, String accountingLinePropertyName, Integer lineIndex, Person currentUser, String groupTitle) {
038            return lineAuthorizer.getActions(accountingDocument, accountingLineRenderingContext, accountingLinePropertyName, lineIndex, currentUser, groupTitle);
039        }
040    
041        public Set<String> getUnviewableBlocks(AccountingDocument accountingDocument, AccountingLine accountingLine, boolean newLine, Person currentUser) {
042            return lineAuthorizer.getUnviewableBlocks(accountingDocument, accountingLine, newLine, currentUser);
043        }
044    
045        /**
046         * Makes call to check edit access security on accounting line
047         * 
048         * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizer#hasEditPermissionOnAccountingLine
049         */
050        public boolean hasEditPermissionOnAccountingLine(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, Person currentUser, boolean pageIsEditable) {
051            boolean hasEditPermission = lineAuthorizer.hasEditPermissionOnAccountingLine(accountingDocument, accountingLine, accountingLineCollectionProperty, currentUser, pageIsEditable);
052            
053            if (hasEditPermission) {
054                hasEditPermission = SpringContext.getBean(AccessSecurityService.class).canEditDocumentAccountingLine(accountingDocument, accountingLine, currentUser);
055            }
056                
057            return hasEditPermission;
058        }
059    
060        /**
061         * If access was granted to line and line authorizer allows field modify then allow field modify
062         * 
063         * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizer#hasEditPermissionOnField
064         */
065        public boolean hasEditPermissionOnField(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, String fieldName, boolean editableLine, boolean editablePage, Person currentUser) {
066            boolean hasEditPermission = lineAuthorizer.hasEditPermissionOnField(accountingDocument, accountingLine, accountingLineCollectionProperty, fieldName, editableLine, editablePage, currentUser);
067            
068            return hasEditPermission && editableLine;
069        }
070    
071        public boolean isGroupEditable(AccountingDocument accountingDocument, List<? extends AccountingLineRenderingContext> accountingLineRenderingContexts, Person currentUser) {
072            return lineAuthorizer.isGroupEditable(accountingDocument, accountingLineRenderingContexts, currentUser);
073        }
074    
075        public boolean renderNewLine(AccountingDocument accountingDocument, String accountingGroupProperty) {
076            return lineAuthorizer.renderNewLine(accountingDocument, accountingGroupProperty);
077        }
078    
079        /**
080         * Sets the lineAuthorizer attribute value.
081         * 
082         * @param lineAuthorizer The lineAuthorizer to set.
083         */
084        public void setLineAuthorizer(AccountingLineAuthorizer lineAuthorizer) {
085            this.lineAuthorizer = lineAuthorizer;
086        }
087    
088    
089    }