OAuth2ValidatorImpl implements OAuth2Validator { @Override public ValidationResponse validate(AuthorizationRequest authorizationRequest) { try { validateAuthorizationRequest(authorizationRequest); String responseType = validateResponseType(authorizationRequest); Client client = validateClient(authorizationRequest); authorizationRequest.setClient(client); String redirectUri = determineRedirectUri(authorizationRequest, responseType, client); authorizationRequest.setRedirectUri(redirectUri); List<String> scopes = determineScopes(authorizationRequest, client); authorizationRequest.setRequestedScopes(scopes); } catch (ValidationResponseException e) { return e.v; } return VALID; }  @Override ValidationResponse validate(AuthorizationRequest authorizationRequest); @Override ValidationResponse validate(AccessTokenRequest request, 
      BasicAuthCredentials clientCredentials);  }
@Test public void testValidateValidRedirectUri() { request.setRedirectUri("http: validate(ValidationResponse.REDIRECT_URI_NOT_VALID); }
@Test public void testInvalidRedirectUriFragment() { request.setRedirectUri(request.getRedirectUri() + "#fragment"); validate(ValidationResponse.REDIRECT_URI_FRAGMENT_COMPONENT); }
@Test public void testClientNotPermittedImplicitGrant() { request.setResponseType(OAuth2ValidatorImpl.IMPLICIT_GRANT_RESPONSE_TYPE); validate(ValidationResponse.IMPLICIT_GRANT_NOT_PERMITTED); }
@Test public void testHappyFlow() { validate(ValidationResponse.VALID); }
@Test public void testRedirectUriWithQueryParameter() { request.setRedirectUri(request.getRedirectUri() + "?param=example&param2=test"); validate(ValidationResponse.VALID); }
@Test public void testValidateClientId() { request.setClientId("unknown_client"); validate(ValidationResponse.UNKNOWN_CLIENT_ID); }
@Test public void testValidateImplicitGrant() { reset(clientRepository); Client client = createClient("client-app"); client.setAllowedImplicitGrant(true); when(clientRepository.findByClientId(client.getClientId())).thenReturn(client); request.setResponseType(OAuth2ValidatorImpl.IMPLICIT_GRANT_RESPONSE_TYPE); request.setRedirectUri(" "); validate(ValidationResponse.IMPLICIT_GRANT_REDIRECT_URI); }
@Test public void partOfRedirectUrimatching() { request.setRedirectUri("http: validate(ValidationResponse.VALID); }
@Test public void testValidateScope() { request.setRequestedScopes(Arrays.asList("no-existing-scope")); validate(ValidationResponse.SCOPE_NOT_VALID); }
@Test public void testValidateRedirectUri() { request.setRedirectUri(" validate(ValidationResponse.REDIRECT_URI_NOT_URI); }