Coverage Report - org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentAuthorizerBase
0%
0/28
0%
0/22
2
 
 1  
 /*
 2  
  * Copyright 2007 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.kns.document.authorization;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.HashSet;
 20  
 import java.util.Map;
 21  
 import java.util.Set;
 22  
 
 23  
 import org.kuali.rice.core.util.AttributeSet;
 24  
 import org.kuali.rice.kim.bo.Person;
 25  
 import org.kuali.rice.kim.util.KimConstants;
 26  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 27  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 28  
 import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService;
 29  
 import org.kuali.rice.kns.util.KNSConstants;
 30  
 import org.kuali.rice.kns.util.KNSUtils;
 31  
 
 32  0
 public class MaintenanceDocumentAuthorizerBase extends DocumentAuthorizerBase
 33  
                 implements MaintenanceDocumentAuthorizer {
 34  
         // private static final org.apache.log4j.Logger LOG =
 35  
         // org.apache.log4j.Logger.getLogger(MaintenanceDocumentAuthorizerBase.class);
 36  
 
 37  
         transient protected static MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService;
 38  
 
 39  
         public final boolean canCreate(Class boClass, Person user) {
 40  0
                 AttributeSet permissionDetails = new AttributeSet();
 41  0
                 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
 42  
                                 getMaintenanceDocumentDictionaryService().getDocumentTypeName(
 43  
                                                 boClass));
 44  0
                 permissionDetails.put(KNSConstants.MAINTENANCE_ACTN,
 45  
                                 KNSConstants.MAINTENANCE_NEW_ACTION);
 46  0
                 return !permissionExistsByTemplate(KNSConstants.KNS_NAMESPACE,
 47  
                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 48  
                                 permissionDetails)
 49  
                                 || getIdentityManagementService()
 50  
                                                 .isAuthorizedByTemplateName(
 51  
                                                                 user.getPrincipalId(),
 52  
                                                                 KNSConstants.KNS_NAMESPACE,
 53  
                                                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 54  
                                                                 permissionDetails, new AttributeSet());
 55  
         }
 56  
 
 57  
         public final boolean canMaintain(Object dataObject, Person user) {
 58  0
                 Map<String, String> permissionDetails = new HashMap<String, String>(2);
 59  0
                 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
 60  
                                 getMaintenanceDocumentDictionaryService().getDocumentTypeName(
 61  
                                                 dataObject.getClass()));
 62  0
                 permissionDetails.put(KNSConstants.MAINTENANCE_ACTN,
 63  
                                 KNSConstants.MAINTENANCE_EDIT_ACTION);
 64  0
                 return !permissionExistsByTemplate(KNSConstants.KNS_NAMESPACE,
 65  
                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 66  
                                 permissionDetails)
 67  
                                 || isAuthorizedByTemplate(
 68  
                                                 dataObject,
 69  
                                                 KNSConstants.KNS_NAMESPACE,
 70  
                                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 71  
                                                 user.getPrincipalId(), permissionDetails, null);
 72  
         }
 73  
 
 74  
         public final boolean canCreateOrMaintain(
 75  
                         MaintenanceDocument maintenanceDocument, Person user) {
 76  0
                 return !permissionExistsByTemplate(maintenanceDocument,
 77  
                                 KNSConstants.KNS_NAMESPACE,
 78  
                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS)
 79  
                                 || isAuthorizedByTemplate(
 80  
                                                 maintenanceDocument,
 81  
                                                 KNSConstants.KNS_NAMESPACE,
 82  
                                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 83  
                                                 user.getPrincipalId());
 84  
         }
 85  
 
 86  
         public Set<String> getSecurePotentiallyHiddenSectionIds() {
 87  0
                 return new HashSet<String>();
 88  
         }
 89  
 
 90  
         public Set<String> getSecurePotentiallyReadOnlySectionIds() {
 91  0
                 return new HashSet<String>();
 92  
         }
 93  
 
 94  
         @SuppressWarnings("unchecked")
 95  
         @Override
 96  
         protected void addRoleQualification(Object dataObject, Map<String, String> attributes) {
 97  0
                 super.addRoleQualification(dataObject, attributes);
 98  0
                 if (dataObject instanceof MaintenanceDocument) {
 99  0
                         MaintenanceDocument maintDoc = (MaintenanceDocument)dataObject;
 100  0
                         if ( maintDoc.getNewMaintainableObject() != null ) {                        
 101  0
                                 attributes.putAll(KNSUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getBoClass()));
 102  
                         }
 103  
                 }
 104  0
         }
 105  
 
 106  
         @SuppressWarnings("unchecked")
 107  
         @Override
 108  
         protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) {
 109  0
                 super.addPermissionDetails(dataObject, attributes);
 110  0
                 if (dataObject instanceof MaintenanceDocument) {
 111  0
                         MaintenanceDocument maintDoc = (MaintenanceDocument)dataObject;
 112  0
                         if ( maintDoc.getNewMaintainableObject() != null ) {                        
 113  0
                                 attributes.putAll(KNSUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getBoClass()));
 114  0
                                 attributes.put(KNSConstants.MAINTENANCE_ACTN,maintDoc.getNewMaintainableObject().getMaintenanceAction());
 115  
                         }
 116  
                 }
 117  0
         }
 118  
 
 119  
         protected final MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() {
 120  0
                 if (maintenanceDocumentDictionaryService == null) {
 121  0
                         maintenanceDocumentDictionaryService = KNSServiceLocatorWeb
 122  
                                         .getMaintenanceDocumentDictionaryService();
 123  
                 }
 124  0
                 return maintenanceDocumentDictionaryService;
 125  
         }
 126  
 
 127  
 }