use of org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory in project carbon-identity-framework by wso2.
the class GraphBasedSequenceHandlerCustomFunctionsTest method testHandleDynamicJavascriptSerialization.
@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");
}
use of org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory in project carbon-identity-framework by wso2.
the class GraphBasedSequenceHandlerFailTest method handleFailMethodWithParamsOnFailTest.
@Test
public void handleFailMethodWithParamsOnFailTest() throws Exception {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
ServiceProvider sp1 = getTestServiceProvider("js-sp-fail-method-with-params-onFail.xml");
AuthenticationContext context = getAuthenticationContext(sp1);
SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1);
context.setSequenceConfig(sequenceConfig);
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS)).thenReturn(AuthenticatorFlowStatus.FAIL_COMPLETED);
HttpServletResponse resp = mock(HttpServletResponse.class);
UserCoreUtil.setDomainInThreadLocal("test_domain");
graphBasedSequenceHandler.handle(req, resp, context);
List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
assertNotNull(authHistories);
assertFalse(context.isRequestAuthenticated());
assertEquals(context.getProperty(FrameworkConstants.AUTH_ERROR_CODE), "access_denied");
assertEquals(context.getProperty(FrameworkConstants.AUTH_ERROR_MSG), "login could not be completed");
assertEquals(context.getProperty(FrameworkConstants.AUTH_ERROR_URI), "https://wso2.com/");
}
use of org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory in project carbon-identity-framework by wso2.
the class GraphBasedSequenceHandlerFailTest method handleFailMethodWithParamsTest.
@Test
public void handleFailMethodWithParamsTest() throws Exception {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
ServiceProvider sp1 = getTestServiceProvider("js-sp-fail-method-with-params-onSuccess.xml");
AuthenticationContext context = getAuthenticationContext(sp1);
SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1);
context.setSequenceConfig(sequenceConfig);
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS)).thenReturn(AuthenticatorFlowStatus.SUCCESS_COMPLETED);
HttpServletResponse resp = mock(HttpServletResponse.class);
UserCoreUtil.setDomainInThreadLocal("test_domain");
graphBasedSequenceHandler.handle(req, resp, context);
List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
assertNotNull(authHistories);
assertFalse(context.isRequestAuthenticated());
assertEquals(context.getProperty(FrameworkConstants.AUTH_ERROR_CODE), "access_denied");
assertEquals(context.getProperty(FrameworkConstants.AUTH_ERROR_MSG), "login could not be completed");
assertEquals(context.getProperty(FrameworkConstants.AUTH_ERROR_URI), "https://wso2.com/");
}
use of org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory in project carbon-identity-framework by wso2.
the class UserSessionStore method updateFederatedAuthSessionInfo.
/**
* Update session details of a given session context key to map the current session context key with
* the federated IdP's session ID.
*
* @param sessionContextKey Session Context Key.
* @param authHistory History of the authentication flow.
* @throws UserSessionException Error while storing session details.
*/
public void updateFederatedAuthSessionInfo(String sessionContextKey, AuthHistory authHistory) throws UserSessionException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(SQLQueries.SQL_UPDATE_FEDERATED_AUTH_SESSION_INFO, preparedStatement -> {
preparedStatement.setString(1, sessionContextKey);
preparedStatement.setString(2, authHistory.getIdpSessionIndex());
});
} catch (DataAccessException e) {
throw new UserSessionException("Error while updating " + sessionContextKey + " of session:" + authHistory.getIdpSessionIndex() + " in table " + IDN_AUTH_SESSION_META_DATA_TABLE + ".", e);
}
}
use of org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory in project carbon-identity-framework by wso2.
the class DefaultRequestPathBasedSequenceHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws FrameworkException {
if (log.isDebugEnabled()) {
log.debug("Executing the Request Path Authentication...");
}
SequenceConfig seqConfig = context.getSequenceConfig();
List<AuthenticatorConfig> reqPathAuthenticators = seqConfig.getReqPathAuthenticators();
for (AuthenticatorConfig reqPathAuthenticator : reqPathAuthenticators) {
ApplicationAuthenticator authenticator = reqPathAuthenticator.getApplicationAuthenticator();
if (log.isDebugEnabled()) {
log.debug("Executing " + authenticator.getName());
}
if (authenticator.canHandle(request)) {
if (log.isDebugEnabled()) {
log.debug(authenticator.getName() + " can handle the request");
}
try {
AuthenticatorFlowStatus status = authenticator.process(request, response, context);
request.setAttribute(FrameworkConstants.RequestParams.FLOW_STATUS, status);
if (log.isDebugEnabled()) {
log.debug(authenticator.getName() + ".authenticate() returned: " + status.toString());
}
AuthenticatedUser authenticatedUser = context.getSubject();
seqConfig.setAuthenticatedUser(authenticatedUser);
if (log.isDebugEnabled()) {
if (authenticatedUser != null) {
log.debug("Authenticated User: " + authenticatedUser.getAuthenticatedSubjectIdentifier());
log.debug("Authenticated User Tenant Domain: " + authenticatedUser.getTenantDomain());
} else {
log.debug("Authenticated User is NULL.");
}
}
AuthenticatedIdPData authenticatedIdPData = new AuthenticatedIdPData();
// store authenticated user
authenticatedIdPData.setUser(authenticatedUser);
// store authenticated idp
authenticatedIdPData.setIdpName(FrameworkConstants.LOCAL_IDP_NAME);
reqPathAuthenticator.setAuthenticatorStateInfo(context.getStateInfo());
authenticatedIdPData.setAuthenticator(reqPathAuthenticator);
seqConfig.setAuthenticatedReqPathAuthenticator(reqPathAuthenticator);
context.getCurrentAuthenticatedIdPs().put(FrameworkConstants.LOCAL_IDP_NAME, authenticatedIdPData);
handlePostAuthentication(request, response, context, authenticatedIdPData);
context.addAuthenticationStepHistory(new AuthHistory(authenticator.getName(), authenticatedIdPData.getIdpName()));
} catch (InvalidCredentialsException e) {
if (log.isDebugEnabled()) {
log.debug("A login attempt was failed due to invalid credentials", e);
}
context.setRequestAuthenticated(false);
} catch (AuthenticationFailedException e) {
log.error(e.getMessage(), e);
context.setRequestAuthenticated(false);
} catch (LogoutFailedException e) {
throw new FrameworkException(e.getMessage(), e);
}
context.getSequenceConfig().setCompleted(true);
return;
}
}
}
Aggregations