001 /** 002 * Copyright 2005-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.rice.krad.uif.authorization; 017 018 019 import org.kuali.rice.kim.api.KimConstants; 020 import org.kuali.rice.kim.api.identity.Person; 021 import org.kuali.rice.krad.document.MaintenanceDocument; 022 import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 023 import org.kuali.rice.krad.util.KRADConstants; 024 import org.kuali.rice.krad.util.KRADUtils; 025 026 import java.util.HashMap; 027 import java.util.HashSet; 028 import java.util.Map; 029 import java.util.Set; 030 031 /** 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034 public class MaintenanceDocumentAuthorizerBase extends DocumentAuthorizerBase { 035 036 public final boolean canCreate(Class<?> boClass, Person user) { 037 Map<String, String> permissionDetails = new HashMap<String, String>(); 038 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, 039 KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(boClass)); 040 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, 041 KRADConstants.MAINTENANCE_NEW_ACTION); 042 return !permissionExistsByTemplate(KRADConstants.KRAD_NAMESPACE, 043 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, 044 permissionDetails) 045 || getPermissionService() 046 .isAuthorizedByTemplateName( 047 user.getPrincipalId(), 048 KRADConstants.KRAD_NAMESPACE, 049 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, 050 permissionDetails, new HashMap<String, String>()); 051 } 052 053 public final boolean canMaintain(Object dataObject, Person user) { 054 Map<String, String> permissionDetails = new HashMap<String, String>(2); 055 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, 056 KRADServiceLocatorWeb.getDocumentDictionaryService() 057 .getMaintenanceDocumentTypeName(dataObject.getClass())); 058 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_EDIT_ACTION); 059 return !permissionExistsByTemplate(KRADConstants.KRAD_NAMESPACE, 060 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails) || 061 isAuthorizedByTemplate(dataObject, KRADConstants.KRAD_NAMESPACE, 062 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId(), 063 permissionDetails, null); 064 } 065 066 public final boolean canCreateOrMaintain(MaintenanceDocument maintenanceDocument, Person user) { 067 return !permissionExistsByTemplate(maintenanceDocument, KRADConstants.KRAD_NAMESPACE, 068 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) || 069 isAuthorizedByTemplate(maintenanceDocument, KRADConstants.KRAD_NAMESPACE, 070 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId()); 071 } 072 073 public Set<String> getSecurePotentiallyHiddenSectionIds() { 074 return new HashSet<String>(); 075 } 076 077 public Set<String> getSecurePotentiallyReadOnlySectionIds() { 078 return new HashSet<String>(); 079 } 080 081 @SuppressWarnings("unchecked") 082 @Override 083 protected void addRoleQualification(Object dataObject, Map<String, String> attributes) { 084 super.addRoleQualification(dataObject, attributes); 085 if (dataObject instanceof MaintenanceDocument) { 086 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject; 087 if (maintDoc.getNewMaintainableObject() != null) { 088 attributes.putAll(KRADUtils 089 .getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass())); 090 } 091 } 092 } 093 094 @SuppressWarnings("unchecked") 095 @Override 096 protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) { 097 super.addPermissionDetails(dataObject, attributes); 098 if (dataObject instanceof MaintenanceDocument) { 099 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject; 100 if (maintDoc.getNewMaintainableObject() != null) { 101 attributes.putAll(KRADUtils 102 .getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass())); 103 attributes.put(KRADConstants.MAINTENANCE_ACTN, 104 maintDoc.getNewMaintainableObject().getMaintenanceAction()); 105 } 106 } 107 } 108 }