Search in sources :

Example 6 with Attribute

use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.

the class FidoDeviceWebService method updateDevice.

@Path("{id}")
@PUT
@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(scopes = { "https://jans.io/scim/fido.write" })
@RefAdjusted
public Response updateDevice(FidoDeviceResource fidoDeviceResource, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. updateDevice");
        // remove externalId, no place to store it in LDAP
        fidoDeviceResource.setExternalId(null);
        if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
            throw new SCIMException("Parameter id does not match id attribute of Device");
        String userId = fidoDeviceResource.getUserId();
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fidoResourceType);
        if (response != null)
            return response;
        executeValidation(fidoDeviceResource, true);
        FidoDeviceResource updatedResource = new FidoDeviceResource();
        transferAttributesToFidoResource(device, updatedResource, endpointUrl, userId);
        updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
        updatedResource = (FidoDeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
        transferAttributesToDevice(updatedResource, device);
        fidoDeviceService.updateGluuCustomFidoDevice(device);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (SCIMException e) {
        log.error("Validation check error: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SCIMException(io.jans.scim.model.exception.SCIMException) GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 7 with Attribute

use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.

the class Fido2DeviceWebService method updateF2Device.

@Path("{id}")
@PUT
@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(scopes = { "https://jans.io/scim/fido2.write" })
@RefAdjusted
public Response updateF2Device(Fido2DeviceResource fidoDeviceResource, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. updateDevice");
        // remove externalId, no place to store it in LDAP
        fidoDeviceResource.setExternalId(null);
        if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
            throw new SCIMException("Parameter id does not match id attribute of Device");
        String userId = fidoDeviceResource.getUserId();
        GluuFido2Device device = fidoDeviceService.getFido2DeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fido2ResourceType);
        response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fido2ResourceType);
        if (response != null)
            return response;
        executeValidation(fidoDeviceResource, true);
        Fido2DeviceResource updatedResource = new Fido2DeviceResource();
        transferAttributesToFido2Resource(device, updatedResource, endpointUrl, userId);
        updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
        updatedResource = (Fido2DeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
        transferAttributesToDevice(updatedResource, device);
        fidoDeviceService.updateFido2Device(device);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (SCIMException e) {
        log.error("Validation check error: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) SCIMException(io.jans.scim.model.exception.SCIMException) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) GluuFido2Device(io.jans.scim.model.GluuFido2Device) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 8 with Attribute

use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.

the class GroupWebService method updateGroup.

/**
 * This implementation differs from spec in the following aspects:
 * - Passing a null value for an attribute, does not modify the attribute in the destination, however passing an
 * empty array for a multivalued attribute does clear the attribute. Thus, to clear single-valued attribute, PATCH
 * operation should be used
 */
@Path("{id}")
@PUT
@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(scopes = { "https://jans.io/scim/groups.write" })
@RefAdjusted
public Response updateGroup(GroupResource group, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. updateGroup");
        // empty externalId, no place to store it in LDAP
        group.setExternalId(null);
        // Check if the ids match in case the group coming has one
        if (group.getId() != null && !group.getId().equals(id))
            throw new SCIMException("Parameter id does not match with id attribute of Group");
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        if (gluuGroup == null)
            return notFoundResponse(id, groupResourceType);
        response = externalConstraintsService.applyEntityCheck(gluuGroup, group, httpHeaders, uriInfo, HttpMethod.PUT, groupResourceType);
        if (response != null)
            return response;
        executeValidation(group, true);
        if (StringUtils.isNotEmpty(group.getDisplayName())) {
            checkDisplayNameExistence(group.getDisplayName(), id);
        }
        boolean skipValidation = isMembersValidationSkipped();
        boolean displayExcluded = isDisplayExcluded(skipValidation, attrsList, excludedAttrsList);
        GroupResource updatedResource = scim2GroupService.updateGroup(gluuGroup, group, skipValidation, !displayExcluded, endpointUrl, usersUrl);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (DuplicateEntryException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
    } catch (SCIMException e) {
        log.error("Validation check at updateGroup returned: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateGroup method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SCIMException(io.jans.scim.model.exception.SCIMException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) GluuGroup(io.jans.scim.model.GluuGroup) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) GroupResource(io.jans.scim.model.scim2.group.GroupResource) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 9 with Attribute

use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.

the class Scim2UserService method transferAttributesToUserResource.

public void transferAttributesToUserResource(ScimCustomPerson person, UserResource res, String url) {
    log.debug("transferAttributesToUserResource");
    res.setId(person.getInum());
    res.setExternalId(person.getAttribute("jansExtId"));
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(person.getAttribute("jansMetaCreated"));
    if (meta.getCreated() == null) {
        Date date = person.getCreationDate();
        meta.setCreated(date == null ? null : DateUtil.millisToISOString(date.getTime()));
    }
    meta.setLastModified(person.getAttribute("jansMetaLastMod"));
    if (meta.getLastModified() == null) {
        Date date = person.getUpdatedAt();
        meta.setLastModified(date == null ? null : DateUtil.millisToISOString(date.getTime()));
    }
    meta.setLocation(person.getAttribute("jansMetaLocation"));
    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("jansHonorificPrefix"));
    name.setHonorificSuffix(person.getAttribute("jansHonorificSuffix"));
    String formatted = person.getAttribute("jansNameFormatted");
    if (formatted == null) {
        // recomputes the formatted name if absent in LDAP
        name.computeFormattedName();
    } else {
        name.setFormatted(formatted);
    }
    res.setName(name);
    res.setDisplayName(person.getDisplayName());
    res.setNickName(person.getAttribute("nickname"));
    res.setProfileUrl(person.getAttribute("jansProfileURL"));
    res.setTitle(person.getAttribute("jansTitle"));
    res.setUserType(person.getAttribute("jansUsrTyp"));
    res.setPreferredLanguage(person.getPreferredLanguage());
    res.setLocale(person.getAttribute("locale"));
    res.setTimezone(person.getTimezone());
    res.setActive(Boolean.valueOf(person.getAttribute("jansActive")) || GluuBoolean.getByValue(person.getAttribute("jansStatus")).isBooleanValue());
    res.setPassword(person.getUserPassword());
    res.setEmails(getAttributeListValue(person, Email.class, "jansEmail"));
    if (res.getEmails() == null) {
        // There can be cases where jansEmail is not synced with mail attribute....
        List<Email> emails = person.getAttributeList("mail").stream().map(m -> {
            Email email = new Email();
            email.setValue(m);
            email.setPrimary(false);
            return email;
        }).collect(Collectors.toList());
        res.setEmails(emails.size() == 0 ? null : emails);
    }
    res.setPhoneNumbers(getAttributeListValue(person, PhoneNumber.class, "jansPhoneValue"));
    res.setIms(getAttributeListValue(person, InstantMessagingAddress.class, "jansImsValue"));
    res.setPhotos(getAttributeListValue(person, Photo.class, "jansPhotos"));
    res.setAddresses(getAttributeListValue(person, Address.class, "jansAddres"));
    List<String> listOfGroups = person.getMemberOf();
    if (listOfGroups != null && listOfGroups.size() > 0) {
        List<Group> groupList = new ArrayList<>();
        for (String groupDN : listOfGroups) {
            try {
                GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
                Group group = new Group();
                group.setValue(gluuGroup.getInum());
                String reference = groupEndpointUrl + "/" + 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, "jansEntitlements"));
    res.setRoles(getAttributeListValue(person, Role.class, "jansRole"));
    res.setX509Certificates(getAttributeListValue(person, X509Certificate.class, "jansx509Certificate"));
    res.setPairwiseIdentifiers(person.getPpid());
    transferExtendedAttributesToResource(person, res);
}
Also used : ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) Path(javax.ws.rs.Path) Meta(io.jans.scim.model.scim2.Meta) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) GluuStatus(io.jans.model.GluuStatus) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) Map(java.util.Map) GluuGroup(io.jans.scim.model.GluuGroup) SortOrder(io.jans.orm.model.SortOrder) ScimCustomPerson(io.jans.scim.model.scim.ScimCustomPerson) UserResource(io.jans.scim.model.scim2.user.UserResource) Collection(java.util.Collection) IntrospectUtil(io.jans.scim.model.scim2.util.IntrospectUtil) AppConfiguration(io.jans.scim.model.conf.AppConfiguration) Address(io.jans.scim.model.scim2.user.Address) ScimFilterParserService(io.jans.scim.service.antlr.scimFilter.ScimFilterParserService) Collectors(java.util.stream.Collectors) PersistenceEntryManager(io.jans.orm.PersistenceEntryManager) X509Certificate(io.jans.scim.model.scim2.user.X509Certificate) Serializable(java.io.Serializable) List(java.util.List) Group(io.jans.scim.model.scim2.user.Group) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationScoped(javax.enterprise.context.ApplicationScoped) GluuBoolean(io.jans.scim.model.GluuBoolean) GroupService(io.jans.scim.service.GroupService) Photo(io.jans.scim.model.scim2.user.Photo) Filter(io.jans.orm.search.filter.Filter) Extension(io.jans.scim.model.scim2.extensions.Extension) Email(io.jans.scim.model.scim2.user.Email) HashMap(java.util.HashMap) DateUtil(io.jans.scim.model.scim2.util.DateUtil) PairwiseIdentifier(io.jans.as.persistence.model.PairwiseIdentifier) ArrayList(java.util.ArrayList) ScimResourceUtil(io.jans.scim.model.scim2.util.ScimResourceUtil) Inject(javax.inject.Inject) InstantMessagingAddress(io.jans.scim.model.scim2.user.InstantMessagingAddress) PersonService(io.jans.scim.service.PersonService) Role(io.jans.scim.model.scim2.user.Role) Entitlement(io.jans.scim.model.scim2.user.Entitlement) GroupWebService(io.jans.scim.ws.rs.scim2.GroupWebService) ServiceUtil(io.jans.scim.util.ServiceUtil) Status(javax.ws.rs.core.Response.Status) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Name(io.jans.scim.model.scim2.user.Name) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) ExternalScimService(io.jans.scim.service.external.ExternalScimService) PagedResult(io.jans.orm.model.PagedResult) Meta(io.jans.scim.model.scim2.Meta) GluuGroup(io.jans.scim.model.GluuGroup) Group(io.jans.scim.model.scim2.user.Group) Email(io.jans.scim.model.scim2.user.Email) Address(io.jans.scim.model.scim2.user.Address) InstantMessagingAddress(io.jans.scim.model.scim2.user.InstantMessagingAddress) ArrayList(java.util.ArrayList) Photo(io.jans.scim.model.scim2.user.Photo) GluuGroup(io.jans.scim.model.GluuGroup) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) X509Certificate(io.jans.scim.model.scim2.user.X509Certificate) Name(io.jans.scim.model.scim2.user.Name) Role(io.jans.scim.model.scim2.user.Role) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) Entitlement(io.jans.scim.model.scim2.user.Entitlement) InstantMessagingAddress(io.jans.scim.model.scim2.user.InstantMessagingAddress)

Example 10 with Attribute

use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.

the class BaseScimWebService method executeValidation.

protected void executeValidation(BaseScimResource resource, boolean laxRequiredness) throws SCIMException {
    ResourceValidator rv = new ResourceValidator(resource, extService.getResourceExtensions(resource.getClass()));
    if (!laxRequiredness) {
        rv.validateSchemasAttribute();
    }
    rv.validateRequiredAttributes(laxRequiredness);
    rv.validateValidableAttributes();
    // By section 7 of RFC 7643, we are not forced to constrain attribute values when they have a list of canonical values associated
    // rv.validateCanonicalizedAttributes();
    rv.validateExtendedAttributes();
}
Also used : ResourceValidator(io.jans.scim.model.scim2.util.ResourceValidator)

Aggregations

Response (javax.ws.rs.core.Response)19 UserResource (io.jans.scim.model.scim2.user.UserResource)13 ListResponse (io.jans.scim.model.scim2.ListResponse)12 Test (org.testng.annotations.Test)12 SCIMException (io.jans.scim.model.exception.SCIMException)11 Attribute (io.jans.scim.model.scim2.annotations.Attribute)11 Field (java.lang.reflect.Field)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)11 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)11 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)10 Extension (io.jans.scim.model.scim2.extensions.Extension)9 UserBaseTest (io.jans.scim2.client.UserBaseTest)7 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)5 NullType (javax.lang.model.type.NullType)5 Path (javax.ws.rs.Path)5 SearchRequest (io.jans.scim.model.scim2.SearchRequest)4 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)4 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)4 BaseTest (io.jans.scim2.client.BaseTest)4 URI (java.net.URI)4