Package org.springframework.security.oauth2.common.exceptions

Examples of org.springframework.security.oauth2.common.exceptions.OAuth2Exception


  public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException {

    OAuth2AccessTokenEntity accessToken = tokenRepository.getAccessTokenByValue(accessTokenValue);

    if (accessToken == null) {
      throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
    }

    if (accessToken.isExpired()) {
      //tokenRepository.removeAccessToken(accessToken);
      revokeAccessToken(accessToken);
      throw new InvalidTokenException("Expired access token: " + accessTokenValue);
    }

    return accessToken.getAuthenticationHolder().getAuthentication();
  }
View Full Code Here


   */
  @Override
  public OAuth2AccessTokenEntity readAccessToken(String accessTokenValue) throws AuthenticationException {
    OAuth2AccessTokenEntity accessToken = tokenRepository.getAccessTokenByValue(accessTokenValue);
    if (accessToken == null) {
      throw new InvalidTokenException("Access token for value " + accessTokenValue + " was not found");
    }
    else {
      return accessToken;
    }
  }
View Full Code Here

   */
  @Override
  public OAuth2RefreshTokenEntity getRefreshToken(String refreshTokenValue) throws AuthenticationException {
    OAuth2RefreshTokenEntity refreshToken = tokenRepository.getRefreshTokenByValue(refreshTokenValue);
    if (refreshToken == null) {
      throw new InvalidTokenException("Refresh token for value " + refreshTokenValue + " was not found");
    }
    else {
      return refreshToken;
    }
  }
View Full Code Here

      try {
        HttpMessageConverterExtractor<OAuth2Exception> extractor = new HttpMessageConverterExtractor<OAuth2Exception>(
            OAuth2Exception.class, messageConverters);
        try {
          OAuth2Exception body = extractor.extractData(bufferedResponse);
          if (body != null) {
            // If we can get an OAuth2Exception already from the body, it is likely to have more information than
            // the header does, so just re-throw it here.
            throw body;
          }
View Full Code Here

    headerType = headerType.toLowerCase();
    if (authenticateHeader.toLowerCase().startsWith(headerType)) {
      Map<String, String> headerEntries = StringSplitUtils.splitEachArrayElementAndCreateMap(
          StringSplitUtils.splitIgnoringQuotes(authenticateHeader.substring(headerType.length()), ','), "=",
          "\"");
      OAuth2Exception ex = OAuth2Exception.valueOf(headerEntries);
      if (ex instanceof InvalidTokenException) {
        // Special case: an invalid token can be renewed so tell the caller what to do
        throw new AccessTokenRequiredException(resource);
      }
      throw ex;
View Full Code Here

    @SuppressWarnings("unchecked")
    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
      for (HttpMessageConverter<?> converter : messageConverters) {
        if (converter.canRead(OAuth2Exception.class, response.getHeaders().getContentType())) {
          OAuth2Exception ex;
          try {
            ex = ((HttpMessageConverter<OAuth2Exception>) converter).read(OAuth2Exception.class, response);
          }
          catch (Exception e) {
            // ignore
View Full Code Here

    converter = new JaxbOAuth2ExceptionMessageConverter();
  }

  @Test
  public void writeInvalidClient() throws IOException {
    OAuth2Exception oauthException = new InvalidClientException(DETAILS);
    String expected = createResponse(oauthException.getOAuth2ErrorCode());
    converter.write(oauthException, contentType, outputMessage);
    assertEquals(expected, getOutput());
  }
View Full Code Here

    assertEquals(expected, getOutput());
  }

  @Test
  public void writeInvalidGrant() throws Exception {
    OAuth2Exception oauthException = new InvalidGrantException(DETAILS);
    String expected = createResponse(oauthException.getOAuth2ErrorCode());
    converter.write(oauthException, contentType, outputMessage);
    assertEquals(expected, getOutput());
  }
View Full Code Here

    assertEquals(expected, getOutput());
  }

  @Test
  public void writeInvalidRequest() throws Exception {
    OAuth2Exception oauthException = new InvalidRequestException(DETAILS);
    String expected = createResponse(oauthException.getOAuth2ErrorCode());
    converter.write(oauthException, contentType, outputMessage);
    assertEquals(expected, getOutput());
  }
View Full Code Here

    assertEquals(expected, getOutput());
  }

  @Test
  public void writeInvalidScope() throws Exception {
    OAuth2Exception oauthException = new InvalidScopeException(DETAILS);
    String expected = createResponse(oauthException.getOAuth2ErrorCode());
    converter.write(oauthException, contentType, outputMessage);
    assertEquals(expected, getOutput());
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.common.exceptions.OAuth2Exception

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.