Search in sources :

Example 81 with Context

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

the class RestRouterIT method shouldReadCrestEndpointOnRootHandler.

@Test
public void shouldReadCrestEndpointOnRootHandler() throws Exception {
    //Given
    Context context = mockRequiredContexts();
    Request request = newRequest("GET", "/json/config");
    auditingOff();
    //When
    handler.handle(context, request);
    //Then
    verify(configResource).readInstance(any(Context.class), any(ReadRequest.class));
}
Also used : RootContext(org.forgerock.services.context.RootContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SessionContext(org.forgerock.http.session.SessionContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) AttributesContext(org.forgerock.services.context.AttributesContext) SecurityContext(org.forgerock.services.context.SecurityContext) Context(org.forgerock.services.context.Context) Request(org.forgerock.http.protocol.Request) ReadRequest(org.forgerock.json.resource.ReadRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 82 with Context

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

the class RestRouterIT method shouldReadCrestEndpointOnRealmHandlerWithRootRealm.

@Test
public void shouldReadCrestEndpointOnRealmHandlerWithRootRealm() throws Exception {
    //Given
    Context context = mockRequiredContexts();
    Request request = newRequest("GET", "/json/users/demo");
    auditingOff();
    //When
    handler.handle(context, request);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(usersResource).readInstance(contextCaptor.capture(), eq("demo"), any(ReadRequest.class));
    assertThat(contextCaptor.getValue().asContext(RealmContext.class).getResolvedRealm()).isEqualTo("/");
}
Also used : RootContext(org.forgerock.services.context.RootContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SessionContext(org.forgerock.http.session.SessionContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) AttributesContext(org.forgerock.services.context.AttributesContext) SecurityContext(org.forgerock.services.context.SecurityContext) Context(org.forgerock.services.context.Context) Request(org.forgerock.http.protocol.Request) ReadRequest(org.forgerock.json.resource.ReadRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 83 with Context

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

the class CrestProtocolEnforcementFilterTest method requestWithCorrectProtocolVersionShouldCallHandler.

@Test
public void requestWithCorrectProtocolVersionShouldCallHandler() {
    //Given
    Context context = mock(Context.class);
    Request request = new Request();
    Handler next = mock(Handler.class);
    request.getHeaders().put(AcceptApiVersionHeader.valueOf("protocol=1"));
    //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)

Example 84 with Context

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

the class CrestProtocolEnforcementFilterTest method requestWithIncorrectProtocolMajorVersionShouldReturnBadRequestResponse.

@Test
public void requestWithIncorrectProtocolMajorVersionShouldReturnBadRequestResponse() throws IOException {
    //Given
    Context context = mock(Context.class);
    Request request = new Request();
    Handler next = mock(Handler.class);
    request.getHeaders().put(AcceptApiVersionHeader.valueOf("protocol=2"));
    //When
    Response response = filter.filter(context, request, next).getOrThrowUninterruptibly();
    //Then
    assertThat(getUnsupportedMajorVersionExceptionJson(version(2))).isEqualTo(response.getEntity().getJson());
    assertThat(AcceptApiVersionHeader.valueOf(request).getProtocolVersion()).isEqualTo(version(2));
    verify(next, never()).handle(context, request);
}
Also used : Context(org.forgerock.services.context.Context) Response(org.forgerock.http.protocol.Response) Request(org.forgerock.http.protocol.Request) Handler(org.forgerock.http.Handler) Test(org.testng.annotations.Test)

Example 85 with Context

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

the class ElevatedConnectionFactoryWrapperTest method requestGetsElevatedToAdminSession.

@Test
public void requestGetsElevatedToAdminSession() throws Exception {
    // Given
    SSOToken ssoToken = mock(SSOToken.class);
    given(ssoTokenPrivilegedAction.run()).willReturn(ssoToken);
    SSOPrincipal principal = new SSOPrincipal("test");
    given(ssoToken.getPrincipal()).willReturn(principal);
    SSOTokenID tokenID = mock(SSOTokenID.class);
    given(ssoToken.getTokenID()).willReturn(tokenID);
    given(internalConnectionFactory.getConnection()).willReturn(connection);
    // When
    RootContext context = new RootContext();
    ReadRequest readRequest = Requests.newReadRequest("/test", "abc");
    try (Connection connection = connectionFactory.getConnection()) {
        connection.read(context, readRequest);
    }
    // Then
    verify(connection).read(contextCaptor.capture(), eq(readRequest));
    Context capturedContext = contextCaptor.getValue();
    assertThat(capturedContext.containsContext(SecurityContext.class)).isTrue();
    SecurityContext securityContext = capturedContext.asContext(SecurityContext.class);
    assertThat(securityContext.getAuthenticationId()).isEqualTo("test");
    assertThat(securityContext.getAuthorization()).containsOnlyKeys("authLevel", "tokenId");
}
Also used : SSOTokenID(com.iplanet.sso.SSOTokenID) RootContext(org.forgerock.services.context.RootContext) SecurityContext(org.forgerock.services.context.SecurityContext) Context(org.forgerock.services.context.Context) RootContext(org.forgerock.services.context.RootContext) SSOToken(com.iplanet.sso.SSOToken) SSOPrincipal(com.iplanet.sso.providers.dpro.SSOPrincipal) Connection(org.forgerock.json.resource.Connection) SecurityContext(org.forgerock.services.context.SecurityContext) ReadRequest(org.forgerock.json.resource.ReadRequest) 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