Search in sources :

Example 6 with InsufficientScopeException

use of org.springframework.security.oauth2.common.exceptions.InsufficientScopeException in project spring-security-oauth by spring-projects.

the class DefaultWebResponseExceptionTranslator method handleOAuth2Exception.

private ResponseEntity<OAuth2Exception> handleOAuth2Exception(OAuth2Exception e) throws IOException {
    int status = e.getHttpErrorCode();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Cache-Control", "no-store");
    headers.set("Pragma", "no-cache");
    if (status == HttpStatus.UNAUTHORIZED.value() || (e instanceof InsufficientScopeException)) {
        headers.set("WWW-Authenticate", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, e.getSummary()));
    }
    ResponseEntity<OAuth2Exception> response = new ResponseEntity<OAuth2Exception>(e, headers, HttpStatus.valueOf(status));
    return response;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) InsufficientScopeException(org.springframework.security.oauth2.common.exceptions.InsufficientScopeException) ResponseEntity(org.springframework.http.ResponseEntity) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception)

Aggregations

InsufficientScopeException (org.springframework.security.oauth2.common.exceptions.InsufficientScopeException)6 Test (org.junit.Test)3 OAuth2ContextConfiguration (org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration)3 HttpHeaders (org.springframework.http.HttpHeaders)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 ConfigAttribute (org.springframework.security.access.ConfigAttribute)2 AuthorizationCodeResourceDetails (org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails)2 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)2 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)2 HttpEntity (org.springframework.http.HttpEntity)1 ResponseEntity (org.springframework.http.ResponseEntity)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)1 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)1