Coverage Report - org.kuali.rice.kns.uif.authorization.AuthorizerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
AuthorizerBase
0%
0/56
0%
0/16
1.381
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 1.0 (the
 5  
  * "License"); 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/ecl1.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, WITHOUT
 12  
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13  
  * License for the specific language governing permissions and limitations under
 14  
  * the License.
 15  
  */
 16  
 package org.kuali.rice.kns.uif.authorization;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.HashSet;
 20  
 import java.util.Map;
 21  
 import java.util.Set;
 22  
 
 23  
 import org.kuali.rice.core.xml.dto.AttributeSet;
 24  
 import org.kuali.rice.kim.bo.Person;
 25  
 import org.kuali.rice.kim.service.IdentityManagementService;
 26  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 27  
 import org.kuali.rice.kim.service.PersonService;
 28  
 import org.kuali.rice.kim.util.KimConstants;
 29  
 import org.kuali.rice.kns.service.DataDictionaryService;
 30  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 31  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 32  
 import org.kuali.rice.kns.service.KualiModuleService;
 33  
 import org.kuali.rice.kns.util.GlobalVariables;
 34  
 import org.kuali.rice.kns.util.KNSUtils;
 35  
 import org.kuali.rice.kns.web.spring.form.UifFormBase;
 36  
 
 37  
 /**
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  */
 40  0
 public class AuthorizerBase implements Authorizer {
 41  
 
 42  
     private static IdentityManagementService identityManagementService;
 43  
     private static PersonService personService;
 44  
     private static KualiModuleService kualiModuleService;
 45  
     private static DataDictionaryService dataDictionaryService;
 46  
 
 47  
     /**
 48  
      * @see org.kuali.rice.kns.uif.authorization.Authorizer#getActionFlags(org.kuali.rice.kns.web.spring.form.UifFormBase,
 49  
      *      org.kuali.rice.kim.bo.Person, java.util.Set)
 50  
      */
 51  
     public Set<String> getActionFlags(UifFormBase model, Person user, Set<String> documentActions) {
 52  0
         return documentActions;
 53  
     }
 54  
 
 55  
     /**
 56  
      * @see org.kuali.rice.kns.uif.authorization.Authorizer#getEditModes(org.kuali.rice.kns.web.spring.form.UifFormBase,
 57  
      *      org.kuali.rice.kim.bo.Person, java.util.Set)
 58  
      */
 59  
     public Set<String> getEditModes(UifFormBase model, Person user, Set<String> editModes) {
 60  0
         return editModes;
 61  
     }
 62  
 
 63  
     /**
 64  
      * @see org.kuali.rice.kns.uif.authorization.Authorizer#getSecurePotentiallyHiddenGroupIds()
 65  
      */
 66  
     public Set<String> getSecurePotentiallyHiddenGroupIds() {
 67  0
         return new HashSet<String>();
 68  
     }
 69  
 
 70  
     /**
 71  
      * @see org.kuali.rice.kns.uif.authorization.Authorizer#getSecurePotentiallyReadOnlyGroupIds()
 72  
      */
 73  
     public Set<String> getSecurePotentiallyReadOnlyGroupIds() {
 74  0
         return new HashSet<String>();
 75  
     }
 76  
 
 77  
     /**
 78  
      * Override this method to populate the role qualifier attributes from the
 79  
      * primary data object or document. This will only be called once per
 80  
      * request.
 81  
      * 
 82  
      * @param primaryDataObjectOrDocument
 83  
      *            - the primary data object (i.e. the main object instance
 84  
      *            behind the lookup result row or inquiry) or the document
 85  
      * @param attributes
 86  
      *            - role qualifiers will be added to this map
 87  
      */
 88  
     protected void addRoleQualification(Object primaryDataObjectOrDocument, Map<String, String> attributes) {
 89  0
         addStandardAttributes(primaryDataObjectOrDocument, attributes);
 90  0
     }
 91  
 
 92  
     /**
 93  
      * Override this method to populate the permission details from the primary
 94  
      * data object or document. This will only be called once per request.
 95  
      * 
 96  
      * @param primaryDataObjectOrDocument
 97  
      *            - the primary data object (i.e. the main object instance
 98  
      *            behind the lookup result row or inquiry) or the document
 99  
      * @param attributes
 100  
      *            - permission details will be added to this map
 101  
      */
 102  
     protected void addPermissionDetails(Object primaryDataObjectOrDocument, Map<String, String> attributes) {
 103  0
         addStandardAttributes(primaryDataObjectOrDocument, attributes);
 104  0
     }
 105  
 
 106  
     /**
 107  
      * @param primaryDataObjectOrDocument
 108  
      *            - the primary data object (i.e. the main object instance
 109  
      *            behind the lookup result row or inquiry) or the document
 110  
      * @param attributes
 111  
      *            - attributes (i.e. role qualifications or permission details)
 112  
      *            will be added to this map
 113  
      */
 114  
     private void addStandardAttributes(Object primaryDataObjectOrDocument, Map<String, String> attributes) {
 115  0
         attributes.putAll(KNSUtils.getNamespaceAndComponentSimpleName(primaryDataObjectOrDocument.getClass()));
 116  0
     }
 117  
 
 118  
     protected final boolean permissionExistsByTemplate(Object dataObject, String namespaceCode,
 119  
             String permissionTemplateName) {
 120  0
         return getIdentityManagementService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName,
 121  
                 new AttributeSet(getPermissionDetailValues(dataObject)));
 122  
     }
 123  
 
 124  
     protected final boolean permissionExistsByTemplate(String namespaceCode, String permissionTemplateName,
 125  
             Map<String, String> permissionDetails) {
 126  0
         return getIdentityManagementService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName,
 127  
                 new AttributeSet(permissionDetails));
 128  
     }
 129  
 
 130  
     protected final boolean permissionExistsByTemplate(Object dataObject, String namespaceCode,
 131  
             String permissionTemplateName, Map<String, String> permissionDetails) {
 132  0
         AttributeSet combinedPermissionDetails = new AttributeSet(getPermissionDetailValues(dataObject));
 133  0
         combinedPermissionDetails.putAll(permissionDetails);
 134  
 
 135  0
         return getIdentityManagementService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName,
 136  
                 combinedPermissionDetails);
 137  
     }
 138  
 
 139  
     public final boolean isAuthorized(Object dataObject, String namespaceCode, String permissionName, String principalId) {
 140  0
         return getIdentityManagementService().isAuthorized(principalId, namespaceCode, permissionName,
 141  
                 new AttributeSet(getPermissionDetailValues(dataObject)),
 142  
                 new AttributeSet(getRoleQualification(dataObject, principalId)));
 143  
     }
 144  
 
 145  
     public final boolean isAuthorizedByTemplate(Object dataObject, String namespaceCode, String permissionTemplateName,
 146  
             String principalId) {
 147  0
         return getIdentityManagementService().isAuthorizedByTemplateName(principalId, namespaceCode,
 148  
                 permissionTemplateName, new AttributeSet(getPermissionDetailValues(dataObject)),
 149  
                 new AttributeSet(getRoleQualification(dataObject, principalId)));
 150  
     }
 151  
 
 152  
     public final boolean isAuthorized(Object dataObject, String namespaceCode, String permissionName,
 153  
             String principalId, Map<String, String> collectionOrFieldLevelPermissionDetails,
 154  
             Map<String, String> collectionOrFieldLevelRoleQualification) {
 155  0
         AttributeSet roleQualifiers = null;
 156  0
         AttributeSet permissionDetails = null;
 157  0
         if (collectionOrFieldLevelRoleQualification != null) {
 158  0
             roleQualifiers = new AttributeSet(getRoleQualification(dataObject, principalId));
 159  0
             roleQualifiers.putAll(collectionOrFieldLevelRoleQualification);
 160  
         }
 161  
         else {
 162  0
             roleQualifiers = new AttributeSet(getRoleQualification(dataObject, principalId));
 163  
         }
 164  0
         if (collectionOrFieldLevelPermissionDetails != null) {
 165  0
             permissionDetails = new AttributeSet(getPermissionDetailValues(dataObject));
 166  0
             permissionDetails.putAll(collectionOrFieldLevelPermissionDetails);
 167  
         }
 168  
         else {
 169  0
             permissionDetails = new AttributeSet(getPermissionDetailValues(dataObject));
 170  
         }
 171  
 
 172  0
         return getIdentityManagementService().isAuthorized(principalId, namespaceCode, permissionName,
 173  
                 permissionDetails, roleQualifiers);
 174  
     }
 175  
 
 176  
     public final boolean isAuthorizedByTemplate(Object dataObject, String namespaceCode, String permissionTemplateName,
 177  
             String principalId, Map<String, String> collectionOrFieldLevelPermissionDetails,
 178  
             Map<String, String> collectionOrFieldLevelRoleQualification) {
 179  0
         AttributeSet roleQualifiers = new AttributeSet(getRoleQualification(dataObject, principalId));
 180  0
         AttributeSet permissionDetails = new AttributeSet(getPermissionDetailValues(dataObject));
 181  
 
 182  0
         if (collectionOrFieldLevelRoleQualification != null) {
 183  0
             roleQualifiers.putAll(collectionOrFieldLevelRoleQualification);
 184  
         }
 185  0
         if (collectionOrFieldLevelPermissionDetails != null) {
 186  0
             permissionDetails.putAll(collectionOrFieldLevelPermissionDetails);
 187  
         }
 188  
 
 189  0
         return getIdentityManagementService().isAuthorizedByTemplateName(principalId, namespaceCode,
 190  
                 permissionTemplateName, permissionDetails, roleQualifiers);
 191  
     }
 192  
 
 193  
     /**
 194  
      * Returns a role qualification map based off data from the primary business
 195  
      * object or the document. DO NOT MODIFY THE MAP RETURNED BY THIS METHOD
 196  
      * 
 197  
      * @param primaryDataObjectOrDocument
 198  
      *            the primary data object (i.e. the main object instance behind
 199  
      *            the lookup result row or inquiry) or the document
 200  
      * @return a Map containing role qualifications
 201  
      */
 202  
     protected final Map<String, String> getRoleQualification(Object primaryDataObjectOrDocument) {
 203  0
         return getRoleQualification(primaryDataObjectOrDocument, GlobalVariables.getUserSession().getPerson()
 204  
                 .getPrincipalId());
 205  
     }
 206  
 
 207  
     protected final Map<String, String> getRoleQualification(Object primaryDataObjectOrDocument, String principalId) {
 208  0
         Map<String, String> roleQualification = new HashMap<String, String>();
 209  0
         addRoleQualification(primaryDataObjectOrDocument, roleQualification);
 210  0
         roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, principalId);
 211  
 
 212  0
         return roleQualification;
 213  
     }
 214  
 
 215  
     /**
 216  
      * Returns a permission details map based off data from the primary business
 217  
      * object or the document. DO NOT MODIFY THE MAP RETURNED BY THIS METHOD
 218  
      * 
 219  
      * @param primaryDataObjectOrDocument
 220  
      *            the primary data object (i.e. the main object instance behind
 221  
      *            the lookup result row or inquiry) or the document
 222  
      * @return a Map containing permission details
 223  
      */
 224  
     protected final Map<String, String> getPermissionDetailValues(Object primaryDataObjectOrDocument) {
 225  0
         Map<String, String> permissionDetails = new HashMap<String, String>();
 226  0
         addPermissionDetails(primaryDataObjectOrDocument, permissionDetails);
 227  
 
 228  0
         return permissionDetails;
 229  
     }
 230  
 
 231  
     protected static final IdentityManagementService getIdentityManagementService() {
 232  0
         if (identityManagementService == null) {
 233  0
             identityManagementService = KIMServiceLocator.getIdentityManagementService();
 234  
         }
 235  0
         return identityManagementService;
 236  
     }
 237  
 
 238  
     protected static final PersonService getPersonService() {
 239  0
         if (personService == null) {
 240  0
             personService = KIMServiceLocator.getPersonService();
 241  
         }
 242  0
         return personService;
 243  
     }
 244  
 
 245  
     protected static final KualiModuleService getKualiModuleService() {
 246  0
         if (kualiModuleService == null) {
 247  0
             kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService();
 248  
         }
 249  0
         return kualiModuleService;
 250  
     }
 251  
 
 252  
     protected static final DataDictionaryService getDataDictionaryService() {
 253  0
         if (dataDictionaryService == null) {
 254  0
             dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService();
 255  
         }
 256  0
         return dataDictionaryService;
 257  
     }
 258  
 
 259  
 }