use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifierTest method shouldCheckBodyType.
@Test
public void shouldCheckBodyType() throws Exception {
// Given
Request request = new Request();
request.setEntity(new EmptyRepresentation());
OAuth2Request req = new RestletOAuth2Request(null, request);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifierTest method shouldCheckValid.
@Test
public void shouldCheckValid() throws Exception {
// Given
Form form = new Form();
form.add("access_token", "freddy");
Request request = new Request();
request.setEntity(form.getWebRepresentation());
OAuth2Request req = new RestletOAuth2Request(null, request);
AccessToken token = new AccessToken(json(object()), "access_token", "freddy") {
@Override
public boolean isExpired() {
return false;
}
};
when(tokenStore.readAccessToken(req, "freddy")).thenReturn(token);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isTrue();
assertThat(result.getTokenId()).isEqualTo("freddy");
verify(tokenStore).readAccessToken(req, "freddy");
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifierTest method shouldCheckExpired.
@Test
public void shouldCheckExpired() throws Exception {
// Given
Form form = new Form();
form.add("access_token", "freddy");
Request request = new Request();
request.setEntity(form.getWebRepresentation());
OAuth2Request req = new RestletOAuth2Request(null, request);
AccessToken token = new AccessToken(json(object()), "access_token", "freddy") {
@Override
public boolean isExpired() {
return true;
}
};
when(tokenStore.readAccessToken(req, "freddy")).thenReturn(token);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
verify(tokenStore).readAccessToken(req, "freddy");
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifierTest method shouldCheckBody.
@Test
public void shouldCheckBody() throws Exception {
// Given
Request request = new Request();
OAuth2Request req = new RestletOAuth2Request(null, request);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class RestletHeaderAccessTokenVerifier method obtainTokenId.
/**
* {@inheritDoc}
*/
protected String obtainTokenId(OAuth2Request request) {
final Request req = request.getRequest();
ChallengeResponse result = getChallengeResponse(req);
if (result == null) {
logger.debug("Request does not contain Authorization header.");
return null;
}
return result.getRawValue();
}
Aggregations