Search in sources :

Example 1 with FederatedUserSession

use of org.wso2.carbon.identity.application.authentication.framework.model.FederatedUserSession in project carbon-identity-framework by wso2.

the class UserSessionDAOImplTest method testGetFederatedAuthSessionDetails.

@Test
public void testGetFederatedAuthSessionDetails() throws Exception {
    setupSessionStore();
    DataSource dataSource = mock(DataSource.class);
    mockStatic(IdentityDatabaseUtil.class);
    when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSource);
    when(IdentityDatabaseUtil.getSessionDataSource()).thenReturn(dataSource);
    when(dataSource.getConnection()).thenReturn(getConnection(DB_NAME));
    FederatedUserSession federatedUserSession = userSessionDAO.getFederatedAuthSessionDetails(IDP_SESSION_INDEX);
    assertEquals(federatedUserSession.getSessionId(), SESSION_CONTEXT_KEY);
    assertEquals(federatedUserSession.getIdpName(), IDP_NAME);
    assertEquals(federatedUserSession.getAuthenticatorName(), AUTHENTICATOR_ID);
    assertEquals(federatedUserSession.getProtocolType(), PROTOCOL_TYPE);
}
Also used : FederatedUserSession(org.wso2.carbon.identity.application.authentication.framework.model.FederatedUserSession) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) DataSource(javax.sql.DataSource) Test(org.testng.annotations.Test) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with FederatedUserSession

use of org.wso2.carbon.identity.application.authentication.framework.model.FederatedUserSession in project carbon-identity-framework by wso2.

the class UserSessionDAO method getFederatedAuthSessionDetails.

/**
 * Get federated user session details mapped for federated IDP sessionId.
 *
 * @param fedIdpSessionId sid claim in the logout token of the federated idp.
 * @return A FederatedUserSession containing federated authentication session details.
 * @throws SessionManagementServerException
 */
default FederatedUserSession getFederatedAuthSessionDetails(String fedIdpSessionId) throws SessionManagementServerException {
    FederatedUserSession federatedUserSession;
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(JdbcUtils.Database.SESSION);
    try {
        federatedUserSession = jdbcTemplate.fetchSingleRecord(SQLQueries.SQL_GET_FEDERATED_AUTH_SESSION_INFO_BY_SESSION_ID, (resultSet, rowNumber) -> new FederatedUserSession(resultSet.getString(SessionMgtConstants.FEDERATED_IDP_SESSION_ID), resultSet.getString(SessionMgtConstants.FEDERATED_SESSION_ID), resultSet.getString(SessionMgtConstants.FEDERATED_IDP_NAME), resultSet.getString(SessionMgtConstants.FEDERATED_AUTHENTICATOR_ID), resultSet.getString(SessionMgtConstants.FEDERATED_PROTOCOL_TYPE)), preparedStatement -> preparedStatement.setString(1, fedIdpSessionId));
        return federatedUserSession;
    } catch (DataAccessException e) {
        throw new SessionManagementServerException(SessionMgtConstants.ErrorMessages.ERROR_CODE_UNABLE_TO_GET_FED_USER_SESSION, SessionMgtConstants.ErrorMessages.ERROR_CODE_UNABLE_TO_GET_FED_USER_SESSION.getDescription(), e);
    }
}
Also used : JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) SessionManagementServerException(org.wso2.carbon.identity.application.authentication.framework.exception.session.mgt.SessionManagementServerException) JdbcUtils(org.wso2.carbon.identity.application.authentication.framework.util.JdbcUtils) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) FederatedUserSession(org.wso2.carbon.identity.application.authentication.framework.model.FederatedUserSession) UserSession(org.wso2.carbon.identity.application.authentication.framework.model.UserSession) SQLQueries(org.wso2.carbon.identity.application.authentication.framework.store.SQLQueries) SessionMgtConstants(org.wso2.carbon.identity.application.authentication.framework.util.SessionMgtConstants) SessionManagementServerException(org.wso2.carbon.identity.application.authentication.framework.exception.session.mgt.SessionManagementServerException) FederatedUserSession(org.wso2.carbon.identity.application.authentication.framework.model.FederatedUserSession) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Aggregations

FederatedUserSession (org.wso2.carbon.identity.application.authentication.framework.model.FederatedUserSession)2 DataSource (javax.sql.DataSource)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)1 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)1 SessionManagementServerException (org.wso2.carbon.identity.application.authentication.framework.exception.session.mgt.SessionManagementServerException)1 UserSession (org.wso2.carbon.identity.application.authentication.framework.model.UserSession)1 SQLQueries (org.wso2.carbon.identity.application.authentication.framework.store.SQLQueries)1 JdbcUtils (org.wso2.carbon.identity.application.authentication.framework.util.JdbcUtils)1 SessionMgtConstants (org.wso2.carbon.identity.application.authentication.framework.util.SessionMgtConstants)1 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)1