Coverage Report - org.kuali.rice.krad.document.authorization.MaintenanceDocumentAuthorizerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentAuthorizerBase
0%
0/28
0%
0/22
2
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.krad.document.authorization;
 17  
 
 18  
 
 19  
 import org.kuali.rice.kim.api.KimConstants;
 20  
 import org.kuali.rice.kim.api.identity.Person;
 21  
 import org.kuali.rice.krad.document.MaintenanceDocument;
 22  
 import org.kuali.rice.krad.service.DocumentDictionaryService;
 23  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 24  
 import org.kuali.rice.krad.util.KRADConstants;
 25  
 import org.kuali.rice.krad.util.KRADUtils;
 26  
 
 27  
 import java.util.HashMap;
 28  
 import java.util.HashSet;
 29  
 import java.util.Map;
 30  
 import java.util.Set;
 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 DocumentDictionaryService documentDictionaryService;
 38  
 
 39  
         public final boolean canCreate(Class boClass, Person user) {
 40  0
                 Map<String, String> permissionDetails = new HashMap<String, String>();
 41  0
                 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
 42  
                                 getDocumentDictionaryService().getMaintenanceDocumentTypeName(
 43  
                                                 boClass));
 44  0
                 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN,
 45  
                                 KRADConstants.MAINTENANCE_NEW_ACTION);
 46  0
                 return !permissionExistsByTemplate(KRADConstants.KRAD_NAMESPACE,
 47  
                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 48  
                                 permissionDetails)
 49  
                                 || getPermissionService()
 50  
                                                 .isAuthorizedByTemplateName(
 51  
                                                                 user.getPrincipalId(),
 52  
                                                                 KRADConstants.KRAD_NAMESPACE,
 53  
                                                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 54  
                                                                 permissionDetails, new HashMap<String, String>());
 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  
                                 getDocumentDictionaryService().getMaintenanceDocumentTypeName(
 61  
                                                 dataObject.getClass()));
 62  0
                 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN,
 63  
                                 KRADConstants.MAINTENANCE_EDIT_ACTION);
 64  0
                 return !permissionExistsByTemplate(KRADConstants.KRAD_NAMESPACE,
 65  
                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 66  
                                 permissionDetails)
 67  
                                 || isAuthorizedByTemplate(
 68  
                                                 dataObject,
 69  
                                                 KRADConstants.KRAD_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  
                                 KRADConstants.KRAD_NAMESPACE,
 78  
                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS)
 79  
                                 || isAuthorizedByTemplate(
 80  
                                                 maintenanceDocument,
 81  
                                                 KRADConstants.KRAD_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(
 102  
                         KRADUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass()));
 103  
                         }
 104  
                 }
 105  0
         }
 106  
 
 107  
         @SuppressWarnings("unchecked")
 108  
         @Override
 109  
         protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) {
 110  0
                 super.addPermissionDetails(dataObject, attributes);
 111  0
                 if (dataObject instanceof MaintenanceDocument) {
 112  0
                         MaintenanceDocument maintDoc = (MaintenanceDocument)dataObject;
 113  0
                         if ( maintDoc.getNewMaintainableObject() != null ) {                        
 114  0
                                 attributes.putAll(
 115  
                         KRADUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass()));
 116  0
                                 attributes.put(KRADConstants.MAINTENANCE_ACTN,maintDoc.getNewMaintainableObject().getMaintenanceAction());
 117  
                         }
 118  
                 }
 119  0
         }
 120  
 
 121  
     protected static DocumentDictionaryService getDocumentDictionaryService() {
 122  0
         if (documentDictionaryService == null) {
 123  0
             documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService();
 124  
         }
 125  0
         return documentDictionaryService;
 126  
     }
 127  
 
 128  
 }