Search in sources :

Example 86 with Context

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

the class RealmContextFilterTest method filterShouldConsumeRealmFromCRUDPAQRequestWithSubrealm.

@Test(dataProvider = "CRUDPAQ")
public void filterShouldConsumeRealmFromCRUDPAQRequestWithSubrealm(Request request, String postURIString) throws Exception {
    //Given
    RequestHandler requestHandler = mock(RequestHandler.class);
    String path = SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT;
    Context context = mockContext(path);
    request.setUri(createRequestURI(HOSTNAME, path, postURIString));
    mockDnsAlias(HOSTNAME, "/");
    mockRealmAlias("/" + SUB_REALM, "/" + 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(), "", "/" + SUB_REALM, null);
    verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM);
    verifyResolvedResourcePath(requestCaptor.getValue(), 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 87 with Context

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

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithUriRealmAndOverrideRealm.

@Test
public void filterShouldConsumeRealmFromRequestWithUriRealmAndOverrideRealm() throws Exception {
    //Given
    Context context = mockContext(SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(HOSTNAME, SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
    mockDnsAlias(HOSTNAME, "/");
    mockRealmAlias("/" + SUB_REALM, "/" + SUB_REALM);
    mockRealmAlias(OVERRIDE_REALM_ALIAS, OVERRIDE_REALM);
    //When
    filter.filter(context, request, handler);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(handler).handle(contextCaptor.capture(), eq(request));
    verifyRealmContext(contextCaptor.getValue(), "", "/" + SUB_REALM, OVERRIDE_REALM);
    verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM);
}
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) 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) Test(org.testng.annotations.Test)

Example 88 with Context

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

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithDnsAlias.

@Test
public void filterShouldConsumeRealmFromRequestWithDnsAlias() throws Exception {
    //Given
    Context context = mockContext(ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(DNS_ALIAS_HOSTNAME, ENDPOINT_PATH_ELEMENT);
    mockDnsAlias(DNS_ALIAS_HOSTNAME, "/" + DNS_ALIS_SUB_REALM);
    //When
    filter.filter(context, request, handler);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(handler).handle(contextCaptor.capture(), eq(request));
    verifyRealmContext(contextCaptor.getValue(), "/" + DNS_ALIS_SUB_REALM, "", null);
    verifyUriRouterContext(contextCaptor.getValue(), "");
}
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) 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) Test(org.testng.annotations.Test)

Example 89 with Context

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

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithUriRealmAlias.

@Test
public void filterShouldConsumeRealmFromRequestWithUriRealmAlias() throws Exception {
    //Given
    Context context = mockContext(SUB_REALM_ALIAS + "/" + ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(HOSTNAME, SUB_REALM_ALIAS + "/" + ENDPOINT_PATH_ELEMENT);
    mockDnsAlias(HOSTNAME, "/");
    mockRealmAlias(SUB_REALM_ALIAS, "/" + SUB_REALM);
    //When
    filter.filter(context, request, handler);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(handler).handle(contextCaptor.capture(), eq(request));
    verifyRealmContext(contextCaptor.getValue(), "", "/" + SUB_REALM, null);
    verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM_ALIAS);
}
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) 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) Test(org.testng.annotations.Test)

Example 90 with Context

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

the class RealmContextFilterTest method filterShouldFailToConsumeRealmFromRequestWithDnsAliasAndUriRealmAlias.

@Test
public void filterShouldFailToConsumeRealmFromRequestWithDnsAliasAndUriRealmAlias() throws Exception {
    //Given
    Context context = mockContext(SUB_REALM_ALIAS + "/" + ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(DNS_ALIAS_HOSTNAME, SUB_REALM_ALIAS + "/" + ENDPOINT_PATH_ELEMENT);
    mockDnsAlias(DNS_ALIAS_HOSTNAME, "/" + DNS_ALIS_SUB_REALM);
    mockRealmAlias("/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM_ALIAS, "/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM);
    mockInvalidRealmAlias(SUB_REALM_ALIAS);
    //When
    filter.filter(context, request, handler);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(handler).handle(contextCaptor.capture(), eq(request));
    verifyUriRouterContextForInvalidRealm(contextCaptor.getValue());
}
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) 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) Test(org.testng.annotations.Test)

Aggregations

Context (org.forgerock.services.context.Context)250 Test (org.testng.annotations.Test)231 RealmContext (org.forgerock.openam.rest.RealmContext)150 ResourceException (org.forgerock.json.resource.ResourceException)132 ClientContext (org.forgerock.services.context.ClientContext)120 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)101 ResourceResponse (org.forgerock.json.resource.ResourceResponse)82 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)76 RootContext (org.forgerock.services.context.RootContext)62 JsonValue (org.forgerock.json.JsonValue)56 QueryRequest (org.forgerock.json.resource.QueryRequest)54 ReadRequest (org.forgerock.json.resource.ReadRequest)50 AttributesContext (org.forgerock.services.context.AttributesContext)44 ActionRequest (org.forgerock.json.resource.ActionRequest)43 QueryResponse (org.forgerock.json.resource.QueryResponse)43 Subject (javax.security.auth.Subject)42 Matchers.anyString (org.mockito.Matchers.anyString)38 Request (org.forgerock.http.protocol.Request)37 UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 DeleteRequest (org.forgerock.json.resource.DeleteRequest)35