Search in sources :

Example 6 with WsAddMemberResults

use of edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults 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 7 with WsAddMemberResults

use of edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults 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 8 with WsAddMemberResults

use of edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceImpl method addAdmin.

// adds a user to the admins group
@Override
public GroupingsServiceResult addAdmin(String currentAdminUsername, String newAdminUsername) {
    logger.info("addAdmin; username: " + currentAdminUsername + "; newAdmin: " + newAdminUsername + ";");
    String action = "add " + newAdminUsername + " to " + GROUPING_ADMINS;
    if (mas.isSuperuser(currentAdminUsername)) {
        if (mas.isAdmin(newAdminUsername)) {
            // todo replace hard coded string with value from top
            return hs.makeGroupingsServiceResult("SUCCESS: " + newAdminUsername + " was already in" + GROUPING_ADMINS, action);
        }
        WsAddMemberResults addMemberResults = grouperFS.makeWsAddMemberResults(GROUPING_ADMINS, newAdminUsername);
        return hs.makeGroupingsServiceResult(addMemberResults, action);
    }
    // todo replace hard coded string with value from top
    return hs.makeGroupingsServiceResult("FAILURE: " + currentAdminUsername + " is not an admin", action);
}
Also used : WsAddMemberResults(edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)

Aggregations

WsAddMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)7 GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)3 WsResultMeta (edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta)3 WsSubjectLookup (edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Group (edu.hawaii.its.api.type.Group)1 Grouping (edu.hawaii.its.api.type.Grouping)1 Person (edu.hawaii.its.api.type.Person)1 GcAddMember (edu.internet2.middleware.grouperClient.api.GcAddMember)1 WsDeleteMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults)1 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)1