Search in sources :

Example 6 with PGPoolingDataSource

use of org.postgresql.ds.PGPoolingDataSource in project Gatekeeper by FINRAOS.

the class PostgresDBConnection method revokeAccess.

public boolean revokeAccess(String user, RoleType roles, String address) throws SQLException {
    PGPoolingDataSource dataSource = null;
    try {
        dataSource = connect(address);
        JdbcTemplate conn = new JdbcTemplate(dataSource);
        logger.info("Removing " + user + " from " + address + " if they exist.");
        revokeUser(conn, user + "_" + roles.getShortSuffix());
        return true;
    } catch (Exception ex) {
        logger.error("An exception was thrown while trying to revoke user " + user + "_" + roles.getShortSuffix() + " from address " + address, ex);
        return false;
    } finally {
        if (dataSource != null) {
            dataSource.close();
        }
    }
}
Also used : PGPoolingDataSource(org.postgresql.ds.PGPoolingDataSource) DataAccessException(org.springframework.dao.DataAccessException) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) GKUnsupportedDBException(org.finra.gatekeeper.services.db.exception.GKUnsupportedDBException)

Example 7 with PGPoolingDataSource

use of org.postgresql.ds.PGPoolingDataSource in project Gatekeeper by FINRAOS.

the class PostgresDBConnection method getAvailableTables.

public Map<RoleType, List<String>> getAvailableTables(String address) throws SQLException {
    Map<RoleType, List<String>> results = new HashMap<>();
    PGPoolingDataSource dataSource = connect(address);
    JdbcTemplate conn = new JdbcTemplate(dataSource);
    logger.info("Getting available schema information for " + address);
    for (RoleType roleType : RoleType.values()) {
        try {
            List<String> schemas = conn.queryForList(getSchemas, new Object[] { roleType.getDbRole() }, String.class);
            results.put(roleType, !schemas.isEmpty() ? schemas : Collections.singletonList("No Schemas are available for role " + roleType.getDbRole() + " at this time."));
            logger.info("Retrieved available schema information for database " + address + " for role " + roleType.getDbRole());
        } catch (Exception ex) {
            logger.error("Could not retrieve available role information for database " + address + " for role " + roleType.getDbRole(), ex);
            results.put(roleType, Collections.singletonList("Unable to get available schemas for role " + roleType.getDbRole()));
        }
    }
    dataSource.close();
    return results;
}
Also used : RoleType(org.finra.gatekeeper.services.accessrequest.model.RoleType) PGPoolingDataSource(org.postgresql.ds.PGPoolingDataSource) DataAccessException(org.springframework.dao.DataAccessException) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) GKUnsupportedDBException(org.finra.gatekeeper.services.db.exception.GKUnsupportedDBException)

Aggregations

PGPoolingDataSource (org.postgresql.ds.PGPoolingDataSource)7 CannotGetJdbcConnectionException (org.springframework.jdbc.CannotGetJdbcConnectionException)4 GKUnsupportedDBException (org.finra.gatekeeper.services.db.exception.GKUnsupportedDBException)3 DataAccessException (org.springframework.dao.DataAccessException)3 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 JDBCClient (io.vertx.ext.jdbc.JDBCClient)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 TestUtil (io.vertx.openshift.jdbc.TestUtil)1 SQLException (java.sql.SQLException)1 RoleType (org.finra.gatekeeper.services.accessrequest.model.RoleType)1