Search in sources :

Example 11 with Resource

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

the class UserExtensionsTest method testCreatePersonFromJsonString.

@Test
@Parameters({ "test.scim2.userext.create_json" })
public void testCreatePersonFromJsonString(final String createJson) throws Exception {
    System.out.println(" testCreatePersonFromJsonString() ");
    // Create custom attributes
    // String, not
    GluuAttribute scimCustomFirst = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomFirst") == null) {
        scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
    }
    // Date, multi-valued
    GluuAttribute scimCustomSecond = null;
    if (attributeService.getAttributeByName("scimCustomSecond") == null) {
        scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
    }
    // Numeric, not
    GluuAttribute scimCustomThird = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomThird") == null) {
        scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
    }
    // String CREATEJSON =
    // "{\"schemas\":[\"urn:ietf:params:scim:schemas:core:2.0:User\",\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\"],\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\":
    // {\"scimCustomFirst\":\"[1000,2000]\",\"scimCustomSecond\":[\"2016-02-23T15:35:22Z\"],\"scimCustomThird\":3000},\"externalId\":\"scimclient\",\"userName\":\"userjson.add.username\",\"name\":{\"givenName\":\"json\",\"familyName\":\"json\",\"middleName\":\"N/A\",\"honorificPrefix\":\"N/A\",\"honorificSuffix\":\"N/A\"},\"displayName\":\"json
    // json\",\"nickName\":\"json\",\"profileUrl\":\"http://www.gluu.org/\",\"emails\":[{\"value\":\"json@gluu.org\",\"type\":\"work\",\"primary\":\"true\"},{\"value\":\"json2@gluu.org\",\"type\":\"home\",\"primary\":\"false\"}],\"addresses\":[{\"type\":\"work\",\"streetAddress\":\"621
    // East 6th Street Suite
    // 200\",\"locality\":\"Austin\",\"region\":\"TX\",\"postalCode\":\"78701\",\"country\":\"US\",\"formatted\":\"621
    // East 6th Street Suite 200 Austin , TX 78701
    // US\",\"primary\":\"true\"}],\"phoneNumbers\":[{\"value\":\"646-345-2346\",\"type\":\"work\"}],\"ims\":[{\"value\":\"nynytest_user\",\"type\":\"Skype\"}],\"userType\":\"CEO\",\"title\":\"CEO\",\"preferredLanguage\":\"en-us\",\"locale\":\"en_US\",\"active\":\"true\",\"password\":\"secret\",\"roles\":[{\"value\":\"Owner\"}],\"entitlements\":[{\"value\":\"full
    // access\"}],\"x509Certificates\":[{\"value\":\"MIIDQzCCAqygAwIBAgICEAAwDQYJKoZIhvcNAQEFBQAwTjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFDASBgNVBAoMC2V4YW1wbGUuY29tMRQwEgYDVQQDDAtleGFtcGxlLmNvbTAeFw0xMTEwMjIwNjI0MzFaFw0xMjEwMDQwNjI0MzFa
    // MH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRQwEgYDVQQKDAtleGFtcGxlLmNvbTEhMB8GA1UEAwwYTXMuIEJhcmJhcmEgSiBKZW5zZW4gSUlJMSIwIAYJKoZIhvcNAQkBFhNiamVuc2VuQGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7Kr+Dcds/JQ5GwejJFcBIP682X3xpjis56AK02bc1FLgzdLI8auoR+cC9/Vrh5t66HkQIOdA4unHh0AaZ4xL5PhVbXIPMB5vAPKpzz5iPSi8xO8SL7I7SDhcBVJhqVqr3HgllEG6UClDdHO7nkLuwXq8HcISKkbT5WFTVfFZzidPl8HZ7DhXkZIRtJwBweq4bvm3hM1Os7UQH05ZS6cVDgweKNwdLLrT51ikSQG3DYrl+ft781UQRIqxgwqCfXEuDiinPh0kkvIi5jivVu1Z9QiwlYEdRbLJ4zJQBmDrSGTMYn4lRc2HgHO4DqB/bnMVorHB0CC6AV1QoFK4GPe1LwIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU8pD0U0vsZIsaA16lL8En8bx0F/gwHwYDVR0jBBgwFoAUdGeKitcaF7gnzsNwDx708kqaVt0wDQYJKoZIhvcNAQEFBQADgYEAA81SsFnOdYJtNg5Tcq+/ByEDrBgnusx0jloUhByPMEVkoMZ3J7j1ZgI8rAbOkNngX8+pKfTiDz1RC4+dx8oU6Za+4NJXUjlL5CvV6BEYb1+QAEJwitTVvxB/A67g42/vzgAtoRUeDov1+GFiBZ+GNF/cAYKcMtGcrs2i97ZkJMo=\"}],\"meta\":{\"created\":\"2010-01-23T04:56:22Z\",\"lastModified\":\"2011-05-13T04:42:34Z\",\"version\":\"aversion\",\"location\":\"http://localhost:8080/identity/seam/resource/restv1/Users/8c4b6c26-efaf-4840-bddf-c0146a8eb2a9\"}}";
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
    SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, ""));
    simpleModule.addDeserializer(User.class, new UserDeserializer());
    mapper.registerModule(simpleModule);
    User user = mapper.readValue(createJson, User.class);
    String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
    user.setUserName(testUserName);
    Extension extension = user.getExtension(Constants.USER_EXT_SCHEMA_ID);
    assertNotNull(extension, "(Deserialization) Custom extension not deserialized.");
    Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
    assertNotNull(customFirstField, "(Deserialization) \"scimCustomFirst\" field not deserialized.");
    assertEquals(customFirstField.getValue(), "[1000,2000]");
    System.out.println("##### (Deserialization) customFirstField.getValue() = " + customFirstField.getValue());
    Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
    assertNotNull(customSecondField, "(Deserialization) \"scimCustomSecond\" field not deserialized.");
    List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
    assertEquals(dateList.size(), 1);
    System.out.println("##### (Deserialization) dateList.get(0) = " + dateList.get(0));
    Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
    assertNotNull(customThirdField, "(Deserialization) \"scimCustomThird\" field not deserialized.");
    assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
    System.out.println("##### (Deserialization) customThirdField.getValue() = " + customThirdField.getValue());
    // Create Person
    GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
    assertNotNull(gluuPerson, "gluuPerson is null!");
    System.out.println(">>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
    String inum = personService.generateInumForNewPerson();
    String dn = personService.getDnForPerson(inum);
    String iname = personService.generateInameForNewPerson(user.getUserName());
    gluuPerson.setDn(dn);
    gluuPerson.setInum(inum);
    gluuPerson.setIname(iname);
    gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
    personService.addPerson(gluuPerson);
    // Retrieve Person
    GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
    assertNotNull(retrievedPerson, "Failed to find person.");
    User newPerson = copyUtils2.copy(retrievedPerson, null);
    extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
    assertNotNull(extension, "(Persistence) Custom extension not persisted.");
    customFirstField = extension.getFields().get("scimCustomFirst");
    assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
    assertEquals(customFirstField.getValue(), "[1000,2000]");
    System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
    customSecondField = extension.getFields().get("scimCustomSecond");
    assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
    dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
    assertEquals(dateList.size(), 1);
    System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
    customThirdField = extension.getFields().get("scimCustomThird");
    assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
    assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
    System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
    // Remove Person
    memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
Also used : UserDeserializer(org.gluu.oxtrust.service.scim2.jackson.custom.UserDeserializer) User(org.gluu.oxtrust.model.scim2.User) Date(java.util.Date) BigDecimal(java.math.BigDecimal) GluuAttribute(org.xdi.model.GluuAttribute) Extension(org.gluu.oxtrust.model.scim2.Extension) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.gluu.oxtrust.action.test.BaseTest)

Example 12 with Resource

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

the class UserWebService method getUserById.

@Path("{id}")
@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Find user by id", notes = "Returns a user by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = User.class)
public Response getUserById(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        String filterString = "id eq \"" + id + "\"";
        VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
        List<GluuCustomPerson> personList = search(personService.getDnForPerson(null), GluuCustomPerson.class, filterString, 1, 1, "id", SortOrder.ASCENDING.getValue(), vlvResponse, attributesArray);
        if (personList == null || personList.isEmpty() || vlvResponse.getTotalResults() == 0) {
            // sets HTTP status code 404 Not Found
            return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
        } else {
            log.info(" Resource " + id + " found ");
        }
        GluuCustomPerson gluuPerson = personList.get(0);
        User user = copyUtils2.copy(gluuPerson, null);
        // Serialize to JSON
        String json = serializeToJson(user, attributesArray);
        URI location = new URI(user.getMeta().getLocation());
        return Response.ok(json).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Error in getUserById", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (Exception ex) {
        log.error("Error in getUserById", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 13 with Resource

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

the class FidoDeviceWebService method searchDevicesPost.

@Path("/.search")
@POST
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search devices POST /.search", notes = "Returns a list of devices (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchDevicesPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam("userId") final String userId, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
    try {
        log.info("IN FidoDeviceWebService.searchDevicesPost()...");
        // Authorization check is done in searchDevices()
        Response response = searchDevices(authorization, token, userId, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices/.search");
        log.info("LEAVING FidoDeviceWebService.searchDevicesPost()...");
        return Response.fromResponse(response).location(location).build();
    } catch (EntryPersistenceException epe) {
        log.error("Error in searchDevicesPost", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
    } catch (Exception e) {
        log.error("Error in searchDevicesPost", e);
        e.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 14 with Resource

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

the class FidoDeviceWebService method updateDevice.

@Path("{id}")
@PUT
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Update device", notes = "Update device (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = FidoDevice.class)
public Response updateDevice(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "FidoDevice", required = true) FidoDevice fidoDevice, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (!id.equalsIgnoreCase(fidoDevice.getId())) {
            String detail = "Path param id does not match with device id";
            return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, detail);
        } else {
            FidoDevice updatedFidoDevice = scim2FidoDeviceService.updateFidoDevice(id, fidoDevice);
            // Serialize to JSON
            String json = serializeToJson(updatedFidoDevice, attributesArray);
            URI location = new URI(updatedFidoDevice.getMeta().getLocation());
            return Response.ok(json).location(location).build();
        }
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update device", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (DuplicateEntryException dee) {
        log.error("DuplicateEntryException", dee);
        dee.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, dee.getMessage());
    } catch (Exception e) {
        log.error("Failed to update device", e);
        e.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 15 with Resource

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

the class FidoDeviceWebService method getDeviceById.

@Path("{id}")
@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Find device by id", notes = "Returns a device by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = FidoDevice.class)
public Response getDeviceById(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @QueryParam("userId") final String userId, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        String baseDn = fidoDeviceService.getDnForFidoDevice(userId, id);
        log.info("##### baseDn = " + baseDn);
        String filterString = "id eq \"" + id + "\"";
        VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
        List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, 1, 1, "id", SortOrder.ASCENDING.getValue(), vlvResponse, attributesArray);
        if (gluuCustomFidoDevices == null || gluuCustomFidoDevices.isEmpty() || vlvResponse.getTotalResults() == 0) {
            // sets HTTP status code 404 Not Found
            return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
        } else {
            log.info(" Resource " + id + " found ");
        }
        GluuCustomFidoDevice gluuCustomFidoDevice = gluuCustomFidoDevices.get(0);
        FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
        // Serialize to JSON
        String json = serializeToJson(fidoDevice, attributesArray);
        URI uriLocation = new URI(fidoDevice.getMeta().getLocation());
        return Response.ok(json).location(uriLocation).build();
    } catch (EntryPersistenceException epe) {
        log.error("Error in getDeviceById", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (Exception e) {
        log.error("Error in getDeviceById", e);
        e.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Aggregations

EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)18 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)17 DefaultValue (javax.ws.rs.DefaultValue)15 HeaderParam (javax.ws.rs.HeaderParam)15 Produces (javax.ws.rs.Produces)15 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)15 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)13 Path (javax.ws.rs.Path)13 Response (javax.ws.rs.core.Response)13 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)13 URI (java.net.URI)12 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)7 User (org.gluu.oxtrust.model.scim2.User)6 GET (javax.ws.rs.GET)5 Date (java.util.Date)4 Consumes (javax.ws.rs.Consumes)4 PUT (javax.ws.rs.PUT)4 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 Group (org.gluu.oxtrust.model.scim2.Group)4