Java Code Examples for org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#setSequenceConfig()
The following examples show how to use
org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#setSequenceConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsAuthenticationContextTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void setupAuthContextWithStepData(AuthenticationContext context, AuthenticatedUser authenticatedUser) { SequenceConfig sequenceConfig = new SequenceConfig(); Map<Integer, StepConfig> stepConfigMap = new HashMap<>(); StepConfig stepConfig = new StepConfig(); stepConfig.setOrder(1); stepConfig.setAuthenticatedIdP(TEST_IDP); stepConfigMap.put(1, stepConfig); sequenceConfig.setStepMap(stepConfigMap); AuthenticationGraph authenticationGraph = new AuthenticationGraph(); authenticationGraph.setStepMap(stepConfigMap); sequenceConfig.setAuthenticationGraph(authenticationGraph); context.setSequenceConfig(sequenceConfig); Map<String, AuthenticatedIdPData> idPDataMap = new HashMap<>(); AuthenticatedIdPData idPData = new AuthenticatedIdPData(); idPData.setUser(authenticatedUser); idPData.setIdpName(TEST_IDP); idPDataMap.put(TEST_IDP, idPData); context.setCurrentAuthenticatedIdPs(idPDataMap); }
Example 2
Source File: DefaultAuthenticationRequestHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test public void testHandleDenyFromLoginPage() throws Exception { AuthenticationContext context = spy(new AuthenticationContext()); context.setSequenceConfig(new SequenceConfig()); DefaultAuthenticationRequestHandler authenticationRequestHandler = spy(new DefaultAuthenticationRequestHandler()); // mock the conclude flow doNothing().when(authenticationRequestHandler).concludeFlow(request, response, context); doNothing().when(authenticationRequestHandler).sendResponse(request, response, context); // mock the context to show that flow is returning back from login page when(context.isReturning()).thenReturn(true); doReturn("DENY").when(request).getParameter(FrameworkConstants.RequestParams.DENY); authenticationRequestHandler.handle(request, response, context); assertFalse(context.isRequestAuthenticated()); }
Example 3
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private AuthenticationContext processAndGetAuthenticationContext(String[] acrArray, ServiceProvider sp1) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, FrameworkException { AuthenticationContext context = getAuthenticationContext(sp1); if (acrArray != null) { for (String acr : acrArray) { context.addRequestedAcr(acr); } } SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = mock(HttpServletRequest.class); addMockAttributes(req); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, context); return context; }
Example 4
Source File: DefaultAuthenticationRequestHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test(dataProvider = "sendResponseDataProvider") public void testSendResponse(boolean isRequestAuthenticated, boolean isRememberMe, String callerPath, String sessionDataKey, String expectedRedirectUrl) throws Exception { AuthenticationContext context = new AuthenticationContext(); context.setRequestAuthenticated(isRequestAuthenticated); context.setRememberMe(isRememberMe); context.setCallerPath(callerPath); context.setCallerSessionKey(sessionDataKey); SequenceConfig sequenceConfig = spy(new SequenceConfig()); context.setSequenceConfig(sequenceConfig); DefaultAuthenticationRequestHandler requestHandler = spy(new DefaultAuthenticationRequestHandler()); doNothing().when(requestHandler).populateErrorInformation(request, response, context); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); requestHandler.sendResponse(request, response, context); verify(response).sendRedirect(captor.capture()); assertEquals(captor.getValue(), expectedRedirectUrl); }
Example 5
Source File: DefaultAuthenticationRequestHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = FrameworkException.class) public void testSendResponseException() throws Exception { AuthenticationContext context = new AuthenticationContext(); context.setRequestAuthenticated(true); context.setRememberMe(true); context.setCallerPath("/samlsso"); String sessionDataKey = UUID.randomUUID().toString(); context.setCallerSessionKey(sessionDataKey); SequenceConfig sequenceConfig = spy(new SequenceConfig()); context.setSequenceConfig(sequenceConfig); doThrow(new IOException()).when(response).sendRedirect(anyString()); authenticationRequestHandler.sendResponse(request, response, context); }
Example 6
Source File: DefaultRequestPathBasedSequenceHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@BeforeClass public void setUp() throws Exception { initMocks(this); requestPathBasedSequenceHandler = new DefaultRequestPathBasedSequenceHandler(); // Mock authentication context and sequence config for request path authentication context = new AuthenticationContext(); authenticatorConfig = spy(new AuthenticatorConfig()); doReturn(requestPathAuthenticator).when(authenticatorConfig).getApplicationAuthenticator(); sequenceConfig = spy(new SequenceConfig()); doReturn(Arrays.asList(new AuthenticatorConfig[]{authenticatorConfig})) .when(sequenceConfig).getReqPathAuthenticators(); context.setSequenceConfig(sequenceConfig); }
Example 7
Source File: GraphBasedSequenceHandlerNoJsTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test(dataProvider = "noJsDataProvider") public void testHandleStaticSequence(String spFileName, int authHistoryCount) throws Exception { ServiceProvider sp1 = getTestServiceProvider(spFileName); AuthenticationContext context = getAuthenticationContext(sp1); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = mock(HttpServletRequest.class); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, context); List<AuthHistory> authHistories = context.getAuthenticationStepHistory(); assertNotNull(authHistories); assertEquals(authHistories.size(), authHistoryCount); }
Example 8
Source File: JITProvisioningPostAuthenticationHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * To get the authentication context and to call the handle method of the PostJitProvisioningHandler. * * @param sp1 Service Provider * @return relevant authentication context. * @throws FrameworkException Framwork Exception. */ private AuthenticationContext processAndGetAuthenticationContext(ServiceProvider sp1, boolean withAuthenticatedUser, boolean isFederated) throws FrameworkException { AuthenticationContext context = getAuthenticationContext(sp1); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); context.setProperty(FrameworkConstants.STEP_BASED_SEQUENCE_HANDLER_TRIGGERED, true); ApplicationAuthenticator applicationAuthenticator = mock(ApplicationAuthenticator.class); if (isFederated) { applicationAuthenticator = mock(FederatedApplicationAuthenticator.class); } when(applicationAuthenticator.getName()).thenReturn("Authenticator1"); if (withAuthenticatedUser) { AuthenticatedUser authenticatedUser = new AuthenticatedUser(); authenticatedUser.setUserName("test"); authenticatedUser.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); authenticatedUser.setAuthenticatedSubjectIdentifier("test"); sequenceConfig.setAuthenticatedUser(authenticatedUser); AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig(); authenticatorConfig.setApplicationAuthenticator(applicationAuthenticator); for (Map.Entry<Integer, StepConfig> entry : sequenceConfig.getStepMap().entrySet()) { StepConfig stepConfig = entry.getValue(); stepConfig.setAuthenticatedAutenticator(authenticatorConfig); stepConfig.setAuthenticatedUser(authenticatedUser); } context.setSequenceConfig(sequenceConfig); } UserCoreUtil.setDomainInThreadLocal("test_domain"); return context; }
Example 9
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Test public void testHandleDynamicJavascriptSerialization() throws Exception { JsFunctionRegistry jsFunctionRegistrar = new JsFunctionRegistryImpl(); FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar); jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1", (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1); ServiceProvider sp1 = getTestServiceProvider("js-sp-dynamic-1.xml"); AuthenticationContext context = getAuthenticationContext(sp1); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); byte[] serialized = SerializationUtils.serialize(context); AuthenticationContext deseralizedContext = (AuthenticationContext) SerializationUtils.deserialize(serialized); assertNotNull(deseralizedContext); HttpServletRequest req = mock(HttpServletRequest.class); addMockAttributes(req); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, deseralizedContext); List<AuthHistory> authHistories = deseralizedContext.getAuthenticationStepHistory(); assertNotNull(authHistories); assertEquals(3, authHistories.size()); assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicMockAuthenticator"); assertEquals(authHistories.get(1).getAuthenticatorName(), "HwkMockAuthenticator"); assertEquals(authHistories.get(2).getAuthenticatorName(), "FptMockAuthenticator"); }
Example 10
Source File: GraphBasedSequenceHandlerExceptionRetryTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public void testExceptionRetry() throws Exception { JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl(); FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar); LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl(); CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl); FrameworkServiceDataHolder.getInstance().getAuthenticators().add( new FailingMockAuthenticator("FailingMockAuthenticator")); FrameworkServiceDataHolder.getInstance().setLongWaitStatusStoreService(new LongWaitStatusStoreService (cacheBackedDao, 5000)); jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "hasAnyOfTheRoles", (BiFunction<JsAuthenticatedUser, List<String>, Boolean>) this::hasAnyOfTheRolesFunction); ServiceProvider sp1 = getTestServiceProvider("js-sp-exception-retry.xml"); AuthenticationContext context = getAuthenticationContext(sp1); context.setSessionIdentifier("1234"); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = createMockHttpServletRequest(); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, context); Integer currentAttempts = (Integer) context.getProperties().get(CONTEXT_ATTRIBUTE_NAME_CURRENT_FAIL_TRIES); Assert.assertNotNull(currentAttempts); Assert.assertEquals(currentAttempts.intValue(), 2); }
Example 11
Source File: GraphBasedSequenceHandlerLongWaitTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Test public void testHandleLongWait() throws Exception { JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl(); FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar); LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl(); CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl); FrameworkServiceDataHolder.getInstance().setLongWaitStatusStoreService(new LongWaitStatusStoreService (cacheBackedDao, 5000)); jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "testLongWaitCall", new AsyncAnalyticsCbFunctionImpl()); ServiceProvider sp1 = getTestServiceProvider("js-sp-longwait-1.xml"); AuthenticationContext context = getAuthenticationContext(sp1); context.setSessionIdentifier("1234"); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = createMockHttpServletRequest(); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, context); }
Example 12
Source File: GraphBasedSequenceHandlerAcrTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Test(dataProvider = "staticAcrDataProvider") public void testHandleStaticJavascriptAcr(String spFileName, String[] acrArray, int authHistoryCount) throws Exception { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); ServiceProvider sp1 = getTestServiceProvider(spFileName); AuthenticationContext context = getAuthenticationContext(sp1); if (acrArray != null) { for (String acr : acrArray) { context.addRequestedAcr(acr); } } SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = mock(HttpServletRequest.class); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, context); List<AuthHistory> authHistories = context.getAuthenticationStepHistory(); assertNotNull(authHistories); assertEquals(authHistories.size(), authHistoryCount); }
Example 13
Source File: DefaultAuthenticationRequestHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Test(dataProvider = "rememberMeParamProvider") public void testHandleRememberMeOptionFromLoginPage(String rememberMeParam, boolean expectedResult) throws Exception { doReturn(rememberMeParam).when(request).getParameter(FrameworkConstants.RequestParams.REMEMBER_ME); AuthenticationContext context = spy(new AuthenticationContext()); SequenceConfig sequenceConfig = spy(new SequenceConfig()); when(sequenceConfig.isCompleted()).thenReturn(true); ServiceProvider serviceProvider = spy(new ServiceProvider()); LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = spy(new LocalAndOutboundAuthenticationConfig()); when(localAndOutboundAuthenticationConfig.getAuthenticationType()).thenReturn(ApplicationConstants .AUTH_TYPE_LOCAL); serviceProvider.setLocalAndOutBoundAuthenticationConfig(localAndOutboundAuthenticationConfig); ApplicationConfig applicationConfig = spy(new ApplicationConfig(serviceProvider)); sequenceConfig.setApplicationConfig(applicationConfig); context.setSequenceConfig(sequenceConfig); // mock the context to show that flow is returning back from login page when(context.isReturning()).thenReturn(true); when(context.getCurrentStep()).thenReturn(0); DefaultAuthenticationRequestHandler authenticationRequestHandler = spy(new DefaultAuthenticationRequestHandler()); // Mock conclude flow and post authentication flows to isolate remember me option doNothing().when(authenticationRequestHandler).concludeFlow(request, response, context); authenticationRequestHandler.handle(request, response, context); assertEquals(context.isRememberMe(), expectedResult); }
Example 14
Source File: GraphBasedSequenceHandlerAcrTest.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
@Test(expectedExceptions = FrameworkException.class) public void testHandleIncorrectFunctionJavascriptAcr() throws Exception { ServiceProvider sp1 = getTestServiceProvider("incorrect-function-js-sp-1.xml"); AuthenticationContext context = getAuthenticationContext(sp1); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = mock(HttpServletRequest.class); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, context); }
Example 15
Source File: GraphBasedSequenceHandlerAcrTest.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
@Test(expectedExceptions = FrameworkException.class) public void testHandleIncorrectJavascriptAcr() throws Exception { ServiceProvider sp1 = getTestServiceProvider("incorrect-js-sp-1.xml"); AuthenticationContext context = getAuthenticationContext(sp1); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = mock(HttpServletRequest.class); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); graphBasedSequenceHandler.handle(req, resp, context); }
Example 16
Source File: DefaultRequestPathBasedSequenceHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
@Test(dataProvider = "getPostAuthenticationData") public void testHandlePostAuthentication(Map<String, String> unfilteredLocalClaims, Map<String, String> mappedAttributes, String subjectClaimUri, String expectedSubjectIdentifier) throws Exception { requestPathBasedSequenceHandler = spy(new DefaultRequestPathBasedSequenceHandler()); doReturn(mappedAttributes) .when(requestPathBasedSequenceHandler) .handleClaimMappings(any(AuthenticationContext.class)); doReturn("spRole1,spRole2") .when(requestPathBasedSequenceHandler) .getServiceProviderMappedUserRoles(any(SequenceConfig.class), anyList()); ServiceProvider serviceProvider = new ServiceProvider(); ApplicationConfig applicationConfig = spy(new ApplicationConfig(serviceProvider)); when(applicationConfig.getSubjectClaimUri()).thenReturn(subjectClaimUri); SequenceConfig sequenceConfig = new SequenceConfig(); sequenceConfig.setApplicationConfig(applicationConfig); AuthenticatedUser authenticatedUser = new AuthenticatedUser(); authenticatedUser.setUserName("alice"); sequenceConfig.setAuthenticatedUser(new AuthenticatedUser()); AuthenticationContext context = new AuthenticationContext(); context.setProperty(FrameworkConstants.UNFILTERED_LOCAL_CLAIM_VALUES, unfilteredLocalClaims); context.setSequenceConfig(sequenceConfig); ApplicationAuthenticator applicationAuthenticator = mock(ApplicationAuthenticator.class); when(applicationAuthenticator.getName()).thenReturn("Authenticator1"); AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig(); authenticatorConfig.setApplicationAuthenticator(applicationAuthenticator); AuthenticatedIdPData idPData = new AuthenticatedIdPData(); idPData.setIdpName("LOCAL"); idPData.setAuthenticator(authenticatorConfig); mockStatic(FrameworkUtils.class); when(FrameworkUtils.getMultiAttributeSeparator()).thenReturn(","); requestPathBasedSequenceHandler.handlePostAuthentication(request, response, context, idPData); assertNotNull(context.getSequenceConfig().getAuthenticatedUser()); assertEquals(context.getSequenceConfig().getAuthenticatedUser().getAuthenticatedSubjectIdentifier(), expectedSubjectIdentifier); }
Example 17
Source File: GraphBasedSequenceHandlerClaimMappingsTest.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
public void testHandleClaimHandling() throws Exception { ServiceProvider sp1 = getTestServiceProvider("js-sp-4-claim.xml"); AuthenticationContext context = getAuthenticationContext(sp1); SequenceConfig sequenceConfig = configurationLoader .getSequenceConfig(context, Collections.emptyMap(), sp1); context.setSequenceConfig(sequenceConfig); HttpServletRequest req = createMockHttpServletRequest(); HttpServletResponse resp = mock(HttpServletResponse.class); UserCoreUtil.setDomainInThreadLocal("test_domain"); RealmService currentRealmService = FrameworkServiceDataHolder.getInstance().getRealmService(); RealmService mockRealmService = mock(RealmService.class); UserRealm mockUserRealm = mock(UserRealm.class); UserStoreManager mockUserStoreManager = mock(UserStoreManager.class); when(mockRealmService.getTenantUserRealm(anyInt())).thenReturn(mockUserRealm); when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager); FrameworkServiceDataHolder.getInstance().setRealmService(mockRealmService); when(mockUserStoreManager.getUserClaimValues(anyString(), eq(new String[]{"http://wso2.org/claims/givenname"}) , anyString())).thenReturn(Collections.singletonMap("http://wso2.org/claims/givenname", "Test")); when(mockUserStoreManager.getUserClaimValues(anyString(), eq(new String[]{"http://wso2.org/claims/lastname"}) , anyString())).thenReturn(Collections.singletonMap("http://wso2.org/claims/lastname", "User")); final String[] claimValue = {null}; doAnswer((Answer<Void>) invocationOnMock -> { Object[] arguments = invocationOnMock.getArguments(); claimValue[0] = ((Map<String, String>) arguments[1]).get("http://wso2.org/claims/displayName"); return null; }).when(mockUserStoreManager).setUserClaimValues(anyString(), anyMap(), anyString()); graphBasedSequenceHandler.handle(req, resp, context); FrameworkServiceDataHolder.getInstance().setRealmService(currentRealmService); assertEquals(claimValue[0], "Test User by Javascript"); }
Example 18
Source File: DefaultAuthenticationRequestHandlerTest.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
private void addSequence(AuthenticationContext context, boolean isCompleted) { SequenceConfig sequenceConfig = new SequenceConfig(); sequenceConfig.setCompleted(isCompleted); context.setSequenceConfig(sequenceConfig); }
Example 19
Source File: DefaultRequestCoordinator.java From carbon-identity with Apache License 2.0 | 4 votes |
protected void findPreviousAuthenticatedSession(HttpServletRequest request, AuthenticationContext context) throws FrameworkException { // Get service provider chain SequenceConfig sequenceConfig = ConfigurationFacade.getInstance().getSequenceConfig( context.getRequestType(), request.getParameter(FrameworkConstants.RequestParams.ISSUER), context.getTenantDomain()); Cookie cookie = FrameworkUtils.getAuthCookie(request); // if cookie exists user has previously authenticated if (cookie != null) { if (log.isDebugEnabled()) { log.debug(FrameworkConstants.COMMONAUTH_COOKIE + " cookie is available with the value: " + cookie.getValue()); } // get the authentication details from the cache SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(cookie .getValue()); if (sessionContext != null) { context.setSessionIdentifier(cookie.getValue()); String appName = sequenceConfig.getApplicationConfig().getApplicationName(); if (log.isDebugEnabled()) { log.debug("Service Provider is: " + appName); } SequenceConfig previousAuthenticatedSeq = sessionContext .getAuthenticatedSequences().get(appName); if (previousAuthenticatedSeq != null) { if (log.isDebugEnabled()) { log.debug("A previously authenticated sequence found for the SP: " + appName); } context.setPreviousSessionFound(true); sequenceConfig = previousAuthenticatedSeq; AuthenticatedUser authenticatedUser = sequenceConfig.getAuthenticatedUser(); String authenticatedUserTenantDomain = sequenceConfig.getAuthenticatedUser().getTenantDomain(); if (authenticatedUser != null) { // set the user for the current authentication/logout flow context.setSubject(authenticatedUser); if (log.isDebugEnabled()) { log.debug("Already authenticated by username: " + authenticatedUser.getAuthenticatedSubjectIdentifier()); } if (authenticatedUserTenantDomain != null) { // set the user tenant domain for the current authentication/logout flow context.setProperty("user-tenant-domain", authenticatedUserTenantDomain); if (log.isDebugEnabled()) { log.debug("Authenticated user tenant domain: " + authenticatedUserTenantDomain); } } } } context.setPreviousAuthenticatedIdPs(sessionContext.getAuthenticatedIdPs()); } else { if (log.isDebugEnabled()) { log.debug("Failed to find the SessionContext from the cache. Possible cache timeout."); } } } context.setServiceProviderName(sequenceConfig.getApplicationConfig().getApplicationName()); // set the sequence for the current authentication/logout flow context.setSequenceConfig(sequenceConfig); }
Example 20
Source File: PostAuthenticationMgtServiceTest.java From carbon-identity-framework with Apache License 2.0 | 3 votes |
private void addSequence(AuthenticationContext context, boolean isCompleted) { SequenceConfig sequenceConfig = new SequenceConfig(); sequenceConfig.setCompleted(isCompleted); context.setSequenceConfig(sequenceConfig); }