Search in sources :

Example 1 with SecurityContext

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

the class SessionResourceTest method actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid.

@Test
public void actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid() throws SSOException {
    //Given
    cookieResponse = "SSO_TOKEN_ID";
    final AttributesContext attrContext = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
    final AdviceContext adviceContext = new AdviceContext(attrContext, Collections.<String>emptySet());
    final SecurityContext securityContext = new SecurityContext(adviceContext, null, null);
    final Context context = ClientContext.newInternalClientContext(new SSOTokenContext(mock(Debug.class), null, securityContext));
    final ActionRequest request = mock(ActionRequest.class);
    final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
    given(request.getAction()).willReturn(LOGOUT_ACTION_ID);
    given(authUtilsWrapper.logout(ssoTokenId.toString(), null, null)).willReturn(true);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
    //Then
    assertThat(promise).succeeded().withContent().stringAt("result").isEqualTo("Successfully logged out");
}
Also used : RootContext(org.forgerock.services.context.RootContext) RootContext(org.forgerock.services.context.RootContext) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) 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) SSOTokenID(com.iplanet.sso.SSOTokenID) AttributesContext(org.forgerock.services.context.AttributesContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SecurityContext(org.forgerock.services.context.SecurityContext) SessionContext(org.forgerock.http.session.SessionContext) Test(org.testng.annotations.Test)

Example 2 with SecurityContext

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

the class AuditTestUtils method mockAuditContext.

public static Context mockAuditContext() throws Exception {
    final Context httpContext = new HttpContext(jsonFromFile("/org/forgerock/openam/rest/fluent/httpContext.json"), AbstractAuditFilterTest.class.getClassLoader());
    final Subject callerSubject = new Subject();
    final Context securityContext = new SecurityContext(httpContext, null, null);
    final Context subjectContext = new SSOTokenContext(mock(Debug.class), null, securityContext) {

        @Override
        public Subject getCallerSubject() {
            return callerSubject;
        }

        @Override
        public SSOToken getCallerSSOToken() {
            SSOToken token = mock(SSOToken.class);
            try {
                given(token.getProperty(Constants.AM_CTX_ID)).willReturn("TRACKING_ID");
                given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("USER_ID");
            } catch (SSOException e) {
            // won't happen - it's a mock
            }
            return token;
        }
    };
    final Context clientContext = ClientContext.newInternalClientContext(subjectContext);
    return new RequestAuditContext(new AuditInfoContext(clientContext, AuditConstants.Component.AUDIT));
}
Also used : SecurityContext(org.forgerock.services.context.SecurityContext) HttpContext(org.forgerock.json.resource.http.HttpContext) AuditInfoContext(org.forgerock.openam.rest.resource.AuditInfoContext) Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SecurityContext(org.forgerock.services.context.SecurityContext) SSOException(com.iplanet.sso.SSOException) AuditInfoContext(org.forgerock.openam.rest.resource.AuditInfoContext) Subject(javax.security.auth.Subject) Debug(com.sun.identity.shared.debug.Debug)

Example 3 with SecurityContext

use of org.forgerock.services.context.SecurityContext 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 4 with SecurityContext

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

the class ResourceTypesResourceTest method setUp.

@BeforeMethod
public void setUp() throws ResourceException {
    callerSubject = new Subject();
    // to mock the HTTP method, we need the following contexts
    Context httpContext = new HttpContext(json(object(field(HttpContext.ATTR_HEADERS, Collections.singletonMap("method", Arrays.asList("PUT"))), field(HttpContext.ATTR_PARAMETERS, Collections.emptyMap()))), null);
    Context securityContext = new SecurityContext(httpContext, null, null);
    Context subjectContext = new SSOTokenContext(mock(Debug.class), null, securityContext) {

        @Override
        public Subject getCallerSubject() {
            return callerSubject;
        }
    };
    RealmContext realmContext = new RealmContext(subjectContext);
    realmContext.setSubRealm("/", "/");
    mockServerContext = ClientContext.newInternalClientContext(realmContext);
    resourceTypeService = mock(MockResourceTypeService.class);
    Debug debug = mock(Debug.class);
    resourceTypesResource = new ResourceTypesResource(debug, new EntitlementsExceptionMappingHandler(EntitlementRestGuiceModule.getEntitlementsErrorHandlers()), resourceTypeService);
    rawData.put("name", Collections.singleton("myResourceType"));
    rawData.put("description", Collections.singleton("myResourceType"));
    rawData.put("realm", Collections.singleton("/"));
    rawData.put("actions", Collections.singleton("CREATE"));
    rawData.put("patterns", Collections.singleton("http://example.com:80/*"));
    rawData.put("creationDate", Collections.singleton(String.valueOf(new Date().getTime())));
    rawData.put("lastModifiedDate", Collections.singleton(String.valueOf(new Date().getTime())));
}
Also used : SecurityContext(org.forgerock.services.context.SecurityContext) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) HttpContext(org.forgerock.json.resource.http.HttpContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SecurityContext(org.forgerock.services.context.SecurityContext) Subject(javax.security.auth.Subject) Debug(com.sun.identity.shared.debug.Debug) Date(java.util.Date) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with SecurityContext

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

the class RestRouterIT method mockRequiredContexts.

private Context mockRequiredContexts() {
    final HttpContext httpContext = new HttpContext(json(object(field(HttpContext.ATTR_HEADERS, Collections.singletonMap("Accept-Language", Arrays.asList("en"))), field(HttpContext.ATTR_PARAMETERS, Collections.emptyMap()))), null);
    SecurityContext securityContext = new SecurityContext(mockContext(httpContext), null, null);
    return new SSOTokenContext(mock(Debug.class), null, securityContext) {

        @Override
        public Subject getCallerSubject() {
            return new Subject();
        }

        @Override
        public SSOToken getCallerSSOToken() {
            SSOToken token = mock(SSOToken.class);
            try {
                given(token.getProperty(Constants.AM_CTX_ID)).willReturn("TRACKING_ID");
                given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("USER_ID");
            } catch (SSOException e) {
            // won't happen - it's a mock
            }
            return token;
        }
    };
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SecurityContext(org.forgerock.services.context.SecurityContext) SSOException(com.iplanet.sso.SSOException) Debug(com.sun.identity.shared.debug.Debug) Subject(javax.security.auth.Subject)

Aggregations

SecurityContext (org.forgerock.services.context.SecurityContext)5 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)4 Context (org.forgerock.services.context.Context)4 SSOToken (com.iplanet.sso.SSOToken)3 Debug (com.sun.identity.shared.debug.Debug)3 Subject (javax.security.auth.Subject)3 HttpContext (org.forgerock.json.resource.http.HttpContext)3 ClientContext (org.forgerock.services.context.ClientContext)3 SSOException (com.iplanet.sso.SSOException)2 SSOTokenID (com.iplanet.sso.SSOTokenID)2 RealmContext (org.forgerock.openam.rest.RealmContext)2 RootContext (org.forgerock.services.context.RootContext)2 Test (org.testng.annotations.Test)2 SSOPrincipal (com.iplanet.sso.providers.dpro.SSOPrincipal)1 Date (java.util.Date)1 SessionContext (org.forgerock.http.session.SessionContext)1 Connection (org.forgerock.json.resource.Connection)1 ReadRequest (org.forgerock.json.resource.ReadRequest)1 AuditInfoContext (org.forgerock.openam.rest.resource.AuditInfoContext)1 AttributesContext (org.forgerock.services.context.AttributesContext)1