Search in sources :

Example 1 with RootContext

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

the class RestRouterIT method mockContext.

private Context mockContext(Context parent) {
    if (parent == null) {
        parent = new RootContext();
    }
    AttributesContext httpRequestContext = new AttributesContext(new SessionContext(parent, mock(Session.class)));
    HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
    httpRequestContext.getAttributes().put(HttpServletRequest.class.getName(), httpServletRequest);
    return new RequestAuditContext(httpRequestContext);
}
Also used : RootContext(org.forgerock.services.context.RootContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) AttributesContext(org.forgerock.services.context.AttributesContext) SessionContext(org.forgerock.http.session.SessionContext)

Example 2 with RootContext

use of org.forgerock.services.context.RootContext 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 RootContext

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

the class RealmContextTest method getRelativeRealmShouldReturnRootRealmWhenNotSet.

@Test
public void getRelativeRealmShouldReturnRootRealmWhenNotSet() {
    //Given
    RealmContext context = new RealmContext(new RootContext());
    //When
    String relativeRealm = context.getRelativeRealm();
    //Then
    assertThat(relativeRealm).isEqualTo("/");
}
Also used : RootContext(org.forgerock.services.context.RootContext) Test(org.testng.annotations.Test)

Example 4 with RootContext

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

the class RealmContextTest method staticHelperMethodReturnsAppropriateRealm.

@Test
public void staticHelperMethodReturnsAppropriateRealm() {
    //Given
    RealmContext context = new RealmContext(new RootContext());
    context.setSubRealm("SUB_REALM", "/some/realm");
    //When
    String realm = RealmContext.getRealm(context);
    //Then
    assertThat(realm).isEqualTo("/some/realm");
}
Also used : RootContext(org.forgerock.services.context.RootContext) Test(org.testng.annotations.Test)

Example 5 with RootContext

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

the class UmaResourceSetRegistrationHook method createAdminContext.

/**
     * Used to create a context for deleting policies. If this is being called, we know that the user has the right
     * to delete the policies.
     * @param realm The realm to delete the policies in.
     * @param resourceOwnerId The owner of the ResourceSet that the policies are for.
     * @return The generated context.
     */
private Context createAdminContext(String realm, String resourceOwnerId) {
    RealmContext realmContext = new RealmContext(new RootContext());
    realmContext.setSubRealm(realm, realm);
    SubjectContext subjectContext = new AdminSubjectContext(logger, sessionCache, realmContext);
    Map<String, String> templateVariables = new HashMap<>();
    templateVariables.put("user", resourceOwnerId);
    UriRouterContext routerContext = new UriRouterContext(subjectContext, "", "", templateVariables);
    return routerContext;
}
Also used : RootContext(org.forgerock.services.context.RootContext) RealmContext(org.forgerock.openam.rest.RealmContext) AdminSubjectContext(org.forgerock.openam.rest.resource.AdminSubjectContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) HashMap(java.util.HashMap) AdminSubjectContext(org.forgerock.openam.rest.resource.AdminSubjectContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext)

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