use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifier method obtainTokenId.
/**
* {@inheritDoc}
*/
protected String obtainTokenId(OAuth2Request request) {
final Request req = request.getRequest();
final Representation body = req.getEntity();
if (body == null || !MediaType.APPLICATION_WWW_FORM.equals(body.getMediaType())) {
logger.debug("Request does not contain form.");
return null;
}
Form formBody = new Form(body);
if (!formBody.getNames().contains(OAuth2Constants.Params.ACCESS_TOKEN)) {
logger.debug("Request form does not contain access_token.");
return null;
}
return formBody.getFirstValue(OAuth2Constants.Params.ACCESS_TOKEN);
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class EndSessionTest method shouldAttemptEndSessionAndNotRedirect.
@Test
public void shouldAttemptEndSessionAndNotRedirect() throws Exception {
// given
String requestedUri = "";
String registeredUri = "http://www.example.com";
when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri);
when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri)));
// when
Representation result = endSession.endSession();
// then
verify(openIDConnectEndSession, times(1)).endSession(any(String.class));
assertThat(result).isNull();
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method shouldUpdateResourceSetDescription.
@Test
@SuppressWarnings("unchecked")
public void shouldUpdateResourceSetDescription() throws Exception {
//Given
JsonRepresentation entity = createUpdateRequestRepresentation();
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", RESOURCE_SET_DESCRIPTION_CONTENT.asMap());
setUriResourceSetId();
addCondition();
given(store.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID")).willReturn(resourceSetDescription);
//When
Representation responseRep = endpoint.updateResourceSet(entity);
//Then
ArgumentCaptor<ResourceSetDescription> resourceSetCaptor = ArgumentCaptor.forClass(ResourceSetDescription.class);
verify(store).update(resourceSetCaptor.capture());
assertThat(resourceSetCaptor.getValue().getId()).isEqualTo("RESOURCE_SET_ID");
assertThat(resourceSetCaptor.getValue().getClientId()).isEqualTo("CLIENT_ID");
assertThat(resourceSetCaptor.getValue().getName()).isEqualTo("NEW_NAME");
assertThat(resourceSetCaptor.getValue().getUri()).isEqualTo(URI.create("NEW_URI"));
assertThat(resourceSetCaptor.getValue().getType()).isEqualTo("NEW_TYPE");
assertThat(resourceSetCaptor.getValue().getScopes()).containsExactly("NEW_SCOPE");
assertThat(resourceSetCaptor.getValue().getIconUri()).isEqualTo(URI.create("NEW_ICON_URI"));
Map<String, Object> responseBody = (Map<String, Object>) new ObjectMapper().readValue(responseRep.getText(), Map.class);
assertThat(responseBody).containsKey("_id");
verify(labelRegistration).updateLabelsForExistingResourceSet(any(ResourceSetDescription.class));
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method shouldCreateResourceSetDescription.
@Test
@SuppressWarnings("unchecked")
public void shouldCreateResourceSetDescription() throws Exception {
//Given
JsonRepresentation entity = createCreateRequestRepresentation();
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ResourceSetDescription resourceSetDescription = (ResourceSetDescription) invocation.getArguments()[1];
resourceSetDescription.setId("123");
return null;
}
}).when(store).create(any(OAuth2Request.class), any(ResourceSetDescription.class));
setUriResourceSetId();
noConditions();
//When
Representation response = endpoint.createResourceSet(entity);
//Then
ArgumentCaptor<ResourceSetDescription> resourceSetCaptor = ArgumentCaptor.forClass(ResourceSetDescription.class);
InOrder inOrder = inOrder(resourceRegistrationFilter, store, resourceRegistrationFilter);
inOrder.verify(resourceRegistrationFilter).beforeResourceRegistration(any(ResourceSetDescription.class));
inOrder.verify(store).create(Matchers.<OAuth2Request>anyObject(), resourceSetCaptor.capture());
inOrder.verify(resourceRegistrationFilter).afterResourceRegistration(any(ResourceSetDescription.class));
assertThat(resourceSetCaptor.getValue().getId()).isNotNull().isNotEmpty();
assertThat(resourceSetCaptor.getValue().getClientId()).isEqualTo("CLIENT_ID");
assertThat(resourceSetCaptor.getValue().getName()).isEqualTo("NAME");
assertThat(resourceSetCaptor.getValue().getUri()).isEqualTo(URI.create("URI"));
assertThat(resourceSetCaptor.getValue().getType()).isEqualTo("TYPE");
assertThat(resourceSetCaptor.getValue().getScopes()).containsExactly("SCOPE");
assertThat(resourceSetCaptor.getValue().getIconUri()).isEqualTo(URI.create("ICON_URI"));
Map<String, Object> responseBody = (Map<String, Object>) new ObjectMapper().readValue(response.getText(), Map.class);
assertThat(responseBody).containsKey("_id");
verify(hook).resourceSetCreated(anyString(), Matchers.<ResourceSetDescription>anyObject());
verify(labelRegistration).updateLabelsForNewResourceSet(any(ResourceSetDescription.class));
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilter method auditAccessSuccess.
private void auditAccessSuccess(Request request, Response response) {
String realm = getRealmFromRequest(request);
if (auditEventPublisher.isAuditing(realm, ACCESS_TOPIC, EventName.AM_ACCESS_OUTCOME)) {
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - request.getDate().getTime();
final Representation entity = response.getEntity();
AMAccessAuditEventBuilder builder = auditEventFactory.accessEvent(realm).timestamp(endTime).transactionId(AuditRequestContext.getTransactionIdValue()).eventName(EventName.AM_ACCESS_OUTCOME).component(component).userId(getUserIdForAccessOutcome(request, response)).trackingIds(getTrackingIdsForAccessOutcome(request, response));
JsonValue detail = null;
if (responseDetailCreator != null) {
try {
detail = responseDetailCreator.apply(entity);
} catch (AuditException e) {
debug.warning("An error occurred when fetching response body details for audit", e);
}
}
if (detail == null) {
builder.response(SUCCESSFUL, "", elapsedTime, MILLISECONDS);
} else {
builder.responseWithDetail(SUCCESSFUL, "", elapsedTime, MILLISECONDS, detail);
}
addHttpData(request, builder);
auditEventPublisher.tryPublish(ACCESS_TOPIC, builder.toEvent());
}
}
Aggregations