use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeModuleWithSessionUpgrade.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeModuleWithSessionUpgrade() 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_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("AuthType")).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.MODULE_INSTANCE, "INDEX_VALUE_NEW");
assertNotNull(loginProcess);
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeLevelWithSessionUpgrade.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeLevelWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = null;
AuthIndexType authIndexType = AuthIndexType.LEVEL;
String authIndexValue = "15";
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("AuthLevel")).willReturn("10");
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.LEVEL, "15");
assertNotNull(loginProcess);
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeCompositeWithSessionUpgrade.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeCompositeWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = null;
AuthIndexType authIndexType = AuthIndexType.COMPOSITE;
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(Matchers.<HttpServletRequest>anyObject())).willReturn("ORG_DN");
given(coreServicesWrapper.getAuthContext((HttpServletRequest) anyObject(), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(true), eq(false))).willReturn(authContextLocalWrapper);
given(authContextLocalWrapper.isSessionUpgrade()).willReturn(true);
given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
//When
LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
//Then
verify(authContextLocalWrapper).login(AuthContext.IndexType.COMPOSITE_ADVICE, "INDEX_VALUE");
assertNotNull(loginProcess);
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithResourceAuthIndexType.
@Test
public void shouldGetLoginProcessForInitialRequestWithResourceAuthIndexType() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = null;
AuthIndexType authIndexType = AuthIndexType.RESOURCE;
String authIndexValue = "INDEX_VALUE";
AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
Map<String, Set<String>> envMap = new HashMap<String, Set<String>>();
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);
given(coreServicesWrapper.getEnvMap(request)).willReturn(envMap);
//When
LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
//Then
verify(authContextLocalWrapper).login(AuthContext.IndexType.RESOURCE, "INDEX_VALUE", envMap, null);
verify(coreServicesWrapper).getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), eq(false));
assertNotNull(loginProcess);
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class AuthIdHelperTest method shouldThrowExceptionWhenGeneratingAuthIdAndKeyAliasIsNull.
@Test
public void shouldThrowExceptionWhenGeneratingAuthIdAndKeyAliasIsNull() throws SSOException, SMSException, SignatureException {
//Given
LoginConfiguration loginConfiguration = mock(LoginConfiguration.class);
AuthContextLocalWrapper authContext = mock(AuthContextLocalWrapper.class);
given(authContext.getOrgDN()).willReturn("ORG_DN");
given(authContext.getSessionID()).willReturn(new SessionID("SESSION_ID"));
given(loginConfiguration.getIndexType()).willReturn(AuthIndexType.NONE);
given(loginConfiguration.getIndexValue()).willReturn(null);
mockGetSigningKey("ORG_DN", true);
//When
boolean exceptionCaught = false;
try {
authIdHelper.createAuthId(loginConfiguration, authContext);
fail();
} catch (RestAuthException e) {
exceptionCaught = true;
}
//Then
assertTrue(exceptionCaught);
}
Aggregations