use of org.xdi.ldap.model.VirtualListViewResponse 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 org.xdi.ldap.model.VirtualListViewResponse in project oxTrust by GluuFederation.
the class GroupWebService method searchGroups.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int 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 = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
} else {
log.info(" Searching groups from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuGroup> gluuGroups = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuGroup> groupList = groupService.getAllGroupsList();
GluuGroupList groupsList = new GluuGroupList();
List<String> schema = new ArrayList<String>();
schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
log.info(" setting schema");
groupsList.setSchemas(schema);
// Set total
groupsList.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuGroups != null && !gluuGroups.isEmpty()) {
for (GluuGroup gluuGroup : gluuGroups) {
ScimGroup group = copyUtils.copy(gluuGroup, null);
log.info(" group to be added displayName : " + group.getDisplayName());
groupsList.getResources().add(group);
log.info(" group added? : " + groupsList.getResources().contains(group));
}
// Set the rest of results info
groupsList.setItemsPerPage(vlvResponse.getItemsPerPage());
groupsList.setStartIndex(vlvResponse.getStartIndex());
}
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Groups");
// Serialize to JSON
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customScimFilterModule = new SimpleModule("CustomScim1GroupFilterModule", new Version(1, 0, 0, ""));
GluuGroupListSerializer serializer = new GluuGroupListSerializer();
serializer.setAttributesArray(attributesArray);
customScimFilterModule.addSerializer(ScimGroup.class, serializer);
mapper.registerModule(customScimFilterModule);
String json = mapper.writeValueAsString(groupsList);
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchGroups", ex);
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.xdi.ldap.model.VirtualListViewResponse in project oxTrust by GluuFederation.
the class UserWebService method searchPersons.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchPersons(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int 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 = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
} else {
log.info(" Searching persons 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);
GluuCustomPersonList personsList = new GluuCustomPersonList();
List<String> schema = new ArrayList<String>();
schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
log.info(" setting schema");
personsList.setSchemas(schema);
// Set total
personsList.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuCustomPersons != null && !gluuCustomPersons.isEmpty()) {
for (GluuCustomPerson gluuPerson : gluuCustomPersons) {
ScimPerson person = copyUtils.copy(gluuPerson, null);
log.info(" person to be added id : " + person.getUserName());
personsList.getResources().add(person);
log.info(" person added? : " + personsList.getResources().contains(person));
}
// Set the rest of results info
personsList.setItemsPerPage(vlvResponse.getItemsPerPage());
personsList.setStartIndex(vlvResponse.getStartIndex());
}
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Users");
// Serialize to JSON
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customScimFilterModule = new SimpleModule("CustomScim1PersonFilterModule", new Version(1, 0, 0, ""));
GluuCustomPersonListSerializer serializer = new GluuCustomPersonListSerializer();
serializer.setAttributesArray(attributesArray);
customScimFilterModule.addSerializer(ScimPerson.class, serializer);
mapper.registerModule(customScimFilterModule);
String json = mapper.writeValueAsString(personsList);
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchPersons", ex);
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.xdi.ldap.model.VirtualListViewResponse 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);
}
}
use of org.xdi.ldap.model.VirtualListViewResponse in project oxTrust by GluuFederation.
the class FidoDeviceWebService method searchDevices.
@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 devices", notes = "Returns a list of devices (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchDevices(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam("userId") final String userId, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int 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 {
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 devices from LDAP ");
String baseDn = fidoDeviceService.getDnForFidoDevice(userId, null);
log.info("##### baseDn = " + baseDn);
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
ListResponse devicesListResponse = new ListResponse();
List<String> schema = new ArrayList<String>();
schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
log.info(" setting schema");
devicesListResponse.setSchemas(schema);
// Set total
devicesListResponse.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuCustomFidoDevices != null && !gluuCustomFidoDevices.isEmpty()) {
for (GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices) {
FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
devicesListResponse.getResources().add(fidoDevice);
}
// Set the rest of results info
devicesListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
devicesListResponse.setStartIndex(vlvResponse.getStartIndex());
}
// Serialize to JSON
String json = serializeToJson(devicesListResponse, attributesArray);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices");
return Response.ok(json).location(location).build();
}
} catch (Exception e) {
log.error("Error in searchDevices", e);
e.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
Aggregations