Java Code Examples for org.wso2.carbon.identity.core.util.IdentityDatabaseUtil#commitTransaction()

The following examples show how to use org.wso2.carbon.identity.core.util.IdentityDatabaseUtil#commitTransaction() . 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: WorkflowRequestDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Update state of a existing workflow request
 *
 * @param requestId
 * @param newState
 * @throws InternalWorkflowException
 */
public void updateStatusOfRequest(String requestId, String newState) throws InternalWorkflowException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.UPDATE_STATUS_OF_REQUEST;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, newState);
        prepStmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
        prepStmt.setString(3, requestId);
        prepStmt.execute();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException("Error when executing the sql query:" + query, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
 
Example 2
Source File: AssociationDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param associationName
 * @param workflowId
 * @param eventId
 * @param condition
 * @throws InternalWorkflowException
 */
public void addAssociation(String associationName, String workflowId, String eventId, String condition)
        throws InternalWorkflowException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;

    String query = SQLConstants.ASSOCIATE_WF_TO_EVENT;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, eventId);
        prepStmt.setString(2, associationName);
        prepStmt.setString(3, condition);
        prepStmt.setString(4, workflowId);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException(errorMessage, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
 
Example 3
Source File: JDBCUserRecoveryDataStore.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void invalidate(String code) throws IdentityException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    try {
        prepStmt = connection.prepareStatement(SQLQuery.INVALIDATE_METADATA_FROM_CODE);
        prepStmt.setString(1, code.toLowerCase());
        prepStmt.execute();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw IdentityException.error("Error while invalidating user identity data for code: " + code, e);
    } finally {
        IdentityDatabaseUtil.closeStatement(prepStmt);
        IdentityDatabaseUtil.closeConnection(connection);
    }
}
 
Example 4
Source File: WorkflowRequestAssociationDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Update state of workflow of a request
 *
 * @param requestId requestId to update relationships of.
 * @throws InternalWorkflowException
 */
public void updateStatusOfRelationshipsOfPendingRequest(String requestId, String status) throws
                                                                                         InternalWorkflowException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.UPDATE_STATUS_OF_RELATIONSHIPS_OF_REQUEST;
    try {
        Timestamp updatedDateStamp = new Timestamp(System.currentTimeMillis());
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, status);
        prepStmt.setTimestamp(2, updatedDateStamp);
        prepStmt.setString(3, requestId);
        prepStmt.setString(4, WFConstant.HT_STATE_PENDING);
        prepStmt.execute();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException("Error when executing the sql query:" + query, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
 
Example 5
Source File: IdPManagementDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param resourceId
 * @param tenantId
 * @param tenantDomain
 * @throws IdentityProviderManagementException
 */
public void deleteIdPByResourceId(String resourceId, int tenantId, String tenantDomain)
        throws IdentityProviderManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    try {
        IdentityProvider identityProvider = getIDPbyResourceId(dbConnection, resourceId, tenantId,
                tenantDomain);
        if (identityProvider == null) {
            String msg = "Trying to delete non-existent Identity Provider with resource ID: %s in tenantDomain: %s";
            throw new IdentityProviderManagementException(String.format(msg, resourceId, tenantDomain));
        }
        deleteIdP(dbConnection, tenantId, null, resourceId);
        IdentityDatabaseUtil.commitTransaction(dbConnection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while deleting Identity Provider of tenant "
                + tenantDomain, e);
    } finally {
        IdentityDatabaseUtil.closeConnection(dbConnection);
    }
}
 
Example 6
Source File: RequestEntityRelationshipDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Delete existing relationships of a request.
 *
 * @param uuid
 * @throws InternalWorkflowException
 */
public void deleteRelationshipsOfRequest(String uuid) throws InternalWorkflowException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.DELETE_REQUEST_ENTITY_RELATIONSHIP;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, uuid);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException("Error when executing the sql query", e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
 
Example 7
Source File: IdPManagementDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void deleteTenantRole(int tenantId, String role, String tenantDomain)
        throws IdentityProviderManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    try {
        String sqlStmt = IdPManagementConstants.SQLQueries.DELETE_ROLE_LISTENER_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, role);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(dbConnection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while deleting tenant role " + role +
                " of tenant " + tenantDomain, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt);
    }
}
 
Example 8
Source File: UserProfileMgtDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void deleteAssociationsFromDomain(int tenantId, String domainName) throws
                                                                          UserProfileException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
        preparedStatement = dbConnection.prepareStatement(Constants.SQLQueries.DELETE_ASSOCIATED_ID_FROM_DOMAIN);
        preparedStatement.setInt(1, tenantId);
        preparedStatement.setString(2, domainName);
        preparedStatement.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(dbConnection);

    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new UserProfileException(String.format("Database error occurred while deleting associated ids with " +
                                                     "domain '%s'", domainName), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 9
Source File: WorkflowRequestAssociationDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Adds new workflow-request relationship to database
 *
 * @param relationshipId
 * @param workflowId
 * @param requestId
 * @param status
 * @throws InternalWorkflowException
 */
public void addNewRelationship(String relationshipId, String workflowId, String requestId, String status,
                               int tenantId) throws InternalWorkflowException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.ADD_WORKFLOW_REQUEST_RELATIONSHIP;
    try {
        Timestamp createdDateStamp = new Timestamp(System.currentTimeMillis());
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, relationshipId);
        prepStmt.setString(2, workflowId);
        prepStmt.setString(3, requestId);
        prepStmt.setTimestamp(4, createdDateStamp);
        prepStmt.setString(5, status);
        prepStmt.setInt(6, tenantId);
        prepStmt.execute();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException("Error when executing the sql query:" + query, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
 
Example 10
Source File: WorkflowDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Clear all the parameters that stored under workflow Id
 *
 * @param workflowId WorkflowId
 * @throws InternalWorkflowException
 */
public void removeWorkflowParams(String workflowId) throws InternalWorkflowException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.DELETE_WORKFLOW_PARAMS_QUERY;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, workflowId);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException(errorMessage, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
 
Example 11
Source File: ClaimDialectDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void renameClaimDialect(ClaimDialect oldClaimDialect, ClaimDialect newClaimDialect, int tenantId) throws
        ClaimMetadataException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;

    String query = SQLConstants.UPDATE_CLAIM_DIALECT;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, newClaimDialect.getClaimDialectURI());
        prepStmt.setString(2, oldClaimDialect.getClaimDialectURI());
        prepStmt.setInt(3, tenantId);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new ClaimMetadataException("Error while renaming claim dialect " + oldClaimDialect
                .getClaimDialectURI(), e);
    } finally {
        IdentityDatabaseUtil.closeStatement(prepStmt);
        IdentityDatabaseUtil.closeConnection(connection);
    }
}
 
Example 12
Source File: ClaimDialectDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void addClaimDialect(ClaimDialect claimDialect, int tenantId) throws ClaimMetadataException {

        Connection connection = IdentityDatabaseUtil.getDBConnection();
        PreparedStatement prepStmt = null;

        String query = SQLConstants.ADD_CLAIM_DIALECT;

        try {
            prepStmt = connection.prepareStatement(query);
            prepStmt.setString(1, claimDialect.getClaimDialectURI());
            prepStmt.setInt(2, tenantId);
            prepStmt.executeUpdate();
            IdentityDatabaseUtil.commitTransaction(connection);
        } catch (SQLException e) {
            IdentityDatabaseUtil.rollbackTransaction(connection);
            throw new ClaimMetadataException("Error while adding claim dialect " + claimDialect
                    .getClaimDialectURI(), e);
        } finally {
            IdentityDatabaseUtil.closeStatement(prepStmt);
            IdentityDatabaseUtil.closeConnection(connection);
        }
    }
 
Example 13
Source File: IdPManagementDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param idPName
 * @param tenantId
 * @param tenantDomain
 * @throws IdentityProviderManagementException
 */
public void deleteIdP(String idPName, int tenantId, String tenantDomain)
        throws IdentityProviderManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    try {
        IdentityProvider identityProvider = getIdPByName(dbConnection, idPName, tenantId,
                tenantDomain);
        if (identityProvider == null) {
            String msg = "Trying to delete non-existent Identity Provider: %s in tenantDomain: %s";
            throw new IdentityProviderManagementException(String.format(msg, idPName, tenantDomain));
        }
        deleteIdP(dbConnection, tenantId, idPName, null);
        IdentityDatabaseUtil.commitTransaction(dbConnection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while deleting Identity Provider of tenant "
                + tenantDomain, e);
    } finally {
        IdentityDatabaseUtil.closeConnection(dbConnection);
    }
}
 
Example 14
Source File: UserSessionStore.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the session information records of a given set of session IDs from the relevant tables.
 *
 * @param sessionIdList list of terminated session IDs
 */
public void removeTerminatedSessionRecords(List<String> sessionIdList) {

    String[] sessionsToRemove = sessionIdList.toArray(new String[0]);

    if (log.isDebugEnabled()) {
        log.debug("Removing meta information of the deleted sessions.");
    }

    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {

        deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_USER_SESSION_MAPPING_TABLE,
                SQLQueries.SQL_DELETE_TERMINATED_SESSION_DATA);
        deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_SESSION_APP_INFO_TABLE,
                SQLQueries.SQL_DELETE_IDN_AUTH_SESSION_APP_INFO);
        deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_SESSION_META_DATA_TABLE,
                SQLQueries.SQL_DELETE_IDN_AUTH_SESSION_META_DATA);
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        log.error("Error while removing the terminated session information from the database.", e);
    }
}
 
Example 15
Source File: UserProfileMgtDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the federated association entries for the given user.
 *
 * @param tenantId        Tenant identifier.
 * @param userStoreDomain User store domain name.
 * @param username        Username without user store domain.
 * @throws UserProfileException {@link UserProfileException}.
 */
public void deleteFederatedAssociation(int tenantId, String userStoreDomain, String username)
        throws UserProfileException {

    try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
        try (PreparedStatement prepStmt = connection.prepareStatement(
                Constants.SQLQueries.DELETE_ALL_ASSOCIATIONS_FOR_USER)) {
            prepStmt.setInt(1, tenantId);
            prepStmt.setString(2, userStoreDomain);
            prepStmt.setString(3, username);
            prepStmt.executeUpdate();
            IdentityDatabaseUtil.commitTransaction(connection);
        } catch (SQLException e1) {
            IdentityDatabaseUtil.rollbackTransaction(connection);
            throw new UserProfileException("Error occurred while removing federated association entries of user: " +
                    username + ", of user store domain: " + userStoreDomain + ", in tenant: " + tenantId, e1);
        }
    } catch (SQLException e) {
        throw new UserProfileException("Error occurred while handling the database connection", e);
    }
}
 
Example 16
Source File: ProfileMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Delete federated idp account associations from IDN_ASSOCIATED_ID table
 *
 * @param tenantAwareUsername
 * @param userStoreDomain
 * @param tenantId
 * @throws UserStoreException
 */
private void deleteFederatedIdpAccountAssociations(String tenantAwareUsername,
        String userStoreDomain,
        int tenantId) throws UserStoreException {

    // Run this code only if IDN_ASSOCIATED_ID table presents. We are doing this because of this feature can be used
    // by products which does not have the IDN tables.
    if (!ServiceHodler.isIDNTableExist()) {
        return;
    }

    String sql = "DELETE FROM IDN_ASSOCIATED_ID WHERE USER_NAME=? AND DOMAIN_NAME=? AND TENANT_ID=?";

    String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantId);
    // get tenant domain and user store domain appended username for logging
    String fullyQualifiedUsername = getFullQualifiedUsername(tenantAwareUsername, userStoreDomain, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug("Deleting federated IDP user account associations of user:" + fullyQualifiedUsername);
    }

    try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
        try (PreparedStatement prepStmt = connection.prepareStatement(sql)) {
            prepStmt.setString(1, tenantAwareUsername);
            prepStmt.setString(2, userStoreDomain);
            prepStmt.setInt(3, tenantId);
            prepStmt.executeUpdate();
            IdentityDatabaseUtil.commitTransaction(connection);
        } catch (SQLException e1) {
            IdentityDatabaseUtil.rollbackTransaction(connection);
            throw new UserStoreException(String.format("Error when trying to delete the federated IDP user "
                    + "account associations of user:%s", fullyQualifiedUsername), e1);
        }
    } catch (SQLException e) {
        String msg = "Error when trying to delete the federated IDP user account associations of user:%s";
        throw new UserStoreException(String.format(msg, fullyQualifiedUsername), e);
    }
}
 
Example 17
Source File: JDBCUserRecoveryDataStore.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Stores identity data set.
 *
 * @throws IdentityException
 */
@Override
@Deprecated
public void store(UserRecoveryDataDO[] recoveryDataDOs) throws IdentityException {

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    try {
        prepStmt = connection.prepareStatement(SQLQuery.STORE_META_DATA);
        for (UserRecoveryDataDO dataDO : recoveryDataDOs) {
            prepStmt.setString(1, dataDO.getUserName().toLowerCase());
            prepStmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
            prepStmt.setString(3, dataDO.getCode().toLowerCase());
            prepStmt.setString(4, dataDO.getSecret());
            prepStmt.setString(5, dataDO.getExpireTime());
            prepStmt.addBatch();
        }
        prepStmt.executeBatch();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw IdentityException.error("Error while storing user identity data", e);
    } finally {
        IdentityDatabaseUtil.closeStatement(prepStmt);
        IdentityDatabaseUtil.closeConnection(connection);
    }
}
 
Example 18
Source File: UserProfileMgtDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Delete the association entry for the given user with the given federated identifier.
 *
 * @param tenantId           tenant identifier
 * @param userStoreDomain    user store domain name
 * @param domainFreeUsername username without user store domain
 * @param idpId              identity provider id
 * @param federatedUserId    federated identity id
 * @throws UserProfileException
 */
public void deleteAssociation(int tenantId, String userStoreDomain, String domainFreeUsername, String idpId,
                              String federatedUserId) throws UserProfileException {

    try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
        try (PreparedStatement prepStmt = connection
                .prepareStatement(Constants.SQLQueries.DELETE_ASSOCIATION)) {
            prepStmt.setInt(1, tenantId);
            prepStmt.setString(2, idpId);
            prepStmt.setInt(3, tenantId);
            prepStmt.setString(4, federatedUserId);
            prepStmt.setString(5, domainFreeUsername);
            prepStmt.setString(6, userStoreDomain);

            prepStmt.executeUpdate();
            IdentityDatabaseUtil.commitTransaction(connection);
        } catch (SQLException e1) {
            IdentityDatabaseUtil.rollbackTransaction(connection);
            throw new UserProfileException("Error occurred while removing account association entry of user: " +
                    domainFreeUsername + " of user store domain: " + userStoreDomain + " in tenant: " + tenantId +
                    " with federated ID: " + federatedUserId + " of IdP: " + idpId, e1);
        }
    } catch (SQLException e) {
        throw new UserProfileException("Error occurred while removing account association entry of user: " +
                domainFreeUsername + " of user store domain: " + userStoreDomain + " in tenant: " + tenantId + " " +
                "with federated ID: " + federatedUserId + " of IdP: " + idpId, e);
    }
}
 
Example 19
Source File: UserSessionStore.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all the expired session records from relevant tables.
 */
public void removeExpiredSessionRecords() {

    if (log.isDebugEnabled()) {
        log.debug("Removing information of expired and deleted sessions.");
    }

    try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
        Set<String> terminatedAuthSessionIds = getSessionsTerminated(connection);
        String[] sessionsToRemove = new String[terminatedAuthSessionIds.size()];
        terminatedAuthSessionIds.toArray(sessionsToRemove);

        if (!terminatedAuthSessionIds.isEmpty()) {

            if (log.isDebugEnabled()) {
                log.debug(terminatedAuthSessionIds.size() + " number of sessions should be removed from the " +
                        "database. Removing in " + deleteChunkSize + " size batches.");
            }

            deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_USER_SESSION_MAPPING_TABLE,
                    SQLQueries.SQL_DELETE_TERMINATED_SESSION_DATA);
            deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_SESSION_APP_INFO_TABLE,
                    SQLQueries.SQL_DELETE_IDN_AUTH_SESSION_APP_INFO);
            deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_SESSION_META_DATA_TABLE,
                    SQLQueries.SQL_DELETE_IDN_AUTH_SESSION_META_DATA);

            IdentityDatabaseUtil.commitTransaction(connection);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("No expired sessions found to remove.");
            }
        }
    } catch (SQLException e) {
        log.error("Error while removing expired session information from the database.", e);
    }
}
 
Example 20
Source File: JDBCIdentityDataStore.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void updateUserDataValue(String userName, int tenantId, String key, String value) throws SQLException {

        Connection connection = IdentityDatabaseUtil.getDBConnection();
        PreparedStatement prepStmt = null;
        boolean isUsernameCaseSensitive = IdentityUtil.isUserStoreInUsernameCaseSensitive(userName, tenantId);
        try {
            String query;
            if (isUsernameCaseSensitive) {
                query = SQLQuery.UPDATE_USER_DATA;
            } else {
                query = SQLQuery.UPDATE_USER_DATA_CASE_INSENSITIVE;
            }
            prepStmt = connection.prepareStatement(query);
            prepStmt.setString(1, value);
            prepStmt.setInt(2, tenantId);
            prepStmt.setString(3, userName);
            prepStmt.setString(4, key);
            prepStmt.executeUpdate();
            IdentityDatabaseUtil.commitTransaction(connection);
        } catch (SQLException e) {
            IdentityDatabaseUtil.rollbackTransaction(connection);
        } finally {
            IdentityDatabaseUtil.closeStatement(prepStmt);
            IdentityDatabaseUtil.closeConnection(connection);
        }

    }