/** * @param rs */ public static void closeResultSet(ResultSet rs) { IdentityDatabaseUtil.closeResultSet(rs); }
/** * @param rs */ public static void closeResultSet(ResultSet rs) { IdentityDatabaseUtil.closeResultSet(rs); }
private Map<String, String> getClaimProperties(Connection connection, int localClaimId, int tenantId) throws ClaimMetadataException { Map<String, String> claimProperties = new HashMap<>(); PreparedStatement prepStmt = null; ResultSet rs = null; String query = SQLConstants.GET_CLAIM_PROPERTIES; try { prepStmt = connection.prepareStatement(query); prepStmt.setInt(1, localClaimId); prepStmt.setInt(2, tenantId); rs = prepStmt.executeQuery(); while (rs.next()) { String claimPropertyName = rs.getString(SQLConstants.PROPERTY_NAME_COLUMN); String claimPropertyValue = rs.getString(SQLConstants.PROPERTY_VALUE_COLUMN); claimProperties.put(claimPropertyName, claimPropertyValue); } } catch (SQLException e) { throw new ClaimMetadataException("Error while retrieving claim properties", e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return claimProperties; }
public static void closeAllConnections(Connection dbConnection, ResultSet rs, PreparedStatement prepStmt) { closeResultSet(rs); closeStatement(prepStmt); closeConnection(dbConnection); }
public static void closeAllConnections(Connection dbConnection, ResultSet rs, PreparedStatement prepStmt) { closeResultSet(rs); closeStatement(prepStmt); closeConnection(dbConnection); }
public static void closeAllConnections(Connection dbConnection, ResultSet rs, PreparedStatement prepStmt) { closeResultSet(rs); closeStatement(prepStmt); closeConnection(dbConnection); }
public Map<Integer, Claim> getClaims(Connection connection, String claimDialectURI, int tenantId) throws ClaimMetadataException { List<Claim> claimList = new ArrayList<>(); Map<Integer, Claim> claimMap = new HashMap<>(); PreparedStatement prepStmt = null; ResultSet rs = null; String query = SQLConstants.GET_CLAIMS_BY_DIALECT; try { prepStmt = connection.prepareStatement(query); prepStmt.setString(1, claimDialectURI); prepStmt.setInt(2, tenantId); prepStmt.setInt(3, tenantId); rs = prepStmt.executeQuery(); // TODO : Get the logic reviewed : using executeQuery in a transaction. while (rs.next()) { String claimURI = rs.getString(SQLConstants.CLAIM_URI_COLUMN); int claimId = rs.getInt(SQLConstants.ID_COLUMN); claimMap.put(claimId, new Claim(claimDialectURI, claimURI)); } } catch (SQLException e) { throw new ClaimMetadataException("Error while listing claims for dialect " + claimDialectURI, e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return claimMap; }
public Map<Integer, Claim> getClaims(Connection connection, String claimDialectURI, int tenantId) throws ClaimMetadataException { Map<Integer, Claim> claimMap = new HashMap<>(); PreparedStatement prepStmt = null; ResultSet rs = null; String query = SQLConstants.GET_CLAIMS_BY_DIALECT; try { prepStmt = connection.prepareStatement(query); prepStmt.setString(1, claimDialectURI); prepStmt.setInt(2, tenantId); prepStmt.setInt(3, tenantId); rs = prepStmt.executeQuery(); // TODO : Get the logic reviewed : using executeQuery in a transaction. while (rs.next()) { String claimURI = rs.getString(SQLConstants.CLAIM_URI_COLUMN); int claimId = rs.getInt(SQLConstants.ID_COLUMN); claimMap.put(claimId, new Claim(claimDialectURI, claimURI)); } } catch (SQLException e) { throw new ClaimMetadataException("Error while listing claims for dialect " + claimDialectURI, e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return claimMap; }
public Map<Integer, Claim> getClaims(Connection connection, String claimDialectURI, int tenantId) throws ClaimMetadataException { Map<Integer, Claim> claimMap = new HashMap<>(); PreparedStatement prepStmt = null; ResultSet rs = null; String query = SQLConstants.GET_CLAIMS_BY_DIALECT; try { prepStmt = connection.prepareStatement(query); prepStmt.setString(1, claimDialectURI); prepStmt.setInt(2, tenantId); prepStmt.setInt(3, tenantId); rs = prepStmt.executeQuery(); // TODO : Get the logic reviewed : using executeQuery in a transaction. while (rs.next()) { String claimURI = rs.getString(SQLConstants.CLAIM_URI_COLUMN); int claimId = rs.getInt(SQLConstants.ID_COLUMN); claimMap.put(claimId, new Claim(claimDialectURI, claimURI)); } } catch (SQLException e) { throw new ClaimMetadataException("Error while listing claims for dialect " + claimDialectURI, e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return claimMap; }
public int addClaim(Connection connection, String claimDialectURI, String claimURI, int tenantId) throws ClaimMetadataException { PreparedStatement prepStmt = null; ResultSet rs = null; int claimId = 0; String query = SQLConstants.ADD_CLAIM; try { String dbProductName = connection.getMetaData().getDatabaseProductName(); prepStmt = connection.prepareStatement(query, new String[]{DBUtils.getConvertedAutoGeneratedColumnName (dbProductName, SQLConstants.ID_COLUMN)}); prepStmt.setString(1, claimDialectURI); prepStmt.setInt(2, tenantId); prepStmt.setString(3, claimURI); prepStmt.setInt(4, tenantId); prepStmt.execute(); rs = prepStmt.getGeneratedKeys(); if (rs.next()) { claimId = rs.getInt(1); } } catch (SQLException e) { throw new ClaimMetadataException("Error while adding claim " + claimURI + " to dialect " + claimDialectURI, e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return claimId; }
private List<AttributeMapping> getClaimAttributeMappings(Connection connection, int localClaimId, int tenantId) throws ClaimMetadataException { List<AttributeMapping> attributeMappings = new ArrayList<>(); PreparedStatement prepStmt = null; ResultSet rs = null; String query = SQLConstants.GET_MAPPED_ATTRIBUTES; try { prepStmt = connection.prepareStatement(query); prepStmt.setInt(1, localClaimId); prepStmt.setInt(2, tenantId); rs = prepStmt.executeQuery(); while (rs.next()) { String userStoreDomainName = rs.getString(SQLConstants.USER_STORE_DOMAIN_NAME_COLUMN); String attributeName = rs.getString(SQLConstants.ATTRIBUTE_NAME_COLUMN); AttributeMapping attributeMapping = new AttributeMapping(userStoreDomainName, attributeName); attributeMappings.add(attributeMapping); } } catch (SQLException e) { throw new ClaimMetadataException("Error while retrieving attribute mappings", e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return attributeMappings; }
private List<AttributeMapping> getClaimAttributeMappings(Connection connection, int localClaimId, int tenantId) throws ClaimMetadataException { List<AttributeMapping> attributeMappings = new ArrayList<>(); PreparedStatement prepStmt = null; ResultSet rs = null; String query = SQLConstants.GET_MAPPED_ATTRIBUTES; try { prepStmt = connection.prepareStatement(query); prepStmt.setInt(1, localClaimId); prepStmt.setInt(2, tenantId); rs = prepStmt.executeQuery(); while (rs.next()) { String userStoreDomainName = rs.getString(SQLConstants.USER_STORE_DOMAIN_NAME_COLUMN); String attributeName = rs.getString(SQLConstants.ATTRIBUTE_NAME_COLUMN); AttributeMapping attributeMapping = new AttributeMapping(userStoreDomainName, attributeName); attributeMappings.add(attributeMapping); } } catch (SQLException e) { throw new ClaimMetadataException("Error while retrieving attribute mappings", e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return attributeMappings; }
private List<AttributeMapping> getClaimAttributeMappings(Connection connection, int localClaimId, int tenantId) throws ClaimMetadataException { List<AttributeMapping> attributeMappings = new ArrayList<>(); PreparedStatement prepStmt = null; ResultSet rs = null; String query = SQLConstants.GET_MAPPED_ATTRIBUTES; try { prepStmt = connection.prepareStatement(query); prepStmt.setInt(1, localClaimId); prepStmt.setInt(2, tenantId); rs = prepStmt.executeQuery(); while (rs.next()) { String userStoreDomainName = rs.getString(SQLConstants.USER_STORE_DOMAIN_NAME_COLUMN); String attributeName = rs.getString(SQLConstants.ATTRIBUTE_NAME_COLUMN); AttributeMapping attributeMapping = new AttributeMapping(userStoreDomainName, attributeName); attributeMappings.add(attributeMapping); } } catch (SQLException e) { throw new ClaimMetadataException("Error while retrieving attribute mappings", e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt); } return attributeMappings; }
/** * Checks if the entry exist in the database; * * @param connection * @param rpDo * @return * @throws SQLException */ private boolean isUserRPExist(Connection connection, OpenIDUserRPDO rpDo, int tenantId) throws SQLException { PreparedStatement prepStmt = null; ResultSet results = null; boolean result = false; try { prepStmt = connection.prepareStatement(OpenIDSQLQueries.CHECK_USER_RP_EXIST); prepStmt.setString(1, rpDo.getUserName()); prepStmt.setInt(2, tenantId); prepStmt.setString(3, rpDo.getRpUrl()); results = prepStmt.executeQuery(); if (results != null && results.next()) { result = true; } } finally { IdentityDatabaseUtil.closeResultSet(results); IdentityDatabaseUtil.closeStatement(prepStmt); } return result; }
throw new ClaimMetadataException("Error while retrieving claim mapping", e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt);
throw new ClaimMetadataException("Error while retrieving claim mapping", e); } finally { IdentityDatabaseUtil.closeResultSet(rs); IdentityDatabaseUtil.closeStatement(prepStmt);
/** * 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; }
/** * 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; }
/** * Builds the OpenIDRememberMeDo * * @param results * @param username * @return * @throws SQLException */ private OpenIDRememberMeDO buildRememberMeDO(ResultSet results, String username) { OpenIDRememberMeDO remDO = new OpenIDRememberMeDO(); try { if (!results.next()) { log.debug("RememberMe token not found for the user " + username); return remDO; } remDO.setUserName(results.getString(1)); remDO.setToken(results.getString(3)); remDO.setTimestamp(results.getTimestamp(4)); } catch (SQLException e) { log.error("Failed to create RememberMeDO for the user " + username + ". Error while accessing the database", e); } finally { IdentityDatabaseUtil.closeResultSet(results); } return remDO; }
/** * Builds the OpenIDRememberMeDo * * @param results * @param username * @return * @throws SQLException */ private OpenIDRememberMeDO buildRememberMeDO(ResultSet results, String username) { OpenIDRememberMeDO remDO = new OpenIDRememberMeDO(); try { if (!results.next()) { log.debug("RememberMe token not found for the user " + username); return remDO; } remDO.setUserName(results.getString(1)); remDO.setToken(results.getString(3)); remDO.setTimestamp(results.getTimestamp(4)); } catch (SQLException e) { log.error("Failed to create RememberMeDO for the user " + username + ". Error while accessing the database", e); } finally { IdentityDatabaseUtil.closeResultSet(results); } return remDO; }