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

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


    String pendingClientId = pendingOAuth2Request.getClientId();
    String clientId = tokenRequest.getClientId();
    if (clientId != null && !clientId.equals(pendingClientId)) {
      // just a sanity check.
      throw new InvalidClientException("Client ID mismatch");
    }

    // Secret is not required in the authorization request, so it won't be available
    // in the pendingAuthorizationRequest. We do want to check that a secret is provided
    // in the token request, but that happens elsewhere.
View Full Code Here


      clientId = authenticatedClient.getClientId();
    }
    else {
      // otherwise, make sure that they match
      if (!clientId.equals(authenticatedClient.getClientId())) {
        throw new InvalidClientException("Given client ID does not match authenticated client");
      }
    }
    String grantType = requestParameters.get(OAuth2Utils.GRANT_TYPE);

    Set<String> scopes = extractScopes(requestParameters, clientId);
View Full Code Here

  protected void validateGrantType(String grantType, ClientDetails clientDetails) {
    Collection<String> authorizedGrantTypes = clientDetails.getAuthorizedGrantTypes();
    if (authorizedGrantTypes != null && !authorizedGrantTypes.isEmpty()
        && !authorizedGrantTypes.contains(grantType)) {
      throw new InvalidClientException("Unauthorized grant type: " + grantType);
    }
  }
View Full Code Here

    if (!responseTypes.contains("token") && !responseTypes.contains("code")) {
      throw new UnsupportedResponseTypeException("Unsupported response types: " + responseTypes);
    }

    if (authorizationRequest.getClientId() == null) {
      throw new InvalidClientException("A client id must be provided");
    }

    try {

      if (!(principal instanceof Authentication) || !((Authentication) principal).isAuthenticated()) {
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

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

    assertTrue("Wrong token: " + result, result.contains("\"expires_in\":"));
  }

  @Test
  public void testExceptionSerialization() throws Exception {
    InvalidClientException exception = new InvalidClientException("FOO");
    exception.addAdditionalInformation("foo", "bar");
    String result = new ObjectMapper().writeValueAsString(exception);
    // System.err.println(result);
    assertTrue("Wrong result: "+result, result.contains("\"error\":\"invalid_client\""));
    assertTrue("Wrong result: "+result, result.contains("\"error_description\":\"FOO\""));
    assertTrue("Wrong result: "+result, result.contains("\"foo\":\"bar\""));
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

  }

  @Test
  public void testCommenceWithOAuth2Exception() throws Exception {
    request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE);
    entryPoint.commence(request, response, new BadCredentialsException("Bad", new InvalidClientException(
        "Bad client")));
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
    assertEquals("{\"error\":\"invalid_client\",\"error_description\":\"Bad client\"}", response.getContentAsString());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    assertEquals(null, response.getErrorMessage());
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.