use of io.jans.scim.model.scim2.ListResponse 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();
}
use of io.jans.scim.model.scim2.ListResponse in project oxTrust by GluuFederation.
the class SchemaWebService method listSchemas.
/**
* Retrieves the complete schema.
*
* @param authorization
* @return
* @throws Exception
*/
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listSchemas(@HeaderParam("Authorization") String authorization) throws Exception {
log.info(" listSchemas() ");
ListResponse listResponse = new ListResponse();
List<String> schemas = new ArrayList<String>();
schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
listResponse.setSchemas(schemas);
List<SchemaType> schemaTypes = SchemaTypeMapping.getSchemaInstances();
List<Resource> resources = new ArrayList<Resource>();
SchemaTypeLoadingFactory factory = new SchemaTypeLoadingFactory();
for (SchemaType schemaType : schemaTypes) {
factory.load(appConfiguration, schemaType);
resources.add(schemaType);
}
listResponse.setResources(resources);
listResponse.setTotalResults(schemaTypes.size());
listResponse.setItemsPerPage(10);
listResponse.setStartIndex(1);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas");
// Serialize to JSON
String json = serialize(listResponse);
return Response.ok(json).location(location).build();
}
use of io.jans.scim.model.scim2.ListResponse in project oxTrust by GluuFederation.
the class UserWebService method searchUsers.
@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 = "Search users", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchUsers(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) Integer count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @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 {
count = (count == null) ? getMaxCount() : count;
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
} else {
log.info(" Searching users from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuCustomPerson> gluuCustomPersons = search(personService.getDnForPerson(null), GluuCustomPerson.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuCustomPerson> personList = personService.findAllPersons(null);
ListResponse usersListResponse = new ListResponse();
List<String> schema = new ArrayList<String>();
schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
log.info(" setting schema");
usersListResponse.setSchemas(schema);
// Set total
usersListResponse.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuCustomPersons != null && !gluuCustomPersons.isEmpty()) {
for (GluuCustomPerson gluuPerson : gluuCustomPersons) {
User user = copyUtils2.copy(gluuPerson, null);
log.info(" user to be added id : " + user.getUserName());
usersListResponse.getResources().add(user);
log.info(" user added? : " + usersListResponse.getResources().contains(user));
}
// Set the rest of results info
usersListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
usersListResponse.setStartIndex(vlvResponse.getStartIndex());
}
// Serialize to JSON
String json = serializeToJson(usersListResponse, attributesArray);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Users");
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchUsers", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of io.jans.scim.model.scim2.ListResponse in project oxTrust by GluuFederation.
the class BaseScimWebService method getListResponseSerialized.
String getListResponseSerialized(int total, int startIndex, List<BaseScimResource> resources, String attrsList, String excludedAttrsList, boolean ignoreResults) throws IOException {
ListResponse listResponse = new ListResponse(startIndex, resources.size(), total);
listResponse.setResources(resources);
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
module.addSerializer(ListResponse.class, new ListResponseJsonSerializer(resourceSerializer, attrsList, excludedAttrsList, ignoreResults));
mapper.registerModule(module);
return mapper.writeValueAsString(listResponse);
}
use of io.jans.scim.model.scim2.ListResponse in project oxTrust by GluuFederation.
the class ResourceTypeWS method serve.
@GET
@Produces(MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT)
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@RejectFilterParam
public Response serve() {
try {
ListResponse listResponse = new ListResponse(1, 3, 3);
listResponse.addResource(getUserResourceType());
listResponse.addResource(getGroupResourceType());
listResponse.addResource(getFidoDeviceResourceType());
String json = resourceSerializer.getListResponseMapper().writeValueAsString(listResponse);
return Response.ok(json).location(new URI(endpointUrl)).build();
} catch (Exception e) {
log.error(e.getMessage(), e);
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
}
Aggregations