Search in sources :

Example 21 with RootContext

use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.

the class ResourceApiVersionRoutingFilter method handle.

void handle(Request request, Response response, RestletRouter next) {
    ApiVersionRouterContext apiVersionRouterContext = createApiVersionRouterContext(new RootContext());
    next.handle(apiVersionRouterContext, request, response);
    if (apiVersionRouterContext.getResourceVersion() != null) {
        addContentAPIVersion(response, enforcedProtocolVersion, apiVersionRouterContext.getResourceVersion());
        // If warnings are wanted, and we haven't thrown an exception by this point let's see what we can do...
        if (behaviourManager.isWarningEnabled()) {
            Version requestedVersion = parseResourceApiVersion(request);
            if (requestedVersion == null) {
                // If no version specified at all, we can warn about that
                AdviceWarning warningHeader = AdviceWarning.newAdviceWarning(AGENT_NAME, "No " + AcceptApiVersionHeader.NAME + " specified");
                ServletUtils.getResponse(response).addHeader("Warning", warningHeader.toString());
            }
        }
    }
}
Also used : RootContext(org.forgerock.services.context.RootContext) Version(org.forgerock.http.routing.Version) ResourceApiVersionRestlet.parseResourceApiVersion(org.forgerock.openam.rest.service.ResourceApiVersionRestlet.parseResourceApiVersion) AdviceWarning(org.forgerock.json.resource.AdviceWarning) ApiVersionRouterContext(org.forgerock.http.routing.ApiVersionRouterContext)

Example 22 with RootContext

use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.

the class HttpRouterProviderTest method shouldAddRoutesToRouter.

@Test(dataProvider = "routeRequestsData")
public void shouldAddRoutesToRouter(String requestUri, Handler exceptedHandler) {
    //Given
    Context context = new RootContext();
    Request request = new Request().setUri(URI.create(requestUri));
    Router router = httpRouterProvider.get();
    //When
    router.handle(context, request);
    //Then
    verify(exceptedHandler).handle(any(Context.class), eq(request));
}
Also used : RootContext(org.forgerock.services.context.RootContext) Context(org.forgerock.services.context.Context) RootContext(org.forgerock.services.context.RootContext) Request(org.forgerock.http.protocol.Request) Router(org.forgerock.http.routing.Router) Test(org.testng.annotations.Test)

Example 23 with RootContext

use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.

the class SessionResourceAuthzModuleTest method shouldDeferAllOthers.

@Test
public void shouldDeferAllOthers() {
    //given
    RootContext rootContext = new RootContext();
    ActionRequest mockRequest = mock(ActionRequest.class);
    given(mockRequest.getAction()).willReturn("something else");
    //when
    Promise<AuthorizationResult, ResourceException> promise = testModule.authorizeAction(rootContext, mockRequest);
    //then
    assertThat(promise).failedWithException().isExactlyInstanceOf(ForbiddenException.class);
}
Also used : RootContext(org.forgerock.services.context.RootContext) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 24 with RootContext

use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.

the class AuditEventPublisherImpl method publishToDefault.

private void publishToDefault(String topic, AuditEvent auditEvent) throws ResourceException {
    AMAuditService auditService = auditServiceProvider.getDefaultAuditService();
    Connection connection = newInternalConnection(auditService);
    CreateRequest request = newCreateRequest(topic, auditEvent.getValue());
    connection.create(new RootContext(), request);
}
Also used : RootContext(org.forgerock.services.context.RootContext) CreateRequest(org.forgerock.json.resource.CreateRequest) Requests.newCreateRequest(org.forgerock.json.resource.Requests.newCreateRequest) Connection(org.forgerock.json.resource.Connection) Resources.newInternalConnection(org.forgerock.json.resource.Resources.newInternalConnection)

Aggregations

RootContext (org.forgerock.services.context.RootContext)24 Test (org.testng.annotations.Test)16 Context (org.forgerock.services.context.Context)7 Request (org.forgerock.http.protocol.Request)5 RealmContext (org.forgerock.openam.rest.RealmContext)5 SessionContext (org.forgerock.http.session.SessionContext)4 AttributesContext (org.forgerock.services.context.AttributesContext)4 Connection (org.forgerock.json.resource.Connection)3 CreateRequest (org.forgerock.json.resource.CreateRequest)3 SSOTokenID (com.iplanet.sso.SSOTokenID)2 Response (org.forgerock.http.protocol.Response)2 ActionRequest (org.forgerock.json.resource.ActionRequest)2 DeleteRequest (org.forgerock.json.resource.DeleteRequest)2 QueryRequest (org.forgerock.json.resource.QueryRequest)2 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)2 ReadRequest (org.forgerock.json.resource.ReadRequest)2 Requests.newCreateRequest (org.forgerock.json.resource.Requests.newCreateRequest)2 ResourceException (org.forgerock.json.resource.ResourceException)2 Resources.newInternalConnection (org.forgerock.json.resource.Resources.newInternalConnection)2 AdminSubjectContext (org.forgerock.openam.rest.resource.AdminSubjectContext)2