use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class AuditRestRouteProvider method addResourceRoutes.
@Override
public void addResourceRoutes(ResourceRouter rootRouter, ResourceRouter realmRouter) {
rootRouter.route("global-audit").auditAs(AUDIT, AuditEndpointAuditFilter.class).authorizeWith(SpecialOrAdminOrAgentAuthzModule.class).forVersion(1).toRequestHandler(STARTS_WITH, auditServiceProvider.getDefaultAuditService());
rootRouter.route("realm-audit").auditAs(AUDIT, AuditEndpointAuditFilter.class).authorizeWith(SpecialOrAdminOrAgentAuthzModule.class).forVersion(1).through(RealmContextFilter.class).toRequestHandler(STARTS_WITH, new RequestHandler() {
@Override
public Promise<ActionResponse, ResourceException> handleAction(Context context, ActionRequest actionRequest) {
return getAuditService(context).handleAction(context, actionRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleCreate(Context context, CreateRequest createRequest) {
return getAuditService(context).handleCreate(context, createRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context context, DeleteRequest deleteRequest) {
return getAuditService(context).handleDelete(context, deleteRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handlePatch(Context context, PatchRequest patchRequest) {
return getAuditService(context).handlePatch(context, patchRequest);
}
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest queryRequest, QueryResourceHandler queryResourceHandler) {
return getAuditService(context).handleQuery(context, queryRequest, queryResourceHandler);
}
@Override
public Promise<ResourceResponse, ResourceException> handleRead(Context context, ReadRequest readRequest) {
return getAuditService(context).handleRead(context, readRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleUpdate(Context context, UpdateRequest updateRequest) {
return getAuditService(context).handleUpdate(context, updateRequest);
}
private AMAuditService getAuditService(Context context) {
String realm = context.asContext(RealmContext.class).getResolvedRealm();
if (StringUtils.isEmpty(realm)) {
logger.warn("Context contained RealmContext but had an empty resolved realm");
return auditServiceProvider.getDefaultAuditService();
}
return auditServiceProvider.getAuditService(realm);
}
});
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class AbstractHttpAccessAuditFilterTest method shouldAuditAccessAttemptAndResult.
@Test(dataProvider = "handlerResponses")
public void shouldAuditAccessAttemptAndResult(Status responseStatus) throws AuditException {
//Given
Context context = new RequestAuditContext(mockContext());
Request request = new Request().setMethod("GET").setUri(URI.create("http://example.com:8080?query=value"));
request.getHeaders().put(ContentTypeHeader.valueOf("CONTENT_TYPE"));
enableAccessTopicAuditing();
Handler handler = mockHandler(context, request, responseStatus);
//When
auditFilter.filter(context, request, handler);
//Then
ArgumentCaptor<AuditEvent> auditEventCaptor = ArgumentCaptor.forClass(AuditEvent.class);
verify(eventPublisher, times(2)).tryPublish(eq(AuditConstants.ACCESS_TOPIC), auditEventCaptor.capture());
verifyAccessAttemptAuditEvent(auditEventCaptor.getAllValues().get(0).getValue());
if (responseStatus.isSuccessful()) {
verifyAccessSuccessAuditEvent(auditEventCaptor.getAllValues().get(1).getValue());
} else {
verifyAccessFailedAuditEvent(auditEventCaptor.getAllValues().get(1).getValue());
}
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class AbstractHttpAccessAuditFilterTest method shouldNotAuditIfAuditingIsNotEnabledForAccessTopic.
@Test(dataProvider = "handlerResponses")
public void shouldNotAuditIfAuditingIsNotEnabledForAccessTopic(Status responseStatus) throws AuditException {
//Given
Context context = new RequestAuditContext(mockContext());
Request request = new Request().setUri(URI.create("http://example.com"));
disableAccessTopicAuditing();
Handler handler = mockHandler(context, request, responseStatus);
//When
auditFilter.filter(context, request, handler);
//Then
verify(eventPublisher, never()).tryPublish(anyString(), any(AuditEvent.class));
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class TrustedDevicesResourceTest method ctx.
private Context ctx() {
SSOTokenContext ssoTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(ssoTokenContext);
Context serverContext = ClientContext.newInternalClientContext(realmContext);
return serverContext;
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceAuthzModuleTest method shouldAllowLogoutAction.
@Test
public void shouldAllowLogoutAction() throws ExecutionException, InterruptedException {
//given
Context mockContext = mock(Context.class);
ActionRequest mockRequest = mock(ActionRequest.class);
given(mockRequest.getAction()).willReturn("logout");
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest);
//then
assertTrue(result.get().isAuthorized());
}
Aggregations