use of javax.ws.rs.HeaderParam 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 javax.ws.rs.HeaderParam 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 javax.ws.rs.HeaderParam 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);
}
}
use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.
the class UserWebService method createUser.
@POST
@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 = "Create user", notes = "Create user (https://tools.ietf.org/html/rfc7644#section-3.3)", response = User.class)
public Response createUser(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "User", required = true) User user, @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 {
User createdUser = scim2UserService.createUser(user);
// Serialize to JSON
String json = serializeToJson(createdUser, attributesArray);
URI location = new URI(createdUser.getMeta().getLocation());
// Return HTTP response with status code 201 Created
return Response.created(location).entity(json).build();
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
} catch (PersonRequiredFieldsException ex) {
log.error("PersonRequiredFieldsException: ", ex);
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, ex.getMessage());
} catch (Exception ex) {
log.error("Failed to create user", ex.getMessage());
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of javax.ws.rs.HeaderParam 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);
}
}
Aggregations