Java Code Examples for org.wso2.carbon.identity.core.util.IdentityDatabaseUtil#getUserDBConnection()
The following examples show how to use
org.wso2.carbon.identity.core.util.IdentityDatabaseUtil#getUserDBConnection() .
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: JDBCUserStoreCountRetriever.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private Connection getDBConnection(RealmConfiguration realmConfiguration) throws SQLException, UserStoreException { Connection dbConnection = null; DataSource dataSource = DatabaseUtil.createUserStoreDataSource(realmConfiguration); if (dataSource != null) { dbConnection = DatabaseUtil.getDBConnection(dataSource); } //if primary user store, DB connection can be same as realm data source. if (dbConnection == null && realmConfiguration.isPrimary()) { dbConnection = IdentityDatabaseUtil.getUserDBConnection(); } else if (dbConnection == null) { throw new UserStoreException("Could not create a database connection to " + realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME)); } else { // db connection is present } dbConnection.setAutoCommit(false); if (dbConnection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) { dbConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } return dbConnection; }
Example 2
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Update the permission path for a given id * * @param id Id * @param newPermission New permission path value * @throws SQLException */ private void updatePermissionPath(String id, String newPermission) throws SQLException { PreparedStatement updatePermissionPrepStmt = null; Connection connection = null; try { connection = IdentityDatabaseUtil.getUserDBConnection(); updatePermissionPrepStmt = connection.prepareStatement(ApplicationMgtDBQueries.UPDATE_SP_PERMISSIONS); updatePermissionPrepStmt.setString(1, newPermission); updatePermissionPrepStmt.setString(2, id); updatePermissionPrepStmt.executeUpdate(); } finally { IdentityDatabaseUtil.closeStatement(updatePermissionPrepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example 3
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Get permission id for a given permission path * * @param permission Permission path * @return Permission id * @throws SQLException */ private int getPermissionId(String permission) throws SQLException { PreparedStatement loadPermissionsPrepStmt = null; ResultSet resultSet = null; Connection connection = null; int id = -1; try { connection = IdentityDatabaseUtil.getUserDBConnection(); loadPermissionsPrepStmt = connection.prepareStatement(ApplicationMgtDBQueries.LOAD_UM_PERMISSIONS_W); loadPermissionsPrepStmt.setString(1, permission.toLowerCase()); resultSet = loadPermissionsPrepStmt.executeQuery(); if (resultSet.next()) { id = resultSet.getInt(1); } } finally { IdentityDatabaseUtil.closeResultSet(resultSet); IdentityDatabaseUtil.closeStatement(loadPermissionsPrepStmt); IdentityDatabaseUtil.closeConnection(connection); } return id; }
Example 4
Source File: InternalCountRetriever.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
private Connection getDBConnection(boolean shouldApplyTransaction) throws SQLException, UserStoreException { Connection dbConnection = IdentityDatabaseUtil.getUserDBConnection(); if (dbConnection == null) { throw new UserStoreException("Could not create a database connection to User database"); } if (shouldApplyTransaction) { dbConnection.setAutoCommit(false); if (dbConnection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) { dbConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } } return dbConnection; }
Example 5
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Read application role permissions for a given application name * * @param applicationName Application name * @return Map of key value pairs. key is UM table id and value is permission * @throws SQLException */ private Map<String, String> readApplicationPermissions(String applicationName) throws SQLException { PreparedStatement readPermissionsPrepStmt = null; ResultSet resultSet = null; Connection connection = null; Map<String, String> permissions = new HashMap<>(); try { connection = IdentityDatabaseUtil.getUserDBConnection(); readPermissionsPrepStmt = connection.prepareStatement(ApplicationMgtDBQueries.LOAD_UM_PERMISSIONS); readPermissionsPrepStmt.setString(1, "%" + ApplicationMgtUtil.getApplicationPermissionPath() + "%"); resultSet = readPermissionsPrepStmt.executeQuery(); while (resultSet.next()) { String UM_ID = resultSet.getString(1); String permission = resultSet.getString(2); if (permission.contains(ApplicationMgtUtil.getApplicationPermissionPath() + ApplicationMgtUtil.PATH_CONSTANT + applicationName.toLowerCase())) { permissions.put(UM_ID, permission); } } } finally { IdentityDatabaseUtil.closeResultSet(resultSet); IdentityDatabaseUtil.closeStatement(readPermissionsPrepStmt); IdentityDatabaseUtil.closeConnection(connection); } return permissions; }
Example 6
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Delete role permission mapping for a given permission id * * @param id Permission id * @throws SQLException */ private void deleteRolePermissionMapping(int id) throws SQLException { PreparedStatement deleteRolePermissionPrepStmt = null; Connection connection = null; try { connection = IdentityDatabaseUtil.getUserDBConnection(); deleteRolePermissionPrepStmt = connection.prepareStatement(ApplicationMgtDBQueries.REMOVE_UM_ROLE_PERMISSION); deleteRolePermissionPrepStmt.setInt(1, id); deleteRolePermissionPrepStmt.executeUpdate(); } finally { IdentityApplicationManagementUtil.closeStatement(deleteRolePermissionPrepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example 7
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Delete permission entry for a given id * * @param entry_id Entry id * @throws SQLException */ private void deletePermission(int entry_id) throws SQLException { PreparedStatement deletePermissionPrepStmt = null; Connection connection = null; try { connection = IdentityDatabaseUtil.getUserDBConnection(); deletePermissionPrepStmt = connection.prepareStatement(ApplicationMgtDBQueries.REMOVE_UM_PERMISSIONS); deletePermissionPrepStmt.setInt(1, entry_id); deletePermissionPrepStmt.executeUpdate(); } finally { IdentityApplicationManagementUtil.closeStatement(deletePermissionPrepStmt); IdentityDatabaseUtil.closeConnection(connection); } }