Search in sources :

Example 21 with UserSessionException

use of org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException in project carbon-identity-framework by wso2.

the class UserSessionStore method getUserIdsOfUserStore.

/**
 * Method to return the user Ids of the users in a given user store from the database.
 * @deprecated
 * User ids of local users are no longer stored in IDN_AUTH_USER table and user ids of all the users in a domain
 * should not be retrieved at once.
 *
 * @param userDomain name of the user Store domain
 * @param tenantId   id of the tenant domain
 * @return the list of user Ids of users stored in the given user store
 * @throws UserSessionException if an error occurs when retrieving the user id list from the database
 */
@Deprecated
public List<String> getUserIdsOfUserStore(String userDomain, int tenantId) throws UserSessionException {
    List<String> userIds = new ArrayList<>();
    try (Connection connection = IdentityDatabaseUtil.getSessionDBConnection(false)) {
        try (PreparedStatement preparedStatement = connection.prepareStatement(SQLQueries.SQL_SELECT_USER_IDS_OF_USER_STORE)) {
            preparedStatement.setString(1, userDomain.toUpperCase());
            preparedStatement.setInt(2, tenantId);
            try (ResultSet resultSet = preparedStatement.executeQuery()) {
                while (resultSet.next()) {
                    userIds.add(resultSet.getString(1));
                }
            }
        } catch (SQLException e1) {
            throw new UserSessionException("Error while retrieving user Ids stored in the user domain: " + userDomain + ", Tenant Id: " + tenantId, e1);
        }
    } catch (SQLException e) {
        throw new UserSessionException("Error while retrieving user Ids stored in the user domain: " + userDomain + ", Tenant Id: " + tenantId, e);
    }
    return userIds;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) UserSessionException(org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException)

Example 22 with UserSessionException

use of org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException in project carbon-identity-framework by wso2.

the class UserSessionStore method getIdPId.

/**
 * Retrieve IDP ID from the IDP table using IDP name and tenant ID.
 *
 * @param idpName   IDP name.
 * @param tenantId  Tenant ID.
 * @return          IDP ID.
 * @throws UserSessionException
 */
public int getIdPId(String idpName, int tenantId) throws UserSessionException {
    int idPId = -1;
    if (idpName.equals("LOCAL")) {
        return idPId;
    }
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (PreparedStatement preparedStatement = connection.prepareStatement(SQLQueries.SQL_SELECT_IDP_WITH_TENANT)) {
            preparedStatement.setString(1, idpName);
            preparedStatement.setInt(2, tenantId);
            try (ResultSet resultSet = preparedStatement.executeQuery()) {
                if (resultSet.next()) {
                    idPId = resultSet.getInt(1);
                }
            }
        }
    } catch (SQLException e) {
        throw new UserSessionException("Error while retrieving the IdP id of: " + idpName + " and tenant ID: " + tenantId, e);
    }
    return idPId;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) UserSessionException(org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException)

Example 23 with UserSessionException

use of org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException in project carbon-identity-framework by wso2.

the class UserSessionStore method getUserId.

/**
 * Method to return the user Id of a user from the database.
 * @deprecated use {@link #getFederatedUserId(String, int, int)} instead.
 * Initially when the user store did not support user id, it was created and stored in here. Now the user store
 * support user ids for local users, this is not required for local users anymore. However similar capability is
 * still required for federated users.
 *
 * @param userName   Name of the authenticated user
 * @param tenantId   Id of the tenant domain
 * @param userDomain Name of the user Store domain
 * @return the user id of the user
 * @throws UserSessionException if an error occurs when retrieving the user id of the user from the database
 */
@Deprecated
public String getUserId(String userName, int tenantId, String userDomain) throws UserSessionException {
    String userId = null;
    try (Connection connection = IdentityDatabaseUtil.getSessionDBConnection(false)) {
        try (PreparedStatement preparedStatement = connection.prepareStatement(SQLQueries.SQL_SELECT_USER_IDS_OF_USER)) {
            preparedStatement.setString(1, userName);
            preparedStatement.setInt(2, tenantId);
            preparedStatement.setString(3, (userDomain == null) ? FEDERATED_USER_DOMAIN : userDomain.toUpperCase());
            try (ResultSet resultSet = preparedStatement.executeQuery()) {
                if (resultSet.next()) {
                    userId = resultSet.getString(1);
                }
            }
        } catch (SQLException e1) {
            throw new UserSessionException("Error while retrieving User Id of the user: " + userName + ", Tenant Id: " + tenantId + ", User domain: " + userDomain, e1);
        }
    } catch (SQLException e) {
        throw new UserSessionException("Error while retrieving User Id of the user: " + userName + ", Tenant Id: " + tenantId + ", User domain: " + userDomain, e);
    }
    return userId;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) UserSessionException(org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException)

Example 24 with UserSessionException

use of org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException in project carbon-identity-framework by wso2.

the class UserSessionStore method getAppId.

/**
 * Method to get app id from SP_APP table.
 *
 * @param applicationName application Name
 * @param appTenantID     app tenant id
 * @return the application id
 * @throws UserSessionException if an error occurs when retrieving app id
 *
 * @deprecated Since the UserSessionStore should not invoke the application management table.
 */
@Deprecated
public int getAppId(String applicationName, int appTenantID) throws UserSessionException {
    Integer appId;
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(JdbcUtils.Database.SESSION);
    try {
        appId = jdbcTemplate.fetchSingleRecord(SQLQueries.SQL_SELECT_APP_ID_OF_APP, ((resultSet, rowNumber) -> resultSet.getInt(1)), preparedStatement -> {
            preparedStatement.setString(1, applicationName);
            preparedStatement.setInt(2, appTenantID);
        });
    } catch (DataAccessException e) {
        throw new UserSessionException("Error while retrieving the app id of " + applicationName + ", " + "tenant id" + appTenantID + ".", e);
    }
    return appId == null ? 0 : appId;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) Connection(java.sql.Connection) IdentityDatabaseUtil(org.wso2.carbon.identity.core.util.IdentityDatabaseUtil) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) SessionMgtConstants(org.wso2.carbon.identity.application.authentication.framework.util.SessionMgtConstants) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DuplicatedAuthUserException(org.wso2.carbon.identity.application.authentication.framework.exception.DuplicatedAuthUserException) SQLException(java.sql.SQLException) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) JdbcUtils(org.wso2.carbon.identity.application.authentication.framework.util.JdbcUtils) ResultSet(java.sql.ResultSet) Map(java.util.Map) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) User(org.wso2.carbon.identity.application.common.model.User) IdPManagementUtil(org.wso2.carbon.idp.mgt.util.IdPManagementUtil) UserSessionException(org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException) Set(java.util.Set) PreparedStatement(java.sql.PreparedStatement) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) JdbcUtils.isH2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) IdentityUtil(org.wso2.carbon.identity.core.util.IdentityUtil) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) AuthHistory(org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory) FrameworkUtils(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) UserSessionException(org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Aggregations

UserSessionException (org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException)24 Connection (java.sql.Connection)14 PreparedStatement (java.sql.PreparedStatement)14 SQLException (java.sql.SQLException)14 ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)6 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)6 AuthHistory (org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory)6 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)5 DuplicatedAuthUserException (org.wso2.carbon.identity.application.authentication.framework.exception.DuplicatedAuthUserException)5 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4 HashSet (java.util.HashSet)4 List (java.util.List)4 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)4 Map (java.util.Map)3 Set (java.util.Set)3 TimeUnit (java.util.concurrent.TimeUnit)3 StringUtils (org.apache.commons.lang.StringUtils)3 Log (org.apache.commons.logging.Log)3 LogFactory (org.apache.commons.logging.LogFactory)3