Search in sources :

Example 1 with FidoDevice

use of org.gluu.oxtrust.model.scim2.fido.FidoDevice in project oxTrust by GluuFederation.

the class ResourceTypeWS method listResources.

@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listResources(@HeaderParam("Authorization") String authorization) throws Exception {
    ListResponse listResponse = new ListResponse();
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
    listResponse.setSchemas(schemas);
    // START: User
    ResourceType userResourceType = new ResourceType();
    userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
    userResourceType.setEndpoint("/v2/Users");
    userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
    Meta userMeta = new Meta();
    userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    userMeta.setResourceType("ResourceType");
    userResourceType.setMeta(userMeta);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
    userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
    userExtensionSchema.setRequired(false);
    schemaExtensions.add(userExtensionSchema);
    userResourceType.setSchemaExtensions(schemaExtensions);
    // START: Group
    ResourceType groupResourceType = new ResourceType();
    groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
    groupResourceType.setEndpoint("/v2/Groups");
    groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
    Meta groupMeta = new Meta();
    groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
    groupMeta.setResourceType("ResourceType");
    groupResourceType.setMeta(groupMeta);
    // START: FidoDevice
    ResourceType fidoDeviceResourceType = new ResourceType();
    fidoDeviceResourceType.setDescription(Constants.FIDO_DEVICES_CORE_SCHEMA_DESCRIPTION);
    fidoDeviceResourceType.setEndpoint("/v2/FidoDevices");
    fidoDeviceResourceType.setName(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setId(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setSchema(Constants.FIDO_DEVICES_CORE_SCHEMA_ID);
    Meta fidoDeviceMeta = new Meta();
    fidoDeviceMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
    fidoDeviceMeta.setResourceType("ResourceType");
    fidoDeviceResourceType.setMeta(fidoDeviceMeta);
    // ResourceType[] resourceTypes = new ResourceType[]{userResourceType, groupResourceType};
    List<Resource> resourceTypes = new ArrayList<Resource>();
    resourceTypes.add(userResourceType);
    resourceTypes.add(groupResourceType);
    resourceTypes.add(fidoDeviceResourceType);
    listResponse.setResources(resourceTypes);
    listResponse.setTotalResults(resourceTypes.size());
    listResponse.setItemsPerPage(10);
    listResponse.setStartIndex(1);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(listResponse).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with FidoDevice

use of org.gluu.oxtrust.model.scim2.fido.FidoDevice in project oxTrust by GluuFederation.

the class SchemaTypeFidoDeviceSerializer method serialize.

@Override
public void serialize(FidoDevice fidoDevice, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(fidoDevice, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (!rootNodeEntry.getKey().equalsIgnoreCase("meta") && !rootNodeEntry.getKey().equalsIgnoreCase("externalId")) {
                AttributeHolder attributeHolder = new AttributeHolder();
                attributeHolder.setName(rootNodeEntry.getKey());
                if (rootNodeEntry.getValue().isBoolean()) {
                    attributeHolder.setType("boolean");
                } else {
                    attributeHolder.setType("string");
                }
                if (rootNodeEntry.getKey().equalsIgnoreCase("userId")) {
                    attributeHolder.setDescription("User ID that owns the device. Using this in a query filter is not supported.");
                } else if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                    attributeHolder.setDescription("schemas list");
                } else {
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                }
                if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("schemas") || rootNodeEntry.getKey().equalsIgnoreCase("userId")) {
                    attributeHolder.setUniqueness("server");
                    attributeHolder.setReturned("always");
                    attributeHolder.setCaseExact(Boolean.TRUE);
                }
                if (rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                    attributeHolder.setReturned("always");
                }
                if (!rootNodeEntry.getKey().equalsIgnoreCase("displayName") && !rootNodeEntry.getKey().equalsIgnoreCase("description")) {
                    attributeHolder.setMutability("readOnly");
                }
                attributeHolders.add(attributeHolder);
            }
        }
        FidoDeviceCoreSchema fidoDeviceCoreSchema = (FidoDeviceCoreSchema) schemaType;
        fidoDeviceCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = fidoDeviceCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the FidoDevice class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) FidoDeviceCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.fido.FidoDeviceCoreSchema) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) IOException(java.io.IOException)

Example 3 with FidoDevice

use of org.gluu.oxtrust.model.scim2.fido.FidoDevice in project oxTrust by GluuFederation.

the class FidoDeviceWebService method transferAttributesToFidoResource.

private void transferAttributesToFidoResource(GluuCustomFidoDevice fidoDevice, FidoDeviceResource res, String url, String userId) {
    res.setId(fidoDevice.getId());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(DateUtil.generalizedToISOStringDate(fidoDevice.getCreationDate()));
    meta.setLastModified(fidoDevice.getMetaLastModified());
    meta.setLocation(fidoDevice.getMetaLocation());
    if (meta.getLocation() == null)
        meta.setLocation(url + "/" + fidoDevice.getId());
    res.setMeta(meta);
    // Set values in order of appearance in FidoDeviceResource class
    res.setUserId(userId);
    res.setCreationDate(meta.getCreated());
    res.setApplication(fidoDevice.getApplication());
    res.setCounter(fidoDevice.getCounter());
    res.setDeviceData(fidoDevice.getDeviceData());
    res.setDeviceHashCode(fidoDevice.getDeviceHashCode());
    res.setDeviceKeyHandle(fidoDevice.getDeviceKeyHandle());
    res.setDeviceRegistrationConf(fidoDevice.getDeviceRegistrationConf());
    res.setLastAccessTime(DateUtil.generalizedToISOStringDate(fidoDevice.getLastAccessTime()));
    res.setStatus(fidoDevice.getStatus());
    res.setDisplayName(fidoDevice.getDisplayName());
    res.setDescription(fidoDevice.getDescription());
    res.setNickname(fidoDevice.getNickname());
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta)

Example 4 with FidoDevice

use of org.gluu.oxtrust.model.scim2.fido.FidoDevice 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 5 with FidoDevice

use of org.gluu.oxtrust.model.scim2.fido.FidoDevice in project oxTrust by GluuFederation.

the class FidoDeviceCoreLoadingStrategy method createDummyFidoDevice.

private FidoDevice createDummyFidoDevice() {
    FidoDevice fidoDevice = new FidoDevice();
    fidoDevice.setId("");
    fidoDevice.setCreationDate("");
    fidoDevice.setApplication("");
    fidoDevice.setCounter("");
    fidoDevice.setDeviceData("");
    fidoDevice.setDeviceHashCode("");
    fidoDevice.setDeviceKeyHandle("");
    fidoDevice.setDeviceRegistrationConf("");
    fidoDevice.setLastAccessTime("");
    fidoDevice.setStatus("");
    fidoDevice.setDisplayName("");
    fidoDevice.setDescription("");
    return fidoDevice;
}
Also used : FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice)

Aggregations

FidoDevice (org.gluu.oxtrust.model.scim2.fido.FidoDevice)6 URI (java.net.URI)5 DefaultValue (javax.ws.rs.DefaultValue)5 HeaderParam (javax.ws.rs.HeaderParam)5 Produces (javax.ws.rs.Produces)5 GluuCustomFidoDevice (org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)5 GET (javax.ws.rs.GET)4 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)4 Meta (org.gluu.oxtrust.model.scim2.Meta)4 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)4 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 Path (javax.ws.rs.Path)3 Response (javax.ws.rs.core.Response)3 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ResourceType (org.gluu.oxtrust.model.scim2.provider.ResourceType)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1