Example usage for org.springframework.boot.actuate.autoconfigure.cloudfoundry SecurityResponse SecurityResponse

List of usage examples for org.springframework.boot.actuate.autoconfigure.cloudfoundry SecurityResponse SecurityResponse

Introduction

In this page you can find the example usage for org.springframework.boot.actuate.autoconfigure.cloudfoundry SecurityResponse SecurityResponse.

Prototype

public SecurityResponse(HttpStatus status, String message) 

Source Link

Usage

From source file:org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundrySecurityInterceptor.java

SecurityResponse preHandle(HttpServletRequest request, String endpointId) {
    if (CorsUtils.isPreFlightRequest(request)) {
        return SecurityResponse.success();
    }//from   w  w w  .  java2 s. c om
    try {
        if (!StringUtils.hasText(this.applicationId)) {
            throw new CloudFoundryAuthorizationException(
                    CloudFoundryAuthorizationException.Reason.SERVICE_UNAVAILABLE,
                    "Application id is not available");
        }
        if (this.cloudFoundrySecurityService == null) {
            throw new CloudFoundryAuthorizationException(
                    CloudFoundryAuthorizationException.Reason.SERVICE_UNAVAILABLE,
                    "Cloud controller URL is not available");
        }
        if (HttpMethod.OPTIONS.matches(request.getMethod())) {
            return SUCCESS;
        }
        check(request, endpointId);
    } catch (Exception ex) {
        logger.error(ex);
        if (ex instanceof CloudFoundryAuthorizationException) {
            CloudFoundryAuthorizationException cfException = (CloudFoundryAuthorizationException) ex;
            return new SecurityResponse(cfException.getStatusCode(),
                    "{\"security_error\":\"" + cfException.getMessage() + "\"}");
        }
        return new SecurityResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
    return SecurityResponse.success();
}

From source file:org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.CloudFoundrySecurityInterceptor.java

private Mono<SecurityResponse> getErrorResponse(Throwable throwable) {
    if (throwable instanceof CloudFoundryAuthorizationException) {
        CloudFoundryAuthorizationException cfException = (CloudFoundryAuthorizationException) throwable;
        return Mono.just(new SecurityResponse(cfException.getStatusCode(),
                "{\"security_error\":\"" + cfException.getMessage() + "\"}"));
    }/*from  www.  j ava  2s. c om*/
    return Mono.just(new SecurityResponse(HttpStatus.INTERNAL_SERVER_ERROR, throwable.getMessage()));
}

From source file:org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet.CloudFoundrySecurityInterceptor.java

SecurityResponse preHandle(HttpServletRequest request, String endpointId) {
    if (CorsUtils.isPreFlightRequest(request)) {
        return SecurityResponse.success();
    }// w ww. ja v  a 2  s  . com
    try {
        if (!StringUtils.hasText(this.applicationId)) {
            throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE,
                    "Application id is not available");
        }
        if (this.cloudFoundrySecurityService == null) {
            throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE,
                    "Cloud controller URL is not available");
        }
        if (HttpMethod.OPTIONS.matches(request.getMethod())) {
            return SUCCESS;
        }
        check(request, endpointId);
    } catch (Exception ex) {
        logger.error(ex);
        if (ex instanceof CloudFoundryAuthorizationException) {
            CloudFoundryAuthorizationException cfException = (CloudFoundryAuthorizationException) ex;
            return new SecurityResponse(cfException.getStatusCode(),
                    "{\"security_error\":\"" + cfException.getMessage() + "\"}");
        }
        return new SecurityResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
    return SecurityResponse.success();
}