@Test
 public void testGetPrincipal() {
   Principal principal = identityService.getPrincipal("KULUSER");
   assertNotNull("principal must not be null", principal);
   assertEquals(
       "Principal name did not match expected result", "kuluser", principal.getPrincipalName());
 }
 protected void logHasPermissionCheck(
     String checkType,
     String principalId,
     String namespaceCode,
     String permissionName,
     Map<String, String> permissionDetails) {
   StringBuilder sb = new StringBuilder();
   sb.append('\n');
   sb.append("Has Perm for ")
       .append(checkType)
       .append(": ")
       .append(namespaceCode)
       .append("/")
       .append(permissionName)
       .append('\n');
   sb.append("             Principal:  ").append(principalId);
   if (principalId != null) {
     Principal principal = getPrincipal(principalId);
     if (principal != null) {
       sb.append(" (").append(principal.getPrincipalName()).append(')');
     }
   }
   sb.append('\n');
   sb.append("             Details:\n");
   if (permissionDetails != null) {
     sb.append(permissionDetails);
   } else {
     sb.append("                         [null]\n");
   }
   if (LOG.isTraceEnabled()) {
     LOG.trace(sb.append(ExceptionUtils.getStackTrace(new Throwable())));
   } else {
     LOG.debug(sb.toString());
   }
 }
 protected String checkMemberFullName(String principalId) {
   Principal principal = getIdentityService().getPrincipal(principalId);
   if (principal != null) {
     Person psn =
         KimApiServiceLocator.getPersonService()
             .getPersonByPrincipalName(principal.getPrincipalName());
     if (psn != null) {
       return psn.getFirstName() + " " + psn.getLastName();
     }
   }
   return null;
 }
 protected boolean checkDelegationMember(RoleDocumentDelegationMember newMember) {
   if (StringUtils.isBlank(newMember.getMemberTypeCode())
       || StringUtils.isBlank(newMember.getMemberId())) {
     GlobalVariables.getMessageMap()
         .putError(
             "document.delegationMember.memberId",
             RiceKeyConstants.ERROR_EMPTY_ENTRY,
             new String[] {"Member Type Code and Member ID"});
     return false;
   }
   if (MemberType.PRINCIPAL.getCode().equals(newMember.getMemberTypeCode())) {
     Principal principalInfo = getIdentityService().getPrincipal(newMember.getMemberId());
     if (principalInfo == null) {
       GlobalVariables.getMessageMap()
           .putError(
               "document.delegationMember.memberId",
               RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH,
               new String[] {newMember.getMemberId()});
       return false;
     } else {
       newMember.setMemberName(principalInfo.getPrincipalName());
     }
   } else if (MemberType.GROUP.getCode().equals(newMember.getMemberTypeCode())) {
     Group groupInfo = null;
     groupInfo = getGroupService().getGroup(newMember.getMemberId());
     if (groupInfo == null) {
       GlobalVariables.getMessageMap()
           .putError(
               "document.delegationMember.memberId",
               RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH,
               new String[] {newMember.getMemberId()});
       return false;
     } else {
       newMember.setMemberName(groupInfo.getName());
       newMember.setMemberNamespaceCode(groupInfo.getNamespaceCode());
     }
   } else if (MemberType.ROLE.getCode().equals(newMember.getMemberTypeCode())) {
     Role roleInfo = KimApiServiceLocator.getRoleService().getRole(newMember.getMemberId());
     if (roleInfo == null) {
       GlobalVariables.getMessageMap()
           .putError(
               "document.delegationMember.memberId",
               RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH,
               new String[] {newMember.getMemberId()});
       return false;
     } else {
       newMember.setMemberName(roleInfo.getName());
       newMember.setMemberNamespaceCode(roleInfo.getNamespaceCode());
     }
   }
   return true;
 }
  protected boolean checkKimDocumentRoleMember(KimDocumentRoleMember newMember) {
    boolean memberExists = false;
    String memberName = null;
    String memberNamespace = null;

    if (StringUtils.isBlank(newMember.getMemberId())) {
      GlobalVariables.getMessageMap()
          .putError(
              "document.member.memberId",
              RiceKeyConstants.ERROR_EMPTY_ENTRY,
              new String[] {"Member ID"});
      return false;
    }

    if (MemberType.PRINCIPAL.getCode().equals(newMember.getMemberTypeCode())) {
      Principal pi = this.getIdentityService().getPrincipal(newMember.getMemberId());
      if (pi != null) {
        memberExists = true;
        memberName = pi.getPrincipalName();
        memberNamespace = "";
      }
    } else if (MemberType.GROUP.getCode().equals(newMember.getMemberTypeCode())) {
      Group gi = KimApiServiceLocator.getGroupService().getGroup(newMember.getMemberId());
      if (gi != null) {
        memberExists = true;
        memberName = gi.getName();
        memberNamespace = gi.getNamespaceCode();
      }
    } else if (MemberType.ROLE.getCode().equals(newMember.getMemberTypeCode())) {
      Role ri = KimApiServiceLocator.getRoleService().getRole(newMember.getMemberId());
      if (!validateRole(newMember.getMemberId(), ri, "document.member.memberId", "Role")) {
        return false;
      } else {
        memberExists = true;
        memberName = ri.getName();
        memberNamespace = ri.getNamespaceCode();
      }
    }

    if (!memberExists) {
      GlobalVariables.getMessageMap()
          .putError(
              "document.member.memberId",
              RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH,
              new String[] {newMember.getMemberId()});
      return false;
    }
    newMember.setMemberName(memberName);
    newMember.setMemberNamespaceCode(memberNamespace);
    return true;
  }
 @Test
 public void testGetDefaultEntityByPrincipalName() {
   String principalName = "kuluser";
   EntityDefault info = identityService.getEntityDefaultByPrincipalName(principalName);
   assertNotNull("entity must not be null", info);
   assertNotNull("entity principals must not be null", info.getPrincipals());
   assertEquals("entity must have exactly 1 principal", 1, info.getPrincipals().size());
   for (Principal principalInfo : info.getPrincipals()) {
     assertEquals("Wrong principal name", principalName, principalInfo.getPrincipalName());
   }
   assertTrue(
       "entity external identifiers must not be null",
       (info.getExternalIdentifiers() == null) || info.getExternalIdentifiers().isEmpty());
 }