Search in sources :

Example 6 with Handler

use of org.forgerock.http.Handler 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));
}
Also used : RootContext(org.forgerock.services.context.RootContext) ClientContext(org.forgerock.services.context.ClientContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) Context(org.forgerock.services.context.Context) AuditRequestContext(org.forgerock.openam.audit.context.AuditRequestContext) SessionContext(org.forgerock.http.session.SessionContext) AttributesContext(org.forgerock.services.context.AttributesContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) Request(org.forgerock.http.protocol.Request) Handler(org.forgerock.http.Handler) AuditEvent(org.forgerock.audit.events.AuditEvent) Test(org.testng.annotations.Test)

Example 7 with Handler

use of org.forgerock.http.Handler in project OpenAM by OpenRock.

the class CoreRestGuiceModule method configure.

@Override
protected void configure() {
    install(new FactoryModuleBuilder().implement(SmsRequestHandler.class, SmsRequestHandler.class).build(SmsRequestHandlerFactory.class));
    install(new FactoryModuleBuilder().implement(SmsCollectionProvider.class, SmsCollectionProvider.class).build(SmsCollectionProviderFactory.class));
    install(new FactoryModuleBuilder().implement(SmsSingletonProvider.class, SmsSingletonProvider.class).build(SmsSingletonProviderFactory.class));
    install(new FactoryModuleBuilder().implement(SmsGlobalSingletonProvider.class, SmsGlobalSingletonProvider.class).build(SmsGlobalSingletonProviderFactory.class));
    bind(DebugRecorder.class).to(DefaultDebugRecorder.class);
    MapBinder<RouteMatcher<Request>, Handler> chfEndpointHandlers = newMapBinder(binder(), new TypeLiteral<RouteMatcher<Request>>() {
    }, new TypeLiteral<Handler>() {
    });
    chfEndpointHandlers.addBinding(requestUriMatcher(EQUALS, "authenticate")).to(Key.get(Handler.class, Names.named("AuthenticateHandler")));
    MapBinder<Component, AbstractHttpAccessAuditFilter> httpAccessAuditFilterMapBinder = newMapBinder(binder(), Component.class, AbstractHttpAccessAuditFilter.class);
    httpAccessAuditFilterMapBinder.addBinding(AUTHENTICATION).to(AuthenticationAccessAuditFilter.class);
    Multibinder<UiRolePredicate> userUiRolePredicates = Multibinder.newSetBinder(binder(), UiRolePredicate.class);
    userUiRolePredicates.addBinding().to(SelfServiceUserUiRolePredicate.class);
    userUiRolePredicates.addBinding().to(GlobalAdminUiRolePredicate.class);
    userUiRolePredicates.addBinding().to(RealmAdminUiRolePredicate.class);
    MapBinder<MatchingResourcePath, CrestAuthorizationModule> smsGlobalAuthzModuleBinder = MapBinder.newMapBinder(binder(), MatchingResourcePath.class, CrestAuthorizationModule.class);
    smsGlobalAuthzModuleBinder.addBinding(resourcePath("realms")).to(AnyPrivilegeAuthzModule.class);
    smsGlobalAuthzModuleBinder.addBinding(resourcePath("authentication/modules/*")).to(PrivilegeWriteAndAnyPrivilegeReadOnlyAuthzModule.class);
    smsGlobalAuthzModuleBinder.addBinding(resourcePath("services/scripting")).to(PrivilegeWriteAndAnyPrivilegeReadOnlyAuthzModule.class);
    smsGlobalAuthzModuleBinder.addBinding(resourcePath("services/scripting/contexts")).to(PrivilegeWriteAndAnyPrivilegeReadOnlyAuthzModule.class);
}
Also used : FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) ConsoleConfigHandler(org.forgerock.openam.sm.config.ConsoleConfigHandler) SmsRequestHandler(org.forgerock.openam.core.rest.sms.SmsRequestHandler) Handler(org.forgerock.http.Handler) CrestAuthorizationModule(org.forgerock.authz.filter.crest.api.CrestAuthorizationModule) SmsGlobalSingletonProviderFactory(org.forgerock.openam.core.rest.sms.SmsGlobalSingletonProviderFactory) SmsRequestHandlerFactory(org.forgerock.openam.core.rest.sms.SmsRequestHandlerFactory) SmsCollectionProviderFactory(org.forgerock.openam.core.rest.sms.SmsCollectionProviderFactory) DebugRecorder(org.forgerock.openam.core.rest.record.DebugRecorder) DefaultDebugRecorder(org.forgerock.openam.core.rest.record.DefaultDebugRecorder) RouteMatcher(org.forgerock.services.routing.RouteMatcher) Component(org.forgerock.openam.audit.AuditConstants.Component) MatchingResourcePath(org.forgerock.openam.forgerockrest.utils.MatchingResourcePath) SmsSingletonProviderFactory(org.forgerock.openam.core.rest.sms.SmsSingletonProviderFactory) AbstractHttpAccessAuditFilter(org.forgerock.openam.audit.AbstractHttpAccessAuditFilter)

Example 8 with Handler

use of org.forgerock.http.Handler in project OpenAM by OpenRock.

the class CoreRestGuiceModule method getAuthenticateHandler.

@Provides
@Named("AuthenticateHandler")
@Inject
Handler getAuthenticateHandler(@Named("InvalidRealmNames") Set<String> invalidRealms, HttpAccessAuditFilterFactory httpAuditFactory) {
    invalidRealms.add(firstPathSegment("authenticate"));
    org.forgerock.http.routing.Router authenticateVersionRouter = new org.forgerock.http.routing.Router();
    Handler authenticateHandlerV1 = Endpoints.from(AuthenticationServiceV1.class);
    Handler authenticateHandlerV2 = Endpoints.from(AuthenticationServiceV2.class);
    authenticateVersionRouter.addRoute(RouteMatchers.requestResourceApiVersionMatcher(version(1, 1)), authenticateHandlerV1);
    authenticateVersionRouter.addRoute(RouteMatchers.requestResourceApiVersionMatcher(version(2)), authenticateHandlerV2);
    return chainOf(authenticateVersionRouter, httpAuditFactory.createFilter(AUTHENTICATION));
}
Also used : ConsoleConfigHandler(org.forgerock.openam.sm.config.ConsoleConfigHandler) SmsRequestHandler(org.forgerock.openam.core.rest.sms.SmsRequestHandler) Handler(org.forgerock.http.Handler) Inject(javax.inject.Inject) Named(javax.inject.Named) Provides(com.google.inject.Provides)

Example 9 with Handler

use of org.forgerock.http.Handler in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldConsumeRealmFromCRUDPAQRequestWithInvalidSubrealm.

@Test(dataProvider = "CRUDPAQ")
public void filterShouldConsumeRealmFromCRUDPAQRequestWithInvalidSubrealm(Request request, String postURIString) throws Exception {
    //Given
    RequestHandler requestHandler = mock(RequestHandler.class);
    String path = INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT;
    Context context = mockContext(path);
    request.setUri(createRequestURI(HOSTNAME, path, postURIString));
    mockDnsAlias(HOSTNAME, "/");
    mockInvalidRealmAlias(INVALID_SUB_REALM);
    //When
    Handler httpHandler = getHttpHandler(requestHandler);
    httpHandler.handle(context, request).getOrThrowUninterruptibly();
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    ArgumentCaptor<org.forgerock.json.resource.Request> requestCaptor = ArgumentCaptor.forClass(org.forgerock.json.resource.Request.class);
    collectCRUDPAQArguments(requestHandler, contextCaptor, requestCaptor);
    verifyRealmContext(contextCaptor.getValue(), "", "/", null);
    verifyUriRouterContextForInvalidRealm(contextCaptor.getValue());
    verifyResolvedResourcePath(requestCaptor.getValue(), INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
}
Also used : RootContext(org.forgerock.services.context.RootContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) AttributesContext(org.forgerock.services.context.AttributesContext) RequestHandler(org.forgerock.json.resource.RequestHandler) CreateRequest(org.forgerock.json.resource.CreateRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) PatchRequest(org.forgerock.json.resource.PatchRequest) Request(org.forgerock.http.protocol.Request) QueryRequest(org.forgerock.json.resource.QueryRequest) RequestHandler(org.forgerock.json.resource.RequestHandler) QueryResponseHandler(org.forgerock.openam.rest.query.QueryResponseHandler) Handler(org.forgerock.http.Handler) Test(org.testng.annotations.Test)

Example 10 with Handler

use of org.forgerock.http.Handler in project OpenAM by OpenRock.

the class CrestProtocolEnforcementFilterTest method requestWithNoProtocolVersionShouldBeDefaultedAndThenCallHandler.

@Test
public void requestWithNoProtocolVersionShouldBeDefaultedAndThenCallHandler() {
    //Given
    Context context = mock(Context.class);
    Request request = new Request();
    Handler next = mock(Handler.class);
    //When
    filter.filter(context, request, next);
    //Then
    assertThat(AcceptApiVersionHeader.valueOf(request).getProtocolVersion()).isEqualTo(version(1));
    verify(next).handle(context, request);
}
Also used : Context(org.forgerock.services.context.Context) Request(org.forgerock.http.protocol.Request) Handler(org.forgerock.http.Handler) Test(org.testng.annotations.Test)

Aggregations

Handler (org.forgerock.http.Handler)13 Request (org.forgerock.http.protocol.Request)10 Context (org.forgerock.services.context.Context)10 Test (org.testng.annotations.Test)9 AttributesContext (org.forgerock.services.context.AttributesContext)5 RootContext (org.forgerock.services.context.RootContext)5 Response (org.forgerock.http.protocol.Response)4 UriRouterContext (org.forgerock.http.routing.UriRouterContext)3 ActionRequest (org.forgerock.json.resource.ActionRequest)3 CreateRequest (org.forgerock.json.resource.CreateRequest)3 DeleteRequest (org.forgerock.json.resource.DeleteRequest)3 PatchRequest (org.forgerock.json.resource.PatchRequest)3 QueryRequest (org.forgerock.json.resource.QueryRequest)3 ReadRequest (org.forgerock.json.resource.ReadRequest)3 RequestHandler (org.forgerock.json.resource.RequestHandler)3 UpdateRequest (org.forgerock.json.resource.UpdateRequest)3 QueryResponseHandler (org.forgerock.openam.rest.query.QueryResponseHandler)3 AuditEvent (org.forgerock.audit.events.AuditEvent)2 SessionContext (org.forgerock.http.session.SessionContext)2 AuditRequestContext (org.forgerock.openam.audit.context.AuditRequestContext)2