Example usage for org.springframework.security.oauth2.common.exceptions BadClientCredentialsException BadClientCredentialsException

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

Introduction

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

Prototype

public BadClientCredentialsException() 

Source Link

Usage

From source file:com.nagarro.core.resolver.OAuth2ExceptionHandlerExceptionResolver.java

@Override
protected ModelAndView doResolveException(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final Exception ex) {
    if (!OAuth2Exception.class.isAssignableFrom(ex.getClass())) {
        return null;
    }/*from w  w w  . ja v a  2s .c  o m*/

    //TokenEndpoint exception handlers logic
    ResponseEntity<OAuth2Exception> responseEntity = null;
    final Exception exceptionToTranslate;
    if (ClientRegistrationException.class.isAssignableFrom(ex.getClass())) {
        exceptionToTranslate = new BadClientCredentialsException();
    } else {
        exceptionToTranslate = ex;
    }

    //Exception translation by WebResponseExceptionTranslator
    try {
        responseEntity = webResponseExceptionTranslator.translate(exceptionToTranslate);
    } catch (final Exception e) {
        logger.error("Translating of [" + exceptionToTranslate.getClass().getName() + "] resulted in Exception",
                e);
        return null;
    }

    final ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(request);
    final ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response);

    //get translated headers
    outputMessage.getHeaders().putAll(responseEntity.getHeaders());

    //set status
    outputMessage.setStatusCode(responseEntity.getStatusCode());

    final ErrorListWsDTO errorListDto = new ErrorListWsDTO();
    errorListDto.setErrors(getWebserviceErrorFactory().createErrorList(ex));

    try {
        return writeWithMessageConverters(errorListDto, inputMessage, outputMessage);
    } catch (final Exception handlerException) {
        logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException);
    }
    return null;
}

From source file:org.mitre.openid.connect.assertion.JWTBearerClientAssertionTokenEndpointFilter.java

@Override
public void afterPropertiesSet() {
    super.afterPropertiesSet();
    setAuthenticationFailureHandler(new AuthenticationFailureHandler() {
        @Override//  w  w  w . java2s . c o  m
        public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
                AuthenticationException exception) throws IOException, ServletException {
            if (exception instanceof BadCredentialsException) {
                exception = new BadCredentialsException(exception.getMessage(),
                        new BadClientCredentialsException());
            }
            authenticationEntryPoint.commence(request, response, exception);
        }
    });
    setAuthenticationSuccessHandler(new AuthenticationSuccessHandler() {
        @Override
        public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
                Authentication authentication) throws IOException, ServletException {
            // no-op - just allow filter chain to continue to token endpoint
        }
    });
}

From source file:org.osiam.security.helper.FBClientCredentialsTokenEndpointFilter.java

@Override
/**/*w  ww.  java  2 s .  co m*/
 * Sets the handler, failed -> BadCredentialsException, success -> just continue.
 */
public void afterPropertiesSet() {
    super.afterPropertiesSet();
    setAuthenticationFailureHandler(new AuthenticationFailureHandler() {
        public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
                AuthenticationException exception) throws IOException, ServletException {
            if (exception instanceof BadCredentialsException) {
                exception = // NOSONAR
                        new BadCredentialsException(exception.getMessage(),
                                new BadClientCredentialsException());
            }
            authenticationEntryPoint.commence(request, response, exception);
        }
    });
    setAuthenticationSuccessHandler(new MyAuthenticationSuccessHandler());
}

From source file:com.hundsun.sso.controller.OAuthRestController.java

@ExceptionHandler(ClientRegistrationException.class)
public ResponseEntity<OAuth2Exception> handleClientRegistrationException(Exception e) throws Exception {
    LOG.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
    return getExceptionTranslator().translate(new BadClientCredentialsException());
}

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

@ExceptionHandler(ClientRegistrationException.class)
public ModelAndView handleClientRegistrationException(Exception e, ServletWebRequest webRequest)
        throws Exception {
    logger.info("Handling ClientRegistrationException error: " + e.getMessage());
    return handleException(new BadClientCredentialsException(), webRequest);
}