001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kns.document.authorization; 017 018 019import org.kuali.rice.kim.api.KimConstants; 020import org.kuali.rice.kim.api.identity.Person; 021import org.kuali.rice.krad.maintenance.MaintenanceDocument; 022import org.kuali.rice.krad.service.DocumentDictionaryService; 023import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 024import org.kuali.rice.krad.util.KRADConstants; 025import org.kuali.rice.krad.util.KRADUtils; 026 027import java.util.HashMap; 028import java.util.HashSet; 029import java.util.Map; 030import java.util.Set; 031 032/** 033 * @deprecated Use {@link org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizerBase}. 034 */ 035@Deprecated 036public class MaintenanceDocumentAuthorizerBase extends DocumentAuthorizerBase implements MaintenanceDocumentAuthorizer { 037 // private static final org.apache.log4j.Logger LOG = 038 // org.apache.log4j.Logger.getLogger(MaintenanceDocumentAuthorizerBase.class); 039 040 transient protected static DocumentDictionaryService documentDictionaryService; 041 042 public boolean canCreate(Class boClass, Person user) { 043 Map<String, String> permissionDetails = new HashMap<String, String>(); 044 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, 045 getDocumentDictionaryService().getMaintenanceDocumentTypeName( 046 boClass)); 047 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, 048 KRADConstants.MAINTENANCE_NEW_ACTION); 049 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE, 050 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, 051 permissionDetails) 052 || getPermissionService() 053 .isAuthorizedByTemplate(user.getPrincipalId(), KRADConstants.KNS_NAMESPACE, 054 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails, 055 new HashMap<String, String>()); 056 } 057 058 public boolean canMaintain(Object dataObject, Person user) { 059 Map<String, String> permissionDetails = new HashMap<String, String>(2); 060 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, 061 getDocumentDictionaryService().getMaintenanceDocumentTypeName( 062 dataObject.getClass())); 063 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, 064 KRADConstants.MAINTENANCE_EDIT_ACTION); 065 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE, 066 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, 067 permissionDetails) 068 || isAuthorizedByTemplate( 069 dataObject, 070 KRADConstants.KNS_NAMESPACE, 071 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, 072 user.getPrincipalId(), permissionDetails, null); 073 } 074 075 public boolean canCreateOrMaintain( 076 MaintenanceDocument maintenanceDocument, Person user) { 077 return !permissionExistsByTemplate(maintenanceDocument, 078 KRADConstants.KNS_NAMESPACE, 079 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) 080 || isAuthorizedByTemplate( 081 maintenanceDocument, 082 KRADConstants.KNS_NAMESPACE, 083 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, 084 user.getPrincipalId()); 085 } 086 087 public Set<String> getSecurePotentiallyHiddenSectionIds() { 088 return new HashSet<String>(); 089 } 090 091 public Set<String> getSecurePotentiallyReadOnlySectionIds() { 092 return new HashSet<String>(); 093 } 094 095 @SuppressWarnings("unchecked") 096 @Override 097 protected void addRoleQualification(Object dataObject, Map<String, String> attributes) { 098 super.addRoleQualification(dataObject, attributes); 099 if (dataObject instanceof MaintenanceDocument) { 100 MaintenanceDocument maintDoc = (MaintenanceDocument)dataObject; 101 if ( maintDoc.getNewMaintainableObject() != null ) { 102 attributes.putAll( 103 KRADUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass())); 104 } 105 } 106 } 107 108 @SuppressWarnings("unchecked") 109 @Override 110 protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) { 111 super.addPermissionDetails(dataObject, attributes); 112 if (dataObject instanceof MaintenanceDocument) { 113 MaintenanceDocument maintDoc = (MaintenanceDocument)dataObject; 114 if ( maintDoc.getNewMaintainableObject() != null ) { 115 attributes.putAll( 116 KRADUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass())); 117 attributes.put(KRADConstants.MAINTENANCE_ACTN,maintDoc.getNewMaintainableObject().getMaintenanceAction()); 118 } 119 } 120 } 121 122 protected static DocumentDictionaryService getDocumentDictionaryService() { 123 if (documentDictionaryService == null) { 124 documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService(); 125 } 126 return documentDictionaryService; 127 } 128 129}