Search in sources :

Example 6 with AuthContextLocalWrapper

use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.

the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeNoneWithSessionUpgradeButNotRequired.

@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeNoneWithSessionUpgradeButNotRequired() throws AuthException, AuthLoginException, SSOException, RestAuthException {
    //Given
    LoginConfiguration loginConfiguration = new LoginConfiguration();
    HttpServletRequest request = mock(HttpServletRequest.class);
    String sessionId = null;
    AuthIndexType authIndexType = AuthIndexType.NONE;
    String authIndexValue = "INDEX_VALUE";
    String ssoTokenId = "SSO_TOKEN_ID";
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    SSOToken ssoToken = mock(SSOToken.class);
    loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
    given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
    given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), eq(false))).willReturn(authContextLocalWrapper);
    given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
    given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
    //When
    LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
    //Then
    assertThat(loginProcess.isSuccessful()).isTrue();
    verify(authContextLocalWrapper, never()).login();
    assertNotNull(loginProcess);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 7 with AuthContextLocalWrapper

use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.

the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexType.

@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexType() throws AuthException, AuthLoginException, SSOException, RestAuthException {
    //Given
    LoginConfiguration loginConfiguration = new LoginConfiguration();
    HttpServletRequest request = mock(HttpServletRequest.class);
    String sessionId = null;
    AuthIndexType authIndexType = AuthIndexType.MODULE;
    String authIndexValue = "INDEX_VALUE";
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue);
    given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
    given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), eq(false))).willReturn(authContextLocalWrapper);
    given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
    //When
    LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
    //Then
    verify(authContextLocalWrapper).login(AuthContext.IndexType.MODULE_INSTANCE, "INDEX_VALUE");
    verify(coreServicesWrapper).getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), eq(false));
    assertNotNull(loginProcess);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) Test(org.testng.annotations.Test)

Example 8 with AuthContextLocalWrapper

use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.

the class LoginAuthenticatorTest method shouldGetLoginProcessForSubsequentRequest.

@Test
public void shouldGetLoginProcessForSubsequentRequest() throws AuthException, AuthLoginException, SSOException, IdRepoException, RestAuthException {
    //Given
    LoginConfiguration loginConfiguration = new LoginConfiguration();
    HttpServletRequest request = mock(HttpServletRequest.class);
    String sessionId = "SESSION_ID";
    AuthIndexType authIndexType = AuthIndexType.NONE;
    String authIndexValue = "INDEX_VALUE";
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue);
    given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
    given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), eq(false))).willReturn(authContextLocalWrapper);
    given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(false);
    //When
    LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
    //Then
    verifyZeroInteractions(authContextLocalWrapper);
    assertNotNull(loginProcess);
    verify(coreServicesWrapper).getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), eq(false));
    verify(coreServicesWrapper).isNewRequest(authContextLocalWrapper);
    verify(coreServicesWrapper).getDomainNameByRequest(request);
    verify(coreServicesWrapper).isOrganizationActive("ORG_DN");
    verify(coreServicesWrapper).getExistingValidSSOToken(Matchers.<SessionID>anyObject());
    verifyNoMoreInteractions(coreServicesWrapper);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) Test(org.testng.annotations.Test)

Example 9 with AuthContextLocalWrapper

use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.

the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeUserWithSessionUpgrade.

@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeUserWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
    //Given
    LoginConfiguration loginConfiguration = new LoginConfiguration();
    HttpServletRequest request = mock(HttpServletRequest.class);
    String sessionId = null;
    AuthIndexType authIndexType = AuthIndexType.USER;
    String authIndexValue = "INDEX_VALUE_NEW";
    String ssoTokenId = "SSO_TOKEN_ID";
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    SSOToken ssoToken = mock(SSOToken.class);
    loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
    given(ssoToken.getProperty("UserToken")).willReturn("INDEX_VALUE");
    given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
    given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(true), eq(false))).willReturn(authContextLocalWrapper);
    given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
    given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
    given(authContextLocalWrapper.isSessionUpgrade()).willReturn(true);
    //When
    LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
    //Then
    verify(authContextLocalWrapper).login(AuthContext.IndexType.USER, "INDEX_VALUE_NEW");
    assertNotNull(loginProcess);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 10 with AuthContextLocalWrapper

use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.

the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeRoleWithSessionUpgrade.

@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeRoleWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
    //Given
    LoginConfiguration loginConfiguration = new LoginConfiguration();
    HttpServletRequest request = mock(HttpServletRequest.class);
    String sessionId = null;
    AuthIndexType authIndexType = AuthIndexType.ROLE;
    String authIndexValue = "INDEX_VALUE_NEW";
    String ssoTokenId = "SSO_TOKEN_ID";
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    SSOToken ssoToken = mock(SSOToken.class);
    loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
    given(ssoToken.getProperty("Role")).willReturn("INDEX_VALUE");
    given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
    given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(true), eq(false))).willReturn(authContextLocalWrapper);
    given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
    given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
    given(coreServicesWrapper.doesValueContainKey(anyString(), anyString())).willReturn(false);
    given(coreServicesWrapper.doesValueContainKey("INDEX_VALUE", "INDEX_VALUE")).willReturn(true);
    given(authContextLocalWrapper.isSessionUpgrade()).willReturn(true);
    //When
    LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
    //Then
    verify(authContextLocalWrapper).login(AuthContext.IndexType.ROLE, "INDEX_VALUE_NEW");
    assertNotNull(loginProcess);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Aggregations

AuthContextLocalWrapper (org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper)30 Test (org.testng.annotations.Test)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)24 SessionID (com.iplanet.dpro.session.SessionID)17 SSOToken (com.iplanet.sso.SSOToken)17 LoginConfiguration (org.forgerock.openam.core.rest.authn.core.LoginConfiguration)8 LoginProcess (org.forgerock.openam.core.rest.authn.core.LoginProcess)7 JsonValue (org.forgerock.json.JsonValue)5 HashMap (java.util.HashMap)4 SSOTokenID (com.iplanet.sso.SSOTokenID)3 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)3 Map (java.util.Map)3 Callback (javax.security.auth.callback.Callback)3 RestAuthException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthException)3 Set (java.util.Set)1 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)1 JwtClaimsSet (org.forgerock.json.jose.jwt.JwtClaimsSet)1 RestAuthErrorCodeException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthErrorCodeException)1 RestAuthResponseException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthResponseException)1