001/** 002 * Copyright 2005-2014 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.bo.authorization; 017 018import org.kuali.rice.kns.authorization.BusinessObjectAuthorizer; 019import org.kuali.rice.krad.bo.BusinessObject; 020import org.kuali.rice.krad.bo.DataObjectAuthorizerBase; 021import org.kuali.rice.krad.service.DataDictionaryService; 022import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 023import org.kuali.rice.krad.service.KualiModuleService; 024import org.kuali.rice.krad.service.PersistenceStructureService; 025import org.kuali.rice.krad.util.GlobalVariables; 026 027import java.util.HashMap; 028import java.util.Map; 029 030/** 031 * @deprecated Use {@link org.kuali.rice.krad.bo.DataObjectAuthorizerBase}. 032 */ 033@Deprecated 034public class BusinessObjectAuthorizerBase extends DataObjectAuthorizerBase implements BusinessObjectAuthorizer { 035 private static final long serialVersionUID = -6315759348728853851L; 036 037 private static KualiModuleService kualiModuleService; 038 private static DataDictionaryService dataDictionaryService; 039 private static PersistenceStructureService persistenceStructureService; 040 041 protected final boolean permissionExistsByTemplate( 042 BusinessObject businessObject, String namespaceCode, 043 String permissionTemplateName) { 044 return getPermissionService() 045 .isPermissionDefinedByTemplate(namespaceCode, permissionTemplateName, new HashMap<String, String>( 046 getPermissionDetailValues(businessObject))); 047 } 048 049 protected final boolean permissionExistsByTemplate( 050 BusinessObject businessObject, String namespaceCode, 051 String permissionTemplateName, Map<String, String> permissionDetails) { 052 Map<String, String> combinedPermissionDetails = new HashMap<String, String>( 053 getPermissionDetailValues(businessObject)); 054 combinedPermissionDetails.putAll(permissionDetails); 055 return getPermissionService() 056 .isPermissionDefinedByTemplate(namespaceCode, permissionTemplateName, combinedPermissionDetails); 057 } 058 059 public final boolean isAuthorized(BusinessObject businessObject, 060 String namespaceCode, String permissionName, String principalId) { 061 return getPermissionService().isAuthorized(principalId, 062 namespaceCode, permissionName, 063 new HashMap<String, String>(getRoleQualification(businessObject, principalId))); 064 } 065 066 public final boolean isAuthorizedByTemplate(BusinessObject dataObject, 067 String namespaceCode, String permissionTemplateName, 068 String principalId) { 069 return getPermissionService().isAuthorizedByTemplate(principalId, namespaceCode, permissionTemplateName, 070 new HashMap<String, String>(getPermissionDetailValues(dataObject)), new HashMap<String, String>( 071 getRoleQualification(dataObject, principalId))); 072 } 073 074 public final boolean isAuthorized(BusinessObject businessObject, 075 String namespaceCode, String permissionName, String principalId, 076 Map<String, String> collectionOrFieldLevelPermissionDetails, 077 Map<String, String> collectionOrFieldLevelRoleQualification) { 078 Map<String, String> roleQualifiers = null; 079 Map<String, String> permissionDetails = null; 080 if (collectionOrFieldLevelRoleQualification != null) { 081 roleQualifiers = new HashMap<String, String>( 082 getRoleQualification(businessObject, principalId)); 083 roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); 084 } else { 085 roleQualifiers = new HashMap<String, String>( 086 getRoleQualification(businessObject, principalId)); 087 } 088 /*if (collectionOrFieldLevelPermissionDetails != null) { 089 permissionDetails = new HashMap<String, String>( 090 getPermissionDetailValues(businessObject)); 091 permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); 092 } else { 093 permissionDetails = new HashMap<String, String>( 094 getPermissionDetailValues(businessObject)); 095 }*/ 096 097 return getPermissionService().isAuthorized(principalId, 098 namespaceCode, permissionName, 099 roleQualifiers); 100 } 101 102 103 /** 104 * Returns a role qualification map based off data from the primary business 105 * object or the document. DO NOT MODIFY THE MAP RETURNED BY THIS METHOD 106 * 107 * @param primaryBusinessObjectOrDocument 108 * the primary business object (i.e. the main BO instance behind 109 * the lookup result row or inquiry) or the document 110 * @return a Map containing role qualifications 111 */ 112 protected final Map<String, String> getRoleQualification( 113 BusinessObject primaryBusinessObjectOrDocument) { 114 return getRoleQualification(primaryBusinessObjectOrDocument, GlobalVariables 115 .getUserSession().getPerson().getPrincipalId()); 116 } 117 118 /** 119 * @see org.kuali.rice.kns.authorization.BusinessObjectAuthorizer#getCollectionItemPermissionDetails(org.kuali.rice.krad.bo.BusinessObject) 120 */ 121 @Override 122 public Map<String, String> getCollectionItemPermissionDetails( 123 BusinessObject collectionItemBusinessObject) { 124 return new HashMap<String, String>(); 125 } 126 127 /** 128 * @see org.kuali.rice.kns.authorization.BusinessObjectAuthorizer#getCollectionItemRoleQualifications(org.kuali.rice.krad.bo.BusinessObject) 129 */ 130 @Override 131 public Map<String, String> getCollectionItemRoleQualifications( 132 BusinessObject collectionItemBusinessObject) { 133 return new HashMap<String, String>(); 134 } 135 136 protected static KualiModuleService getKualiModuleService() { 137 if (kualiModuleService == null) { 138 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService(); 139 } 140 return kualiModuleService; 141 } 142 143 protected static DataDictionaryService getDataDictionaryService() { 144 if (dataDictionaryService == null) { 145 dataDictionaryService = KRADServiceLocatorWeb 146 .getDataDictionaryService(); 147 } 148 return dataDictionaryService; 149 } 150}