Search in sources :

Example 41 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.

the class ServiceUtil method deleteGroupFromPerson.

/**
 * Delete a Group from a Person
 *
 * @return void
 * @throws Exception
 */
public void deleteGroupFromPerson(GluuGroup group, String dn) throws Exception {
    List<String> persons = group.getMembers();
    for (String onePerson : persons) {
        GluuCustomPerson gluuPerson = personService.getPersonByDn(onePerson);
        List<String> memberOflist = gluuPerson.getMemberOf();
        List<String> tempMemberOf = new ArrayList<String>();
        for (String aMemberOf : memberOflist) {
            tempMemberOf.add(aMemberOf);
        }
        for (String oneMemberOf : tempMemberOf) {
            if (oneMemberOf.equalsIgnoreCase(dn)) {
                tempMemberOf.remove(oneMemberOf);
                break;
            }
        }
        List<String> cleanMemberOf = new ArrayList<String>();
        for (String aMemberOf : tempMemberOf) {
            cleanMemberOf.add(aMemberOf);
        }
        gluuPerson.setMemberOf(cleanMemberOf);
        personService.updatePerson(gluuPerson);
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson)

Example 42 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.

the class UserWebService method deleteUser.

@Path("{id}")
@DELETE
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@ApiOperation(value = "Delete User", notes = "Delete User (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteUser(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteUser");
        // person cannot be null (check associated decorator method)
        GluuCustomPerson person = personService.getPersonByInum(id);
        scim2UserService.deleteUser(person);
        response = Response.noContent().build();
    } catch (Exception e) {
        log.error("Failure at deleteUser method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) DELETE(javax.ws.rs.DELETE) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 43 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.

the class Scim2GroupService method transferAttributesToGroupResource.

public void transferAttributesToGroupResource(GluuGroup gluuGroup, GroupResource res, String groupsUrl, String usersUrl) {
    res.setId(gluuGroup.getInum());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(gluuGroup.getAttribute("oxTrustMetaCreated"));
    meta.setLastModified(gluuGroup.getAttribute("oxTrustMetaLastModified"));
    meta.setLocation(gluuGroup.getAttribute("oxTrustMetaLocation"));
    if (meta.getLocation() == null)
        meta.setLocation(groupsUrl + "/" + gluuGroup.getInum());
    res.setMeta(meta);
    res.setDisplayName(gluuGroup.getDisplayName());
    // Transfer members from GluuGroup to GroupResource
    List<String> memberDNs = gluuGroup.getMembers();
    if (memberDNs != null) {
        Set<Member> members = new HashSet<Member>();
        for (String dn : memberDNs) {
            GluuCustomPerson person = null;
            try {
                person = personService.getPersonByDn(dn);
            } catch (Exception e) {
                log.warn("Wrong member entry {} found in group {}", dn, gluuGroup.getDisplayName());
            }
            if (person != null) {
                Member aMember = new Member();
                aMember.setValue(person.getInum());
                aMember.setRef(usersUrl + "/" + person.getInum());
                aMember.setType(ScimResourceUtil.getType(UserResource.class));
                aMember.setDisplay(person.getDisplayName());
                members.add(aMember);
            }
        }
        res.setMembers(members);
    }
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) Member(org.gluu.oxtrust.model.scim2.group.Member) WebApplicationException(javax.ws.rs.WebApplicationException) HashSet(java.util.HashSet)

Example 44 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.

the class Scim2GroupService method syncMemberAttributeInPerson.

private void syncMemberAttributeInPerson(String groupDn, List<String> beforeMemberDns, List<String> afterMemberDns) {
    log.debug("syncMemberAttributeInPerson. Updating memberOf attribute in user LDAP entries");
    log.trace("Before member dns {}; After member dns {}", beforeMemberDns, afterMemberDns);
    // Build 2 sets of DNs
    Set<String> before = new HashSet<String>();
    if (beforeMemberDns != null)
        before.addAll(beforeMemberDns);
    Set<String> after = new HashSet<String>();
    if (afterMemberDns != null)
        after.addAll(afterMemberDns);
    // Do removals
    for (String dn : before) {
        if (!after.contains(dn)) {
            try {
                GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
                List<String> memberOf = new ArrayList<String>();
                memberOf.addAll(gluuPerson.getMemberOf());
                memberOf.remove(groupDn);
                gluuPerson.setMemberOf(memberOf);
                personService.updatePerson(gluuPerson);
            } catch (Exception e) {
                log.error("An error occurred while removing user {} from group {}", dn, groupDn);
                log.error(e.getMessage(), e);
            }
        }
    }
    // Do insertions
    for (String dn : after) {
        if (!before.contains(dn)) {
            try {
                GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
                List<String> memberOf = new ArrayList<String>();
                memberOf.add(groupDn);
                if (gluuPerson.getMemberOf() != null)
                    memberOf.addAll(gluuPerson.getMemberOf());
                gluuPerson.setMemberOf(memberOf);
                personService.updatePerson(gluuPerson);
            } catch (Exception e) {
                log.error("An error occurred while adding user {} to group {}", dn, groupDn);
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) WebApplicationException(javax.ws.rs.WebApplicationException) HashSet(java.util.HashSet)

Example 45 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.

the class Scim2UserService method updateUser.

public UserResource updateUser(String id, UserResource user, String url) throws InvalidAttributeValueException {
    // This is never null (see decorator involved)
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    UserResource tmpUser = new UserResource();
    transferAttributesToUserResource(gluuPerson, tmpUser, url);
    long now = System.currentTimeMillis();
    tmpUser.getMeta().setLastModified(ISODateTimeFormat.dateTime().withZoneUTC().print(now));
    tmpUser = (UserResource) ScimResourceUtil.transferToResourceReplace(user, tmpUser, extService.getResourceExtensions(user.getClass()));
    replacePersonInfo(gluuPerson, tmpUser, url);
    return tmpUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)114 ArrayList (java.util.ArrayList)37 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)27 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 Test (org.testng.annotations.Test)21 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)18 Produces (javax.ws.rs.Produces)17 Response (javax.ws.rs.core.Response)17 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)14 ScimPersonGroups (org.gluu.oxtrust.model.scim.ScimPersonGroups)14 ScimPersonIms (org.gluu.oxtrust.model.scim.ScimPersonIms)14 ScimPersonPhones (org.gluu.oxtrust.model.scim.ScimPersonPhones)14 ScimPersonPhotos (org.gluu.oxtrust.model.scim.ScimPersonPhotos)14 ScimRoles (org.gluu.oxtrust.model.scim.ScimRoles)14 PersonMeta (org.gluu.oxtrust.model.scim.PersonMeta)13 ScimEntitlements (org.gluu.oxtrust.model.scim.ScimEntitlements)13 ScimName (org.gluu.oxtrust.model.scim.ScimName)13 ScimPersonAddresses (org.gluu.oxtrust.model.scim.ScimPersonAddresses)13 ScimPersonEmails (org.gluu.oxtrust.model.scim.ScimPersonEmails)13 ScimCustomAttributes (org.gluu.oxtrust.model.scim.ScimCustomAttributes)12