Search in sources :

Example 21 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class SessionExceptionRestV2Controller method getLatest.

@ApiOperation(value = "Get Last Exception for your session", notes = "")
@ApiResponses({ @ApiResponse(code = 401, message = "Unauthorized user access", response = ResponseEntity.class), @ApiResponse(code = 404, message = "No Exception exists", response = ResponseEntity.class), @ApiResponse(code = 500, message = "Error processing request", response = ResponseEntity.class) })
@RequestMapping(method = { RequestMethod.GET }, value = { "/latest" }, produces = { "application/json" })
public ResponseEntity<Map<String, Exception>> getLatest(HttpServletRequest request) {
    RestProcessResult<Map<String, Exception>> result = new RestProcessResult<>(HttpStatus.OK);
    // Get latest Session Exception
    HttpSession session = request.getSession(false);
    if (session == null)
        throw new ServerErrorException(new TranslatableMessage("rest.error.noSession"));
    Map<String, Exception> exceptionMap = new HashMap<String, Exception>();
    for (String key : exceptionKeys) {
        exceptionMap.put(key, (Exception) session.getAttribute(key));
    }
    return result.createResponseEntity(exceptionMap);
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) ServerErrorException(com.infiniteautomation.mango.rest.v2.exception.ServerErrorException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) HashMap(java.util.HashMap) Map(java.util.Map) ServerErrorException(com.infiniteautomation.mango.rest.v2.exception.ServerErrorException) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class SystemActionRestV2Controller method cancel.

@ApiOperation(value = "Cancel Action", notes = "No Guarantees that the cancel will work, this is task dependent.")
@ApiResponses({ @ApiResponse(code = 401, message = "Unauthorized user access", response = ResponseEntity.class), @ApiResponse(code = 404, message = "No resource exists with given id", response = ResponseEntity.class), @ApiResponse(code = 500, message = "Error processing request", response = ResponseEntity.class) })
@RequestMapping(method = { RequestMethod.PUT }, value = { "/cancel/{resourceId}" })
public ResponseEntity<SystemActionTemporaryResource> cancel(HttpServletRequest request, @ApiParam(value = "Resource id", required = true, allowMultiple = false) @PathVariable String resourceId, @AuthenticationPrincipal User user) {
    SystemActionTemporaryResource resource = resources.get(resourceId);
    resource.cancel();
    return new ResponseEntity<>(resource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SystemActionTemporaryResource(com.infiniteautomation.mango.rest.v2.util.SystemActionTemporaryResource) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class SystemActionRestV2Controller method performAction.

@ApiOperation(value = "Perform an Action", notes = "Kicks off action and returns temporary URL for status")
@ApiResponses({ @ApiResponse(code = 500, message = "Internal error", response = ResponseEntity.class), @ApiResponse(code = 404, message = "Not Found", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.PUT, value = "/trigger/{action}")
public ResponseEntity<SystemActionTemporaryResource> performAction(@ApiParam(value = "Valid System Action", required = true, allowMultiple = false) @PathVariable String action, @ApiParam(value = "Input for task", required = false, allowMultiple = false) @RequestBody(required = false) JsonNode input, @AuthenticationPrincipal User user, UriComponentsBuilder builder) {
    // Kick off action
    SystemActionDefinition def = ModuleRegistry.getSystemActionDefinition(action);
    if (def == null)
        throw new NotFoundRestException();
    String resourceId = resources.generateResourceId();
    SystemActionTemporaryResource resource = new SystemActionTemporaryResource(resourceId, def.getTask(user, input), resources, new Date(System.currentTimeMillis() + 600000));
    // Resource can live for up to 10 minutes (TODO Configurable?)
    resources.put(resourceId, resource);
    URI location = builder.path("/v2/actions/status/{resourceId}").buildAndExpand(resourceId).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) ResponseEntity(org.springframework.http.ResponseEntity) SystemActionTemporaryResource(com.infiniteautomation.mango.rest.v2.util.SystemActionTemporaryResource) URI(java.net.URI) Date(java.util.Date) SystemActionDefinition(com.serotonin.m2m2.module.SystemActionDefinition) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project oxAuth by GluuFederation.

the class UmaConfigurationWS method getConfiguration.

@GET
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "Provides configuration data as json document. It contains options and endpoints supported by the authorization server.", response = UmaConfiguration.class)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Failed to build Uma configuration json object.") })
public Response getConfiguration() {
    try {
        final String baseEndpointUri = appConfiguration.getBaseEndpoint();
        final UmaConfiguration c = new UmaConfiguration();
        c.setVersion("1.0");
        c.setIssuer(appConfiguration.getIssuer());
        c.setPatProfilesSupported(new String[] { TokenType.BEARER.getName() });
        c.setAatProfilesSupported(new String[] { TokenType.BEARER.getName() });
        c.setRptProfilesSupported(new String[] { RptProfiles.BEARER.getIdentifyingUri() });
        c.setPatGrantTypesSupported(new String[] { GrantType.AUTHORIZATION_CODE.getValue(), GrantType.IMPLICIT.getValue(), GrantType.CLIENT_CREDENTIALS.getValue() });
        c.setAatGrantTypesSupported(new String[] { GrantType.AUTHORIZATION_CODE.getValue(), GrantType.IMPLICIT.getValue(), GrantType.CLIENT_CREDENTIALS.getValue() });
        c.setClaimTokenProfilesSupported(new String[] { "openid" });
        c.setUmaProfilesSupported(new String[0]);
        c.setDynamicClientEndpoint(baseEndpointUri + "/oxauth/register");
        c.setTokenEndpoint(baseEndpointUri + "/oxauth/token");
        c.setAuthorizationEndpoint(baseEndpointUri + "/requester/perm");
        c.setRequestingPartyClaimsEndpoint("");
        c.setIntrospectionEndpoint(baseEndpointUri + "/rpt/status");
        c.setResourceSetRegistrationEndpoint(baseEndpointUri + "/host/rsrc/resource_set");
        c.setPermissionRegistrationEndpoint(baseEndpointUri + "/host/rsrc_pr");
        c.setRptEndpoint(baseEndpointUri + "/requester/rpt");
        c.setGatEndpoint(baseEndpointUri + "/requester/gat");
        c.setScopeEndpoint(baseEndpointUri + UMA_SCOPES_SUFFIX);
        c.setRptAsJwt(appConfiguration.getUmaRptAsJwt());
        // convert manually to avoid possible conflicts between resteasy providers, e.g. jettison, jackson
        final String entity = ServerUtil.asPrettyJson(c);
        log.trace("Uma 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(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.SERVER_ERROR)).build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UmaConfiguration(org.xdi.oxauth.model.uma.UmaConfiguration) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 25 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project oxAuth by GluuFederation.

the class U2fConfigurationWS method getConfiguration.

@GET
@Produces({ "application/json" })
@ApiOperation(value = "Provides configuration data as json document. It contains options and endpoints supported by the FIDO U2F server.", response = U2fConfiguration.class)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Failed to build FIDO U2F configuration json object.") })
public Response getConfiguration() {
    try {
        final String baseEndpointUri = appConfiguration.getBaseEndpoint();
        final U2fConfiguration conf = new U2fConfiguration();
        conf.setVersion("2.0");
        conf.setIssuer(appConfiguration.getIssuer());
        conf.setRegistrationEndpoint(baseEndpointUri + "/fido/u2f/registration");
        conf.setAuthenticationEndpoint(baseEndpointUri + "/fido/u2f/authentication");
        // convert manually to avoid possible conflicts between resteasy
        // providers, e.g. jettison, jackson
        final String entity = ServerUtil.asPrettyJson(conf);
        log.trace("FIDO U2F 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(errorResponseFactory.getUmaJsonErrorResponse(U2fErrorResponseType.SERVER_ERROR)).build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) U2fConfiguration(org.xdi.oxauth.model.fido.u2f.U2fConfiguration) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Aggregations

ApiResponses (com.wordnik.swagger.annotations.ApiResponses)47 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)44 Path (javax.ws.rs.Path)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 Produces (javax.ws.rs.Produces)17 POST (javax.ws.rs.POST)14 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)13 IOException (java.io.IOException)10 User (com.serotonin.m2m2.vo.User)9 Consumes (javax.ws.rs.Consumes)9 GET (javax.ws.rs.GET)9 ArrayList (java.util.ArrayList)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)6 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)5 ResponseEntity (org.springframework.http.ResponseEntity)5 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)4 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)4