Search in sources :

Example 1 with SSOPrincipal

use of com.iplanet.sso.providers.dpro.SSOPrincipal 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 2 with SSOPrincipal

use of com.iplanet.sso.providers.dpro.SSOPrincipal in project OpenAM by OpenRock.

the class StatelessSSOTokenTest method shouldReturnCorrectSSOPrincipal.

@Test
public void shouldReturnCorrectSSOPrincipal() throws Exception {
    // Given
    String name = "fred";
    given(mockSession.getProperty(ISAuthConstants.PRINCIPAL)).willReturn(name);
    // When
    Principal result = statelessSSOToken.getPrincipal();
    // Then
    assertThat(result).isInstanceOf(SSOPrincipal.class).isEqualTo(new SSOPrincipal(name));
}
Also used : SSOPrincipal(com.iplanet.sso.providers.dpro.SSOPrincipal) SSOPrincipal(com.iplanet.sso.providers.dpro.SSOPrincipal) Principal(java.security.Principal) Test(org.testng.annotations.Test)

Aggregations

SSOPrincipal (com.iplanet.sso.providers.dpro.SSOPrincipal)2 Test (org.testng.annotations.Test)2 SSOToken (com.iplanet.sso.SSOToken)1 SSOTokenID (com.iplanet.sso.SSOTokenID)1 Principal (java.security.Principal)1 Connection (org.forgerock.json.resource.Connection)1 ReadRequest (org.forgerock.json.resource.ReadRequest)1 Context (org.forgerock.services.context.Context)1 RootContext (org.forgerock.services.context.RootContext)1 SecurityContext (org.forgerock.services.context.SecurityContext)1