use of com.wordnik.swagger.annotations.ApiOperation in project oxAuth by GluuFederation.
the class ResourceSetRegistrationWS method getResourceSetList.
/**
* Gets resource set lists.
* ATTENTION: "scope" is parameter added by gluu to have additional filtering.
* There is no such parameter in UMA specification.
*
* @param authorization authorization
* @param scope scope of resource set for additional filtering, can blank string.
* @return resource set ids.
*/
@GET
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "Lists all previously registered resource set identifiers for this user using the GET method.", notes = "Lists all previously registered resource set identifiers for this user using the GET method. The authorization server MUST return the list in the form of a JSON array of {rsid} string values.\n" + "\n" + "The resource server uses this method as a first step in checking whether its understanding of protected resources is in full synchronization with the authorization server's understanding.", response = ResourceSet.class)
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized") })
public List<String> getResourceSetList(@HeaderParam("Authorization") String authorization, @QueryParam("scope") @ApiParam(value = "Scope uri", required = false) String scope) {
try {
log.trace("Getting list of resource set descriptions.");
final AuthorizationGrant authorizationGrant = umaValidationService.assertHasProtectionScope(authorization);
final String clientDn = authorizationGrant.getClientDn();
final List<org.xdi.oxauth.model.uma.persistence.ResourceSet> ldapResourceSets = resourceSetService.getResourceSetsByAssociatedClient(clientDn);
final List<String> result = new ArrayList<String>(ldapResourceSets.size());
for (org.xdi.oxauth.model.uma.persistence.ResourceSet ldapResourceSet : ldapResourceSets) {
// if scope parameter is not null then filter by it, otherwise just add to result
if (StringUtils.isNotBlank(scope)) {
final List<String> scopeUrlsByDns = umaScopeService.getScopeUrlsByDns(ldapResourceSet.getScopes());
if (scopeUrlsByDns != null && scopeUrlsByDns.contains(scope)) {
result.add(ldapResourceSet.getId());
}
} else {
result.add(ldapResourceSet.getId());
}
}
return result;
} catch (Exception ex) {
log.error("Exception happened on getResourceSetList()", ex);
if (ex instanceof WebApplicationException) {
throw (WebApplicationException) ex;
}
}
errorResponseFactory.throwUmaInternalErrorException();
// redundant but required by java
return Lists.newArrayList();
}
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);
}
}
use of com.wordnik.swagger.annotations.ApiOperation 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);
}
}
Aggregations