View Javadoc
1   /**
2    * Copyright 2005-2015 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.bo.authorization;
17  
18  import org.kuali.rice.kns.authorization.BusinessObjectAuthorizer;
19  import org.kuali.rice.krad.bo.BusinessObject;
20  import org.kuali.rice.krad.bo.DataObjectAuthorizerBase;
21  import org.kuali.rice.krad.service.DataDictionaryService;
22  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23  import org.kuali.rice.krad.service.KualiModuleService;
24  import org.kuali.rice.krad.service.PersistenceStructureService;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  /**
31   * @deprecated Use {@link org.kuali.rice.krad.bo.DataObjectAuthorizerBase}.
32   */
33  @Deprecated
34  public class BusinessObjectAuthorizerBase extends DataObjectAuthorizerBase implements BusinessObjectAuthorizer {
35      private static final long serialVersionUID = -6315759348728853851L;
36  
37  	private static KualiModuleService kualiModuleService;
38  	private static DataDictionaryService dataDictionaryService;
39  	private static PersistenceStructureService persistenceStructureService;
40  
41      protected final boolean permissionExistsByTemplate(
42  			BusinessObject businessObject, String namespaceCode,
43  			String permissionTemplateName) {
44  		return getPermissionService()
45  				.isPermissionDefinedByTemplate(namespaceCode, permissionTemplateName, new HashMap<String, String>(
46                          getPermissionDetailValues(businessObject)));
47  	}
48  
49  	protected final boolean permissionExistsByTemplate(
50  			BusinessObject businessObject, String namespaceCode,
51  			String permissionTemplateName, Map<String, String> permissionDetails) {
52  		Map<String, String> combinedPermissionDetails = new HashMap<String, String>(
53  				getPermissionDetailValues(businessObject));
54  		combinedPermissionDetails.putAll(permissionDetails);
55  		return getPermissionService()
56  				.isPermissionDefinedByTemplate(namespaceCode, permissionTemplateName, combinedPermissionDetails);
57  	}
58  
59  	public final boolean isAuthorized(BusinessObject businessObject,
60  			String namespaceCode, String permissionName, String principalId) {
61  		return getPermissionService().isAuthorized(principalId,
62  				namespaceCode, permissionName,
63  				new HashMap<String, String>(getRoleQualification(businessObject, principalId)));
64  	}
65  
66  	public final boolean isAuthorizedByTemplate(BusinessObject dataObject,
67  			String namespaceCode, String permissionTemplateName,
68  			String principalId) {
69  		return getPermissionService().isAuthorizedByTemplate(principalId, namespaceCode, permissionTemplateName,
70                  new HashMap<String, String>(getPermissionDetailValues(dataObject)), new HashMap<String, String>(
71                  getRoleQualification(dataObject, principalId)));
72  	}
73  
74  	public final boolean isAuthorized(BusinessObject businessObject,
75  			String namespaceCode, String permissionName, String principalId,
76  			Map<String, String> collectionOrFieldLevelPermissionDetails,
77  			Map<String, String> collectionOrFieldLevelRoleQualification) {
78  		Map<String, String> roleQualifiers = null;
79  		Map<String, String> permissionDetails = null;
80  		if (collectionOrFieldLevelRoleQualification != null) {
81  			roleQualifiers = new HashMap<String, String>(
82  					getRoleQualification(businessObject, principalId));
83  			roleQualifiers.putAll(collectionOrFieldLevelRoleQualification);
84  		} else {
85  			roleQualifiers = new HashMap<String, String>(
86  					getRoleQualification(businessObject, principalId));
87  		}
88  		/*if (collectionOrFieldLevelPermissionDetails != null) {
89  			permissionDetails = new HashMap<String, String>(
90  					getPermissionDetailValues(businessObject));
91  			permissionDetails.putAll(collectionOrFieldLevelPermissionDetails);
92  		} else {
93  			permissionDetails = new HashMap<String, String>(
94  					getPermissionDetailValues(businessObject));
95  		}*/
96  		
97  		return getPermissionService().isAuthorized(principalId,
98  				namespaceCode, permissionName,
99  				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 }