Coverage Report - org.kuali.rice.krad.authorization.PermissionDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionDerivedRoleTypeServiceImpl
0%
0/34
0%
0/22
3.25
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.krad.authorization;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 20  
 import org.kuali.rice.core.api.membership.MemberType;
 21  
 import org.kuali.rice.kim.api.role.Role;
 22  
 import org.kuali.rice.kim.api.role.RoleMembership;
 23  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 24  
 import org.kuali.rice.kim.api.common.assignee.Assignee;
 25  
 import org.kuali.rice.kim.api.permission.PermissionService;
 26  
 import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase;
 27  
 
 28  
 import java.util.ArrayList;
 29  
 import java.util.HashMap;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 
 33  
 /**
 34  
  * This is a description of what this class does - wliang don't forget to fill this in.
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  0
 public class PermissionDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase {
 39  
 
 40  
         private static PermissionService permissionService;
 41  
         private String permissionTemplateNamespace;
 42  
         private String permissionTemplateName;
 43  
         /**
 44  
          * @return the permissionTemplateNamespace
 45  
          */
 46  
         public String getPermissionTemplateNamespace() {
 47  0
                 return this.permissionTemplateNamespace;
 48  
         }
 49  
         /**
 50  
          * @param permissionTemplateNamespace the permissionTemplateNamespace to set
 51  
          */
 52  
         public void setPermissionTemplateNamespace(String permissionTemplateNamespace) {
 53  0
                 this.permissionTemplateNamespace = permissionTemplateNamespace;
 54  0
         }
 55  
         /**
 56  
          * @return the permissionTemplateName
 57  
          */
 58  
         public String getPermissionTemplateName() {
 59  0
                 return this.permissionTemplateName;
 60  
         }
 61  
         /**
 62  
          * @param permissionTemplateName the permissionTemplateName to set
 63  
          */
 64  
         public void setPermissionTemplateName(String permissionTemplateName) {
 65  0
                 this.permissionTemplateName = permissionTemplateName;
 66  0
         }
 67  
         
 68  
         protected List<Assignee> getPermissionAssignees(Map<String, String> qualification) {
 69  0
                 return getPermissionService().getPermissionAssigneesByTemplateName(permissionTemplateNamespace,
 70  
                 permissionTemplateName, new HashMap<String, String>(qualification), new HashMap<String, String>(
 71  
                 qualification));
 72  
         }
 73  
 
 74  
     @Override
 75  
     public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) {
 76  0
         if (StringUtils.isBlank(namespaceCode)) {
 77  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 78  
         }
 79  
 
 80  0
         if (roleName == null) {
 81  0
             throw new RiceIllegalArgumentException("roleName was null");
 82  
         }
 83  0
         List<Assignee> permissionAssignees = getPermissionAssignees(qualification);
 84  0
         List<RoleMembership> members = new ArrayList<RoleMembership>();
 85  0
         for (Assignee permissionAssigneeInfo : permissionAssignees) {
 86  0
             if (StringUtils.isNotBlank(permissionAssigneeInfo.getPrincipalId())) {
 87  0
                 members.add(RoleMembership.Builder.create(null/*roleId*/, null, permissionAssigneeInfo.getPrincipalId(), MemberType.PRINCIPAL, null).build());
 88  0
             } else if (StringUtils.isNotBlank(permissionAssigneeInfo.getGroupId())) {
 89  0
                 members.add(RoleMembership.Builder.create(null/*roleId*/, null, permissionAssigneeInfo.getGroupId(), MemberType.GROUP, null).build());
 90  
             }
 91  
         }
 92  0
         return members;
 93  
     }
 94  
 
 95  
 
 96  
     @Override
 97  
     public boolean hasApplicationRole(
 98  
             String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification){
 99  0
         if (StringUtils.isBlank(principalId)) {
 100  0
             throw new RiceIllegalArgumentException("principalId was null or blank");
 101  
         }
 102  
 
 103  0
         if (groupIds == null) {
 104  0
             throw new RiceIllegalArgumentException("groupIds was null or blank");
 105  
         }
 106  
 
 107  0
         if (StringUtils.isBlank(namespaceCode)) {
 108  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 109  
         }
 110  
 
 111  0
         if (StringUtils.isBlank(roleName)) {
 112  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 113  
         }
 114  
 
 115  0
         if (qualification == null) {
 116  0
             throw new RiceIllegalArgumentException("qualification was null");
 117  
         }
 118  
 
 119  
         // FIXME: dangerous - data changes could cause an infinite loop - should add thread-local to trap state and abort
 120  0
         return getPermissionService().isAuthorizedByTemplateName(principalId, permissionTemplateNamespace, permissionTemplateName, new HashMap<String, String>(qualification), new HashMap<String, String>(qualification));
 121  
     }
 122  
 
 123  
     /**
 124  
      * @return the documentService
 125  
      */
 126  
     protected PermissionService getPermissionService() {
 127  0
         if (permissionService == null) {
 128  0
             permissionService = KimApiServiceLocator.getPermissionService();
 129  
         }
 130  0
         return permissionService;
 131  
     }
 132  
 
 133  
 }