Example usage for org.springframework.security.oauth2.common.exceptions OAuth2Exception getSummary

List of usage examples for org.springframework.security.oauth2.common.exceptions OAuth2Exception getSummary

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common.exceptions OAuth2Exception getSummary.

Prototype

public String getSummary() 

Source Link

Usage

From source file:org.joyrest.oauth2.handler.OAuthExceptionConfiguration.java

private void process(Request<?> req, Response<OAuth2Exception> resp, OAuth2Exception ex) {
    resp.entity(ex);/*from   w w w . java2  s.co  m*/

    int status = ex.getHttpErrorCode();
    resp.status(HttpStatus.of(status));

    resp.header(CACHE_CONTROL, "no-store");
    resp.header(PRAGMA, "no-cache");
    if (status == HttpStatus.UNAUTHORIZED.code() || (ex instanceof InsufficientScopeException)) {
        resp.header(WWW_AUTHENTICATE, String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, ex.getSummary()));
    }
}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java

@ExceptionHandler(OAuth2Exception.class)
public ModelAndView handleOAuth2Exception(OAuth2Exception e, ServletWebRequest webRequest) throws Exception {
    logger.info(e.getSummary());
    int errorCode = e.getHttpErrorCode();
    if (errorCode != 401 && "Bad credentials".equals(e.getMessage())) {
        //https://github.com/spring-projects/spring-security-oauth/issues/191
        errorCode = 401;// w w w .j  av a2s .co m
    }
    webRequest.getResponse().setStatus(errorCode);
    return new ModelAndView("forward:/home", Collections.singletonMap("error", e.getSummary()));
}

From source file:org.cloudfoundry.identity.uaa.oauth.UaaAuthorizationEndpoint.java

@ExceptionHandler(OAuth2Exception.class)
public ModelAndView handleOAuth2Exception(OAuth2Exception e, ServletWebRequest webRequest) throws Exception {
    logger.info("Handling OAuth2 error: " + e.getSummary());
    return handleException(e, webRequest);
}

From source file:org.orcid.core.oauth.service.OrcidAuthorizationEndpoint.java

@Override
@ExceptionHandler(OAuth2Exception.class)
public ModelAndView handleOAuth2Exception(OAuth2Exception e, ServletWebRequest webRequest) throws Exception {
    logger.info("Handling OAuth2 error: " + e.getSummary());
    if (e instanceof RedirectMismatchException) {
        return new ModelAndView(redirectUriError);
    } else if (e instanceof ClientAuthenticationException) {
        return new ModelAndView(oauthError);
    }//from   ww w  .  j  a va 2s .  c o m

    return super.handleOAuth2Exception(e, webRequest);
}

From source file:org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator.java

private ResponseEntity<OAuth2Exception> handleOAuth2Exception(OAuth2Exception e) throws IOException {

    if (logger.isDebugEnabled()) {
        logger.debug("OAuth error.", e);
    }/*from  ww w  . jav  a  2  s .  c  o m*/

    int status = e.getHttpErrorCode();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Cache-Control", "no-store");
    if (status == HttpStatus.UNAUTHORIZED.value()) {
        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;

}