Search in sources :

Example 1 with UserResource

use of org.gluu.oxtrust.model.scim2.user.UserResource in project oxTrust by GluuFederation.

the class UserWebService method createUser.

/**
 */
@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Create user", notes = "https://tools.ietf.org/html/rfc7644#section-3.3", response = UserResource.class)
public Response createUser(@ApiParam(value = "User", required = true) UserResource user, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. createUser");
        scim2UserService.createUser(user, endpointUrl);
        String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
        response = Response.created(new URI(user.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at createUser 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) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 2 with UserResource

use of org.gluu.oxtrust.model.scim2.user.UserResource 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)

Example 3 with UserResource

use of org.gluu.oxtrust.model.scim2.user.UserResource in project oxTrust by GluuFederation.

the class Scim2UserService method transferAttributesToUserResource.

public void transferAttributesToUserResource(GluuCustomPerson person, UserResource res, String url) {
    log.debug("transferAttributesToUserResource");
    res.setId(person.getInum());
    res.setExternalId(person.getAttribute("oxTrustExternalId"));
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(person.getAttribute("oxTrustMetaCreated"));
    if (meta.getCreated() == null) {
        Date tmpDate = person.getCreationDate();
        meta.setCreated(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
    }
    meta.setLastModified(person.getAttribute("oxTrustMetaLastModified"));
    if (meta.getLastModified() == null) {
        Date tmpDate = person.getUpdatedAt();
        meta.setLastModified(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
    }
    meta.setLocation(person.getAttribute("oxTrustMetaLocation"));
    if (meta.getLocation() == null)
        meta.setLocation(url + "/" + person.getInum());
    res.setMeta(meta);
    // Set values in order of appearance in UserResource class
    res.setUserName(person.getUid());
    Name name = new Name();
    name.setGivenName(person.getGivenName());
    name.setFamilyName(person.getSurname());
    name.setMiddleName(person.getAttribute("middleName"));
    name.setHonorificPrefix(person.getAttribute("oxTrusthonorificPrefix"));
    name.setHonorificSuffix(person.getAttribute("oxTrusthonorificSuffix"));
    String formatted = person.getAttribute("oxTrustNameFormatted");
    if (// recomputes the formatted name if absent in LDAP
    formatted == null)
        name.computeFormattedName();
    else
        name.setFormatted(formatted);
    res.setName(name);
    res.setDisplayName(person.getDisplayName());
    res.setNickName(person.getAttribute("nickname"));
    res.setProfileUrl(person.getAttribute("oxTrustProfileURL"));
    res.setTitle(person.getAttribute("oxTrustTitle"));
    res.setUserType(person.getAttribute("oxTrustUserType"));
    res.setPreferredLanguage(person.getPreferredLanguage());
    res.setLocale(person.getAttribute("locale"));
    res.setTimezone(person.getTimezone());
    res.setActive(Boolean.valueOf(person.getAttribute("oxTrustActive")) || GluuBoolean.getByValue(person.getAttribute("gluuStatus")).isBooleanValue());
    res.setPassword(person.getUserPassword());
    res.setEmails(getAttributeListValue(person, Email.class, "oxTrustEmail"));
    res.setPhoneNumbers(getAttributeListValue(person, PhoneNumber.class, "oxTrustPhoneValue"));
    res.setIms(getAttributeListValue(person, InstantMessagingAddress.class, "oxTrustImsValue"));
    res.setPhotos(getAttributeListValue(person, Photo.class, "oxTrustPhotos"));
    res.setAddresses(getAttributeListValue(person, Address.class, "oxTrustAddresses"));
    List<String> listOfGroups = person.getMemberOf();
    if (listOfGroups != null && listOfGroups.size() > 0) {
        List<Group> groupList = new ArrayList<Group>();
        for (String groupDN : listOfGroups) {
            try {
                GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
                Group group = new Group();
                group.setValue(gluuGroup.getInum());
                String reference = groupWS.getEndpointUrl() + "/" + gluuGroup.getInum();
                group.setRef(reference);
                group.setDisplay(gluuGroup.getDisplayName());
                // Only support direct membership: see section 4.1.2 of RFC 7644
                group.setType(Group.Type.DIRECT);
                groupList.add(group);
            } catch (Exception e) {
                log.warn("transferAttributesToUserResource. Group with dn {} could not be added to User Resource. {}", groupDN, person.getUid());
                log.error(e.getMessage(), e);
            }
        }
        if (groupList.size() > 0)
            res.setGroups(groupList);
    }
    res.setEntitlements(getAttributeListValue(person, Entitlement.class, "oxTrustEntitlements"));
    res.setRoles(getAttributeListValue(person, Role.class, "oxTrustRole"));
    res.setX509Certificates(getAttributeListValue(person, X509Certificate.class, "oxTrustx509Certificate"));
    res.setPairwiseIdentitifers(person.getOxPPID());
    transferExtendedAttributesToResource(person, res);
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.user.Group) Email(org.gluu.oxtrust.model.scim2.user.Email) Address(org.gluu.oxtrust.model.scim2.user.Address) InstantMessagingAddress(org.gluu.oxtrust.model.scim2.user.InstantMessagingAddress) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.user.Photo) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Date(java.util.Date) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) WebApplicationException(javax.ws.rs.WebApplicationException) X509Certificate(org.gluu.oxtrust.model.scim2.user.X509Certificate) Name(org.gluu.oxtrust.model.scim2.user.Name) Role(org.gluu.oxtrust.model.scim2.user.Role) PhoneNumber(org.gluu.oxtrust.model.scim2.user.PhoneNumber) Entitlement(org.gluu.oxtrust.model.scim2.user.Entitlement) InstantMessagingAddress(org.gluu.oxtrust.model.scim2.user.InstantMessagingAddress)

Example 4 with UserResource

use of org.gluu.oxtrust.model.scim2.user.UserResource in project oxTrust by GluuFederation.

the class Scim2UserService method searchUsers.

public ListViewResponse<BaseScimResource> searchUsers(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url, int maxCount) throws Exception {
    Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "inum=*", UserResource.class);
    log.info("Executing search for users using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
    ListViewResponse<GluuCustomPerson> list = ldapEntryManager.findListViewResponse(personService.getDnForPerson(null), GluuCustomPerson.class, ldapFilter, startIndex, count, maxCount, sortBy, sortOrder, null);
    List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
    for (GluuCustomPerson person : list.getResult()) {
        UserResource scimUsr = new UserResource();
        transferAttributesToUserResource(person, scimUsr, url);
        resources.add(scimUsr);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalResults(), list.getResult().size());
    ListViewResponse<BaseScimResource> result = new ListViewResponse<BaseScimResource>();
    result.setResult(resources);
    result.setTotalResults(list.getTotalResults());
    return result;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Filter(org.gluu.search.filter.Filter) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource)

Example 5 with UserResource

use of org.gluu.oxtrust.model.scim2.user.UserResource in project oxTrust by GluuFederation.

the class BulkWebService method execute.

private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
    Response response = null;
    String idCreated = null;
    try {
        if (ws == userWS)
            switch(verb) {
                case PUT:
                    UserResource user = mapper.readValue(data, UserResource.class);
                    response = userWS.updateUser(user, fragment, "id", null);
                    break;
                case DELETE:
                    response = userWS.deleteUser(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = userWS.patchUser(pr, fragment, "id", null);
                    break;
                case POST:
                    user = mapper.readValue(data, UserResource.class);
                    response = userWS.createUser(user, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        user = mapper.readValue(response.getEntity().toString(), UserResource.class);
                        idCreated = user.getId();
                    }
                    break;
            }
        else if (ws == groupWS)
            switch(verb) {
                case PUT:
                    GroupResource group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.updateGroup(group, fragment, "id", null);
                    break;
                case DELETE:
                    response = groupWS.deleteGroup(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = groupWS.patchGroup(pr, fragment, "id", null);
                    break;
                case POST:
                    group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.createGroup(group, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
                        idCreated = group.getId();
                    }
                    break;
            }
        else if (ws == fidoDeviceWS)
            switch(verb) {
                case PUT:
                    FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
                    response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fidoDeviceWS.deleteDevice(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fidoDeviceWS.createDevice();
                    break;
            }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return new Pair<Response, String>(response, idCreated);
}
Also used : Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.bulk.BulkResponse) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) PatchRequest(org.gluu.oxtrust.model.scim2.patch.PatchRequest) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) Pair(org.xdi.util.Pair)

Aggregations

UserResource (org.gluu.oxtrust.model.scim2.user.UserResource)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)5 Response (javax.ws.rs.core.Response)5 ListViewResponse (org.gluu.persist.model.ListViewResponse)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 URI (java.net.URI)4 DefaultValue (javax.ws.rs.DefaultValue)4 HeaderParam (javax.ws.rs.HeaderParam)4 Produces (javax.ws.rs.Produces)4 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)4 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)4 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)4 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)4 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)4 Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1