use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeModuleWithSessionUpgradeButNotRequired.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeModuleWithSessionUpgradeButNotRequired() 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";
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(false), 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);
//When
LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
//Then
assertThat(loginProcess.isSuccessful()).isTrue();
verify(authContextLocalWrapper, never()).login();
assertNotNull(loginProcess);
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForSubsequentRequestWithAuthIndexTypeCompositeAndSessionUpgradeSet.
@Test
public void shouldGetLoginProcessForSubsequentRequestWithAuthIndexTypeCompositeAndSessionUpgradeSet() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = "SESSION_ID";
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(false), 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.COMPOSITE_ADVICE, "INDEX_VALUE");
assertNotNull(loginProcess);
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class AuthIdHelperTest method shouldCreateAuthIdIncludingAuthIndexTypeAndValue.
@Test
public void shouldCreateAuthIdIncludingAuthIndexTypeAndValue() throws SignatureException, SMSException, SSOException, RestAuthException {
//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.SERVICE);
given(loginConfiguration.getIndexValue()).willReturn("INDEX_VALUE");
mockGetSigningKey("ORG_DN", false);
//When
String authId = authIdHelper.createAuthId(loginConfiguration, authContext);
//Then
assertNotNull(authId);
verify(jwsHeaderBuilder).alg(JwsAlgorithm.HS256);
verify(claimsSetBuilder).claim(eq("otk"), anyString());
ArgumentCaptor<Map> argumentCaptor = ArgumentCaptor.forClass(Map.class);
verify(claimsSetBuilder).claims(argumentCaptor.capture());
Map jwtValues = argumentCaptor.getValue();
assertTrue(jwtValues.containsKey("realm"));
assertTrue(jwtValues.containsValue("ORG_DN"));
assertTrue(jwtValues.containsKey("sessionId"));
assertTrue(jwtValues.containsValue("SESSION_ID"));
assertTrue(jwtValues.containsKey("authIndexType"));
assertTrue(jwtValues.containsValue(AuthIndexType.SERVICE.getIndexType().toString()));
assertTrue(jwtValues.containsKey("authIndexValue"));
assertTrue(jwtValues.containsValue("INDEX_VALUE"));
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class AuthIdHelperTest method shouldCreateAuthId.
@Test
public void shouldCreateAuthId() throws SignatureException, SMSException, SSOException, RestAuthException {
//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", false);
//When
String authId = authIdHelper.createAuthId(loginConfiguration, authContext);
//Then
assertNotNull(authId);
verify(jwsHeaderBuilder).alg(JwsAlgorithm.HS256);
verify(claimsSetBuilder).claim(eq("otk"), anyString());
ArgumentCaptor<Map> contentArgumentCaptor = ArgumentCaptor.forClass(Map.class);
verify(claimsSetBuilder).claims(contentArgumentCaptor.capture());
Map jwtContent = contentArgumentCaptor.getValue();
assertTrue(jwtContent.containsKey("realm"));
assertTrue(jwtContent.containsValue("ORG_DN"));
assertTrue(jwtContent.containsKey("sessionId"));
assertTrue(jwtContent.containsValue("SESSION_ID"));
assertFalse(jwtContent.containsKey("authIndexType"));
assertFalse(jwtContent.containsKey("authIndexValue"));
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class AuthIdHelperTest method shouldThrowSMSExceptionWhenFailToGetOrgConfig.
@Test
public void shouldThrowSMSExceptionWhenFailToGetOrgConfig() throws SSOException, SMSException, SignatureException {
//Given
LoginConfiguration loginConfiguration = mock(LoginConfiguration.class);
AuthContextLocalWrapper authContext = mock(AuthContextLocalWrapper.class);
given(coreServicesWrapper.getServiceConfigManager("iPlanetAMAuthService", null)).willThrow(SMSException.class);
//When
boolean exceptionCaught = false;
RestAuthException exception = null;
try {
authIdHelper.createAuthId(loginConfiguration, authContext);
fail();
} catch (RestAuthException e) {
exceptionCaught = true;
exception = e;
}
//Then
assertTrue(exceptionCaught);
assertEquals(exception.getStatusCode(), 500);
}
Aggregations