Coverage Report - org.kuali.rice.kns.authorization.PermissionDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionDerivedRoleTypeServiceImpl
0%
0/20
0%
0/8
1.5
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.authorization;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.kim.bo.Role;
 23  
 import org.kuali.rice.kim.bo.role.dto.PermissionAssigneeInfo;
 24  
 import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
 25  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 26  
 import org.kuali.rice.kim.service.IdentityManagementService;
 27  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 28  
 import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase;
 29  
 
 30  
 /**
 31  
  * This is a description of what this class does - wliang don't forget to fill this in. 
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  0
 public class PermissionDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase {
 37  
 
 38  
         private static IdentityManagementService identityManagementService;
 39  
         private String permissionTemplateNamespace;
 40  
         private String permissionTemplateName;
 41  
         /**
 42  
          * @return the permissionTemplateNamespace
 43  
          */
 44  
         public String getPermissionTemplateNamespace() {
 45  0
                 return this.permissionTemplateNamespace;
 46  
         }
 47  
         /**
 48  
          * @param permissionTemplateNamespace the permissionTemplateNamespace to set
 49  
          */
 50  
         public void setPermissionTemplateNamespace(String permissionTemplateNamespace) {
 51  0
                 this.permissionTemplateNamespace = permissionTemplateNamespace;
 52  0
         }
 53  
         /**
 54  
          * @return the permissionTemplateName
 55  
          */
 56  
         public String getPermissionTemplateName() {
 57  0
                 return this.permissionTemplateName;
 58  
         }
 59  
         /**
 60  
          * @param permissionTemplateName the permissionTemplateName to set
 61  
          */
 62  
         public void setPermissionTemplateName(String permissionTemplateName) {
 63  0
                 this.permissionTemplateName = permissionTemplateName;
 64  0
         }
 65  
         
 66  
         protected List<PermissionAssigneeInfo> getPermissionAssignees(AttributeSet qualification) {
 67  0
                 return getIdentityManagementService().getPermissionAssigneesForTemplateName(permissionTemplateNamespace, permissionTemplateName, qualification, qualification);
 68  
         }
 69  
 
 70  
         /**
 71  
          * This overridden method ...
 72  
          * 
 73  
          * @see org.kuali.rice.kim.service.support.impl.RoleTypeServiceBase#getPrincipalIdsFromApplicationRole(java.lang.String, java.lang.String, org.kuali.rice.kim.bo.types.dto.AttributeSet)
 74  
          */
 75  
         @Override
 76  
     public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, AttributeSet qualification) {
 77  0
                 List<PermissionAssigneeInfo> permissionAssignees = getPermissionAssignees(qualification);
 78  0
                 List<RoleMembershipInfo> members = new ArrayList<RoleMembershipInfo>();
 79  0
                 for (PermissionAssigneeInfo permissionAssigneeInfo : permissionAssignees) {
 80  0
                         if (StringUtils.isNotBlank(permissionAssigneeInfo.getPrincipalId())) {
 81  0
                             members.add( new RoleMembershipInfo( null/*roleId*/, null, permissionAssigneeInfo.getPrincipalId(), Role.PRINCIPAL_MEMBER_TYPE, null));
 82  0
                         } else if (StringUtils.isNotBlank(permissionAssigneeInfo.getGroupId())) {
 83  0
                 members.add( new RoleMembershipInfo( null/*roleId*/, null, permissionAssigneeInfo.getGroupId(), Role.GROUP_MEMBER_TYPE, null));
 84  
                         }
 85  
                 }
 86  0
                 return members;
 87  
         }
 88  
         
 89  
     /***
 90  
      * @see org.kuali.rice.kim.service.support.impl.RoleTypeServiceBase#hasApplicationRole(java.lang.String, java.util.List, java.lang.String, java.lang.String, org.kuali.rice.kim.bo.types.dto.AttributeSet)
 91  
      */
 92  
     @Override
 93  
     public boolean hasApplicationRole(
 94  
             String principalId, List<String> groupIds, String namespaceCode, String roleName, AttributeSet qualification){
 95  
         // FIXME: dangerous - data changes could cause an infinite loop - should add thread-local to trap state and abort
 96  0
             return getIdentityManagementService().isAuthorizedByTemplateName(principalId,permissionTemplateNamespace, permissionTemplateName, qualification, qualification);    
 97  
         }
 98  
     
 99  
     /**
 100  
      * @return the documentService
 101  
      */
 102  
     protected IdentityManagementService getIdentityManagementService(){
 103  0
         if (identityManagementService == null ) {
 104  0
                 identityManagementService = KIMServiceLocator.getIdentityManagementService();
 105  
         }
 106  0
         return identityManagementService;
 107  
     }
 108  
         
 109  
 }