Search in sources :

Example 41 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class MemberAttributeServiceImpl method assignOwnership.

// give ownership to a new user
@Override
public GroupingsServiceResult assignOwnership(String groupingPath, String ownerUsername, String newOwnerUsername) {
    logger.info("assignOwnership; groupingPath: " + groupingPath + "; ownerUsername: " + ownerUsername + "; newOwnerUsername: " + newOwnerUsername + ";");
    String action = "give " + newOwnerUsername + " ownership of " + groupingPath;
    GroupingsServiceResult ownershipResult;
    if (isOwner(groupingPath, ownerUsername) || isAdmin(ownerUsername)) {
        WsSubjectLookup user = grouperFS.makeWsSubjectLookup(ownerUsername);
        WsAddMemberResults amr = grouperFS.makeWsAddMemberResults(groupingPath + OWNERS, user, newOwnerUsername);
        ownershipResult = hs.makeGroupingsServiceResult(amr, action);
        return ownershipResult;
    }
    ownershipResult = hs.makeGroupingsServiceResult(FAILURE + ", " + ownerUsername + " does not own " + groupingPath, action);
    return ownershipResult;
}
Also used : WsSubjectLookup(edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) WsAddMemberResults(edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)

Example 42 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceImpl method addMemberHelper.

// logic for adding a member
public List<GroupingsServiceResult> addMemberHelper(String username, String groupPath, Person personToAdd) {
    logger.info("addMemberHelper; user: " + username + "; group: " + groupPath + "; personToAdd: " + personToAdd + ";");
    List<GroupingsServiceResult> gsrList = new ArrayList<>();
    String action = "add users to " + groupPath;
    if (mas.isOwner(hs.parentGroupingPath(groupPath), username) || mas.isSuperuser(username) || personToAdd.getUsername().equals(username)) {
        WsSubjectLookup user = grouperFS.makeWsSubjectLookup(username);
        String composite = hs.parentGroupingPath(groupPath);
        String exclude = composite + EXCLUDE;
        String include = composite + INCLUDE;
        String owners = composite + OWNERS;
        boolean updateComposite = false;
        boolean updateExclude = false;
        boolean updateInclude = false;
        boolean updateOwners = false;
        // check to see if it is the include, exclude or owners
        if (groupPath.endsWith(INCLUDE)) {
            // if personToAdd is in exclude, get them out
            if (mas.isMember(exclude, personToAdd)) {
                WsDeleteMemberResults wsDeleteMemberResults = grouperFS.makeWsDeleteMemberResults(exclude, user, personToAdd);
                updateExclude = true;
                gsrList.add(hs.makeGroupingsServiceResult(wsDeleteMemberResults, "delete " + personToAdd.toString() + " from " + exclude));
            }
            // check to see if personToAdd is already in include
            if (!mas.isMember(include, personToAdd)) {
                // add to include
                WsAddMemberResults addMemberResults = grouperFS.makeWsAddMemberResults(include, user, personToAdd);
                updateInclude = true;
                gsrList.add(hs.makeGroupingsServiceResult(addMemberResults, action));
            } else {
                // They are already in the group, so just return SUCCESS
                gsrList.add(hs.makeGroupingsServiceResult(SUCCESS + ": " + personToAdd.toString() + " was already in " + groupPath, action));
            }
        } else // if exclude check if personToAdd is in the include
        if (groupPath.endsWith(EXCLUDE)) {
            // if personToAdd is in include, get them out
            if (mas.isMember(include, personToAdd)) {
                WsDeleteMemberResults wsDeleteMemberResults = grouperFS.makeWsDeleteMemberResults(include, user, personToAdd);
                updateInclude = true;
                gsrList.add(hs.makeGroupingsServiceResult(wsDeleteMemberResults, "delete " + personToAdd.toString() + " from " + include));
            }
            // check to see if userToAdd is already in exclude
            if (!mas.isMember(exclude, personToAdd)) {
                // add to exclude
                WsAddMemberResults addMemberResults = grouperFS.makeWsAddMemberResults(exclude, user, personToAdd);
                updateExclude = true;
                gsrList.add(hs.makeGroupingsServiceResult(addMemberResults, action));
            }
            // They are already in the group, so just return SUCCESS
            gsrList.add(hs.makeGroupingsServiceResult(SUCCESS + ": " + personToAdd.toString() + " was already in " + groupPath, action));
        } else // if owners check to see if the user is already in owners
        if (groupPath.endsWith(OWNERS)) {
            // check to see if userToAdd is already in owners
            if (!mas.isMember(owners, personToAdd)) {
                // add userToAdd to owners
                WsAddMemberResults addMemberResults = grouperFS.makeWsAddMemberResults(owners, user, personToAdd);
                updateOwners = true;
                gsrList.add(hs.makeGroupingsServiceResult(addMemberResults, action));
            }
            // They are already in the group, so just return SUCCESS
            gsrList.add(hs.makeGroupingsServiceResult(SUCCESS + ": " + personToAdd.toString() + " was already in " + groupPath, action));
        } else // Owners can only change include, exclude and owners groups
        {
            gsrList.add(hs.makeGroupingsServiceResult(FAILURE + ": " + username + " may only add to exclude, include or owner group", action));
        }
        // update groups that were changed
        if (updateExclude) {
            updateLastModified(exclude);
            updateComposite = true;
        }
        if (updateInclude) {
            updateLastModified(include);
            updateComposite = true;
        }
        if (updateComposite) {
            updateLastModified(composite);
        }
        if (updateOwners) {
            updateLastModified(owners);
        }
    } else {
        gsrList.add(hs.makeGroupingsServiceResult(FAILURE + ": " + username + "does not have permission to edit " + groupPath, action));
    }
    return gsrList;
}
Also used : WsSubjectLookup(edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) ArrayList(java.util.ArrayList) WsDeleteMemberResults(edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults) WsAddMemberResults(edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)

Example 43 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceImpl method addGroupingMemberByUuid.

// find a user by a uuid and add them to a grouping
@Override
public List<GroupingsServiceResult> addGroupingMemberByUuid(String username, String groupingPath, String userToAddUuid) {
    logger.info("addGroupingMemberByUuid; user: " + username + "; grouping: " + groupingPath + "; userToAdd: " + userToAddUuid + ";");
    List<GroupingsServiceResult> gsrs = new ArrayList<>();
    String action = "add user to " + groupingPath;
    String basis = groupingPath + BASIS;
    String exclude = groupingPath + EXCLUDE;
    String include = groupingPath + INCLUDE;
    Person personToAdd = new Person(null, userToAddUuid, null);
    boolean inBasis = mas.isMember(basis, personToAdd);
    boolean inComposite = mas.isMember(groupingPath, personToAdd);
    boolean inInclude = mas.isMember(include, personToAdd);
    // check to see if they are already in the grouping
    if (!inComposite) {
        // get them out of the exclude
        gsrs.add(deleteGroupMemberByUuid(username, exclude, userToAddUuid));
        // only add them to the include if they are not in the basis
        if (!inBasis) {
            gsrs.addAll(addGroupMemberByUuid(username, include, userToAddUuid));
        } else {
            gsrs.add(hs.makeGroupingsServiceResult(SUCCESS + ": " + userToAddUuid + " was in " + basis, action));
        }
    } else {
        gsrs.add(hs.makeGroupingsServiceResult(SUCCESS + ": " + userToAddUuid + " was already in " + groupingPath, action));
    }
    // should only be in one or the other
    if (inBasis && inInclude) {
        gsrs.add(deleteGroupMemberByUuid(username, include, userToAddUuid));
    }
    return gsrs;
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) ArrayList(java.util.ArrayList) Person(edu.hawaii.its.api.type.Person)

Aggregations

GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)43 Test (org.junit.Test)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)32 GroupingsServiceResultException (edu.hawaii.its.api.type.GroupingsServiceResultException)15 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)15 ArrayList (java.util.ArrayList)15 Grouping (edu.hawaii.its.api.type.Grouping)6 WsSubjectLookup (edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup)4 Person (edu.hawaii.its.api.type.Person)3 WsAddMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)3 WsDeleteMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults)2 WsGetAttributeAssignmentsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetAttributeAssignmentsResults)2 Group (edu.hawaii.its.api.type.Group)1 GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)1 Membership (edu.hawaii.its.api.type.Membership)1 WsResultMeta (edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta)1 WsStemLookup (edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1