use of com.wordnik.swagger.annotations.ApiOperation in project oxTrust by GluuFederation.
the class ScimConfigurationWS method getConfiguration.
@GET
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "Provides configuration data as json document. It contains options and endpoints supported by the SCIM server.", response = UmaConfiguration.class)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Failed to build SCIM configuration json object.") })
public Response getConfiguration() {
try {
final String baseEndpointUri = appConfiguration.getBaseEndpoint();
final List<ScimConfiguration> cl = new ArrayList<ScimConfiguration>();
// cl.setScimConfigurationList(new ArrayList<ScimConfiguration>());
// SCIM 1.0
final ScimConfiguration c1 = new ScimConfiguration();
c1.setVersion("1.0");
c1.setAuthorizationSupported(new String[] { "uma" });
c1.setUserEndpoint(baseEndpointUri + "/scim/v1/Users");
c1.setUserSearchEndpoint(baseEndpointUri + "/scim/v1/Users/Search");
c1.setGroupEndpoint(baseEndpointUri + "/scim/v1/Groups");
c1.setBulkEndpoint(baseEndpointUri + "/scim/v1/Bulk");
cl.add(c1);
// SCIM 2.0
final ScimConfiguration c2 = new ScimConfiguration();
c2.setVersion("2.0");
c2.setAuthorizationSupported(new String[] { "uma" });
c2.setUserEndpoint(baseEndpointUri + "/scim/v2/Users");
c2.setUserSearchEndpoint(baseEndpointUri + "/scim/v2/Users/Search");
c2.setGroupEndpoint(baseEndpointUri + "/scim/v2/Groups");
c2.setBulkEndpoint(baseEndpointUri + "/scim/v2/Bulk");
c2.setServiceProviderEndpoint(baseEndpointUri + "/scim/v2/ServiceProviderConfig");
c2.setResourceTypesEndpoint(baseEndpointUri + "/scim/v2/ResourceTypes");
cl.add(c2);
// Convert manually to avoid possible conflicts between resteasy providers, e.g. jettison, jackson
final String entity = jsonService.objectToPerttyJson(cl);
log.trace("SCIM configuration: {}", entity);
return Response.ok(entity).build();
} catch (Throwable ex) {
log.error(ex.getMessage(), ex);
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to generate SCIM configuration").build());
}
}
use of com.wordnik.swagger.annotations.ApiOperation 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 com.wordnik.swagger.annotations.ApiOperation 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 com.wordnik.swagger.annotations.ApiOperation 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);
}
}
use of com.wordnik.swagger.annotations.ApiOperation 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);
}
}
Aggregations