Search in sources :

Example 1 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class RestRouterIT method shouldBeAbleToReachInternalViaInternalRouter.

@Test
public void shouldBeAbleToReachInternalViaInternalRouter() throws Exception {
    // Given
    Promise<ResourceResponse, ResourceException> promise = newResultPromise(newResourceResponse("1", "1", json(object())));
    given(internalResource.readInstance(any(Context.class), eq("123"), any(ReadRequest.class))).willReturn(promise);
    Router internalRouter = InjectorHolder.getInstance(Key.get(Router.class, Names.named("InternalCrestRouter")));
    Context context = mockRequiredContexts();
    ReadRequest request = Requests.newReadRequest("internal/123");
    // When
    internalRouter.handleRead(context, request);
    // Then
    verify(internalResource).readInstance(any(Context.class), eq("123"), 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) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) Router(org.forgerock.json.resource.Router) ResourceException(org.forgerock.json.resource.ResourceException) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 2 with ReadRequest

use of org.forgerock.json.resource.ReadRequest 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)

Example 3 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class AuditFilterTest method shouldReturnNullForReadSuccess.

@Test
public void shouldReturnNullForReadSuccess() {
    ReadRequest readRequest = mock(ReadRequest.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    JsonValue filterResponse = auditFilter.getReadSuccessDetail(readRequest, resourceResponse);
    assertThat(filterResponse).isEqualTo(null);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 4 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class SelfServiceRequestHandlerTest method initialReadCallsIntoUnderlyingService.

@Test
public void initialReadCallsIntoUnderlyingService() throws ResourceException {
    // When
    ReadRequest request = Requests.newReadRequest("/someEndpoint");
    given(consoleConfigHandler.getConfig("/", MockBuilder.class)).willReturn(consoleConfig);
    given(providerFactory.getProvider(consoleConfig)).willReturn(configProvider);
    given(configProvider.isServiceEnabled(consoleConfig)).willReturn(true);
    ProcessInstanceConfig config = new ProcessInstanceConfig();
    given(configProvider.getServiceConfig(consoleConfig, context, "/")).willReturn(config);
    given(serviceFactory.getService("/", config)).willReturn(underlyingService);
    // Given
    selfServiceHandler.handleRead(context, request);
    // Then
    verify(underlyingService).handleRead(context, request);
}
Also used : ProcessInstanceConfig(org.forgerock.selfservice.core.config.ProcessInstanceConfig) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 5 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class ApplicationTypesResourceTest method shouldReadInstanceCorrectly.

@Test
public void shouldReadInstanceCorrectly() throws IllegalAccessException, InstantiationException, ExecutionException, InterruptedException {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject subject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(subject);
    ReadRequest request = mock(ReadRequest.class);
    ApplicationType mockApplicationType = new ApplicationType("test", null, null, null, null);
    given(mockApplicationTypeManager.getApplicationType(subject, "test")).willReturn(mockApplicationType);
    //when
    Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
    //then
    assertTrue(result.get().getId().equals("test"));
}
Also used : Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ApplicationType(com.sun.identity.entitlement.ApplicationType) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Aggregations

ReadRequest (org.forgerock.json.resource.ReadRequest)35 Test (org.testng.annotations.Test)31 ResourceException (org.forgerock.json.resource.ResourceException)28 ResourceResponse (org.forgerock.json.resource.ResourceResponse)27 Context (org.forgerock.services.context.Context)23 RealmContext (org.forgerock.openam.rest.RealmContext)15 Subject (javax.security.auth.Subject)13 ClientContext (org.forgerock.services.context.ClientContext)11 JsonSchema (com.fasterxml.jackson.databind.jsonschema.JsonSchema)8 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)7 JsonValue (org.forgerock.json.JsonValue)6 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)6 RequestHandler (org.forgerock.json.resource.RequestHandler)4 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)3 LogicalSubject (com.sun.identity.entitlement.LogicalSubject)3 Map (java.util.Map)3 AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)3 Router (org.forgerock.json.resource.Router)3 EntitlementException (com.sun.identity.entitlement.EntitlementException)2 CreateRequest (org.forgerock.json.resource.CreateRequest)2