Examples of InvalidTokenException


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

    headers.set("Authorization", getAuthorizationHeader(clientId, clientSecret));
    Map<String, Object> map = postForMap(checkTokenEndpointUrl, formData, headers);

    if (map.containsKey("error")) {
      logger.debug("check_token returned error: " + map.get("error"));
      throw new InvalidTokenException(accessToken);
    }

    Assert.state(map.containsKey("client_id"), "Client id must be present in response from auth server");
    return tokenConverter.extractAuthentication(map);
  }
View Full Code Here

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

    // token.
    tokenStore.removeAccessTokenUsingRefreshToken(refreshToken);

    if (isExpired(refreshToken)) {
      tokenStore.removeRefreshToken(refreshToken);
      throw new InvalidTokenException("Invalid refresh token (expired): " + refreshToken);
    }

    authentication = createRefreshedAuthentication(authentication, tokenRequest.getScope());

    if (!reuseRefreshToken) {
View Full Code Here

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

  }

  public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException, InvalidTokenException {
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(accessTokenValue);
    if (accessToken == null) {
      throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
    }
    else if (accessToken.isExpired()) {
      tokenStore.removeAccessToken(accessToken);
      throw new InvalidTokenException("Access token expired: " + accessTokenValue);
    }

    OAuth2Authentication result = tokenStore.readAuthentication(accessToken);
    if (clientDetailsService != null) {
      String clientId = result.getOAuth2Request().getClientId();
      try {
        clientDetailsService.loadClientByClientId(clientId);
      }
      catch (ClientRegistrationException e) {
        throw new InvalidTokenException("Client not valid: " + clientId, e);
      }
    }
    return result;
  }
View Full Code Here

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

  }

  public String getClientId(String tokenValue) {
    OAuth2Authentication authentication = tokenStore.readAuthentication(tokenValue);
    if (authentication == null) {
      throw new InvalidTokenException("Invalid access token: " + tokenValue);
    }
    OAuth2Request clientAuth = authentication.getOAuth2Request();
    if (clientAuth == null) {
      throw new InvalidTokenException("Invalid access token (no client id): " + tokenValue);
    }
    return clientAuth.getClientId();
  }
View Full Code Here

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

    assertEquals(expected, getOutput());
  }

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

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

  @Test
  public void readInvalidToken() throws Exception {
    String accessToken = createResponse(OAuth2Exception.INVALID_TOKEN);
    when(inputMessage.getBody()).thenReturn(createInputStream(accessToken));
    @SuppressWarnings("unused")
    InvalidTokenException result = (InvalidTokenException) converter.read(OAuth2Exception.class, inputMessage);
  }
View Full Code Here

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

    public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource,
        OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException {
      if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
        if (((ExpiringOAuth2RefreshToken) refreshToken).getExpiration().getTime() < System.currentTimeMillis()) {
          // this is what a real provider would do (re-throw a remote exception)
          throw new InvalidTokenException("Expired refresh token");
        }
      }
      return refreshedToken;
    }
View Full Code Here

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

  }

  @Test
  public void readValueInvalidToken() throws Exception {
    String accessToken = createResponse(OAuth2Exception.INVALID_TOKEN);
    InvalidTokenException result = (InvalidTokenException) mapper.readValue(accessToken, OAuth2Exception.class);
    assertEquals(DETAILS,result.getMessage());
    assertEquals(null,result.getAdditionalInformation());
  }
View Full Code Here

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

    assertEquals(expected,mapper.writeValueAsString(oauthException));
  }

  @Test
  public void writeValueAsStringInvalidToken() throws Exception {
    oauthException = new InvalidTokenException(DETAILS);
    String expected = createResponse(oauthException.getOAuth2ErrorCode());
    assertEquals(expected,mapper.writeValueAsString(oauthException));
  }
View Full Code Here

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

  }

  @Test
  public void readValueInvalidToken() throws Exception {
    String accessToken = createResponse(OAuth2Exception.INVALID_TOKEN);
    InvalidTokenException result = (InvalidTokenException) mapper.readValue(accessToken, OAuth2Exception.class);
    assertEquals(DETAILS,result.getMessage());
    assertEquals(null,result.getAdditionalInformation());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.