Search in sources :

Example 16 with Meta

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

the class ServiceProviderConfigWS method serve.

@GET
@Produces(MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT)
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@RejectFilterParam
public Response serve() {
    try {
        ServiceProviderConfig serviceProviderConfig = new ServiceProviderConfig();
        serviceProviderConfig.getFilter().setMaxResults(appConfiguration.getMaxCount());
        Meta meta = new Meta();
        meta.setLocation(endpointUrl);
        meta.setResourceType(ScimResourceUtil.getType(serviceProviderConfig.getClass()));
        serviceProviderConfig.setMeta(meta);
        serviceProviderConfig.setAuthenticationSchemes(Collections.singletonList(AuthenticationScheme.createOAuth2(true)));
        return Response.ok(resourceSerializer.serialize(serviceProviderConfig)).build();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
}
Also used : ServiceProviderConfig(io.jans.scim.model.scim2.provider.config.ServiceProviderConfig) Meta(io.jans.scim.model.scim2.Meta) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RejectFilterParam(io.jans.scim.service.scim2.interceptor.RejectFilterParam)

Example 17 with Meta

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

the class Fido2DeviceTest method updateWithObject.

@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject() throws Exception {
    logger.debug("Updating device to original attributes");
    Response response = client.updateF2Device(device, device.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    Fido2DeviceResource updated = response.readEntity(fido2Class);
    // Naively compare (property-to-property) the original and new object. It's feasible since all of them are strings
    for (String path : IntrospectUtil.allAttrs.get(fido2Class)) {
        String val = BeanUtils.getProperty(device, path);
        // Exclude metas since they diverge and skip if original attribute was null (when passing null for an update, server ignores)
        if (!path.startsWith("meta") && val != null) {
            assertEquals(BeanUtils.getProperty(updated, path), val);
        }
    }
    // Update an immutable attribute
    updated.setCounter(Integer.MIN_VALUE);
    response = client.updateF2Device(updated, updated.getId(), null, null);
    assertEquals(response.getStatus(), BAD_REQUEST.getStatusCode());
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 18 with Meta

use of io.jans.scim.model.scim2.Meta in project oxTrust by GluuFederation.

the class CopyUtils2 method copy.

public FidoDevice copy(GluuCustomFidoDevice source, FidoDevice destination) {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        destination = new FidoDevice();
    }
    destination.setId(source.getId());
    destination.setCreationDate(source.getCreationDate());
    destination.setApplication(source.getApplication());
    destination.setCounter(source.getCounter());
    destination.setDeviceData(source.getDeviceData());
    destination.setDeviceHashCode(source.getDeviceHashCode());
    destination.setDeviceKeyHandle(source.getDeviceKeyHandle());
    destination.setDeviceRegistrationConf(source.getDeviceRegistrationConf());
    destination.setLastAccessTime(source.getLastAccessTime());
    destination.setStatus(source.getStatus());
    destination.setDisplayName(source.getDisplayName());
    destination.setDescription(source.getDescription());
    if (source.getDn() != null) {
        String[] dnArray = source.getDn().split("\\,");
        for (String e : dnArray) {
            if (e.startsWith("inum=")) {
                String[] inumArray = e.split("\\=");
                if (inumArray.length > 1) {
                    destination.setUserId(inumArray[1]);
                }
            }
        }
    }
    Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
    if (source.getMetaVersion() != null) {
        meta.setVersion(source.getMetaVersion());
    }
    String location = source.getMetaLocation();
    if (location != null && !location.isEmpty()) {
        if (!location.startsWith("https://") && !location.startsWith("http://")) {
            location = appConfiguration.getBaseEndpoint() + location;
        }
    } else {
        location = appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices/" + source.getId();
    }
    meta.setLocation(location);
    if (source.getCreationDate() != null && !source.getCreationDate().isEmpty()) {
        try {
            meta.setCreated(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getCreationDate()));
        } catch (Exception e) {
            log.error(" Date parse exception (OLD format)", e);
        }
    }
    if (source.getMetaLastModified() != null && !source.getMetaLastModified().isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getMetaLastModified(), DateTimeZone.UTC);
            meta.setLastModified(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            try {
                meta.setLastModified(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getMetaLastModified()));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    destination.setMeta(meta);
    return destination;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) SimpleDateFormat(java.text.SimpleDateFormat) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DateTime(org.joda.time.DateTime)

Example 19 with Meta

use of io.jans.scim.model.scim2.Meta in project oxTrust by GluuFederation.

the class GroupCoreLoadingStrategy method load.

@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
    log.info(" load() ");
    Meta meta = new Meta();
    meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);
    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer();
    serializer.setSchemaType(schemaType);
    groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer);
    mapper.registerModule(groupCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyGroup());
    return serializer.getSchemaType();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaTypeGroupSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeGroupSerializer) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 20 with Meta

use of io.jans.scim.model.scim2.Meta in project oxTrust by GluuFederation.

the class UserCoreLoadingStrategy method load.

@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
    log.info(" load() ");
    Meta meta = new Meta();
    meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);
    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer();
    serializer.setSchemaType(schemaType);
    userCoreLoadingStrategyModule.addSerializer(User.class, serializer);
    mapper.registerModule(userCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyUser());
    return serializer.getSchemaType();
}
Also used : SchemaTypeUserSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeUserSerializer) Meta(org.gluu.oxtrust.model.scim2.Meta) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Aggregations

Meta (org.gluu.oxtrust.model.scim2.Meta)20 ArrayList (java.util.ArrayList)9 Meta (io.jans.scim.model.scim2.Meta)8 DefaultValue (javax.ws.rs.DefaultValue)7 GET (javax.ws.rs.GET)7 HeaderParam (javax.ws.rs.HeaderParam)7 Produces (javax.ws.rs.Produces)7 URI (java.net.URI)5 Date (java.util.Date)4 Path (javax.ws.rs.Path)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ResourceType (org.gluu.oxtrust.model.scim2.provider.ResourceType)4 UserResource (io.jans.scim.model.scim2.user.UserResource)3 IOException (java.io.IOException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashSet (java.util.HashSet)3 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)3 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)3 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)3 GluuGroup (org.gluu.oxtrust.model.GluuGroup)3