View Javadoc

1   /**
2    * Copyright 2005-2013 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.document.authorization;
17  
18  import org.kuali.rice.kim.api.KimConstants;
19  import org.kuali.rice.kim.api.identity.Person;
20  import org.kuali.rice.krad.document.Document;
21  import org.kuali.rice.krad.util.KRADConstants;
22  
23  import java.util.HashMap;
24  import java.util.HashSet;
25  import java.util.Map;
26  import java.util.Set;
27  
28  /**
29   * Base class for all TransactionalDocumentAuthorizers.
30   */
31  public class TransactionalDocumentAuthorizerBase extends DocumentAuthorizerBase
32  		implements TransactionalDocumentAuthorizer {
33  	public final Set<String> getEditModes(Document document, Person user,
34  			Set<String> editModes) {
35  		Set<String> unauthorizedEditModes = new HashSet<String>();
36  		for (String editMode : editModes) {
37  			Map<String, String> additionalPermissionDetails = new HashMap<String, String>();
38  			additionalPermissionDetails.put(KimConstants.AttributeConstants.EDIT_MODE, editMode);
39  			if (permissionExistsByTemplate(
40  					document,
41  					KRADConstants.KNS_NAMESPACE,
42  					KimConstants.PermissionTemplateNames.USE_TRANSACTIONAL_DOCUMENT,
43  					additionalPermissionDetails)
44  					&& !isAuthorizedByTemplate(
45  							document,
46  							KRADConstants.KNS_NAMESPACE,
47  							KimConstants.PermissionTemplateNames.USE_TRANSACTIONAL_DOCUMENT,
48  							user.getPrincipalId(), additionalPermissionDetails,
49  							null)) {
50  				unauthorizedEditModes.add(editMode);
51  			}
52  		}
53  		editModes.removeAll(unauthorizedEditModes);
54  		return editModes;
55  	}
56  }