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

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


    oauthException = null;
  }

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


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

  @Test
  public void writeValueAsStringWithAdditionalDetails() throws Exception {
    oauthException = new InvalidClientException(DETAILS);
    oauthException.addAdditionalInformation("foo", "bar");
    String expected = "{\"error\":\"invalid_client\",\"error_description\":\"some detail\",\"foo\":\"bar\"}";
    assertEquals(expected,mapper.writeValueAsString(oauthException));
  }
View Full Code Here

  }

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

  }

  @Test
  public void readValueWithAdditionalDetails() throws Exception {
    String accessToken = "{\"error\": \"invalid_client\", \"error_description\": \"some detail\", \"foo\": \"bar\"}";
    InvalidClientException result = (InvalidClientException) mapper.readValue(accessToken, OAuth2Exception.class);
    assertEquals(DETAILS,result.getMessage());
    assertEquals("{foo=bar}",result.getAdditionalInformation().toString());
  }
View Full Code Here

  private MockHttpServletResponse response = new MockHttpServletResponse();

  @Test
  public void testErrorPage() throws Exception {
    request.setContextPath("/foo");
    request.setAttribute("error", new InvalidClientException("FOO"));
    ModelAndView result = endpoint.handleError(request);
    result.getView().render(result.getModel(), request , response);
    String content = response.getContentAsString();
    assertTrue("Wrong content: " + content, content.contains("OAuth Error"));
    assertTrue("Wrong content: " + content, content.contains("invalid_client"));
View Full Code Here

    assertEquals(token, provider.obtainAccessToken(resource, request));
  }

  @Test
  public void testGetErrorFromJson() throws Exception {
    final InvalidClientException exception = new InvalidClientException("FOO");
    requestFactory = new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(HttpStatus.BAD_REQUEST,
            new ObjectMapper().writeValueAsString(exception));
      }
View Full Code Here

    query.setParameter("code", code);

    AuthorizationCodeEntity result = JpaUtil.getSingleResult(query.getResultList());

    if (result == null) {
      throw new InvalidGrantException("JpaAuthorizationCodeRepository: no authorization code found for value " + code);
    }

    OAuth2Authentication authRequest = result.getAuthentication();

    manager.remove(result);
View Full Code Here

  @Override
  public String resolveRedirect(String requestedRedirect, ClientDetails client) throws OAuth2Exception {
    String redirect = super.resolveRedirect(requestedRedirect, client);
    if (blacklistService.isBlacklisted(redirect)) {
      // don't let it go through
      throw new InvalidRequestException("The supplied redirect_uri is not allowed on this server.");
    } else {
      // not blacklisted, passed the parent test, we're fine
      return redirect;
    }
  }
View Full Code Here

      OAuth2Authentication authentication = new OAuth2Authentication(getRequestFactory().createOAuth2Request(client, tokenRequest), incomingToken.getAuthenticationHolder().getAuthentication().getUserAuthentication());

      return authentication;

    } else {
      throw new InvalidScopeException("Invalid scope requested in chained request", approvedScopes);
    }

  }
View Full Code Here

   */
  private void validateScope(Set<String> requestedScopes, Set<String> clientScopes) throws InvalidScopeException {
    if (requestedScopes != null && !requestedScopes.isEmpty()) {
      if (clientScopes != null && !clientScopes.isEmpty()) {
        if (!scopeService.scopesMatch(clientScopes, requestedScopes)) {
          throw new InvalidScopeException("Invalid scope", clientScopes);
        }
      }
    }
  }
View Full Code Here

TOP

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

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.