/** Adds a new permission for the specified external component. */ private static void addConfiguration(ExternalComponentConfiguration configuration) { // Remove the permission for the entity from the database java.sql.Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(ADD_CONFIGURATION); pstmt.setString(1, configuration.getSubdomain()); pstmt.setString(2, configuration.getSecret()); pstmt.setString(3, configuration.getPermission().toString()); pstmt.executeUpdate(); } catch (SQLException sqle) { Log.error(sqle); } finally { try { if (pstmt != null) pstmt.close(); } catch (Exception e) { Log.error(e); } try { if (con != null) con.close(); } catch (Exception e) { Log.error(e); } } }
/** * Returns true if the external component with the specified subdomain can connect to the * * <p>local server. * * @param subdomain the subdomain of the external component. * @return true if the external component with the specified subdomain can connect to the * <p>local server. */ public static boolean canAccess(String subdomain) { // By default there is no permission defined for the XMPP entity Permission permission = null; ExternalComponentConfiguration config = getConfiguration(subdomain); if (config != null) { permission = config.getPermission(); } if (PermissionPolicy.blacklist == getPermissionPolicy()) { // Anyone can access except those entities listed in the blacklist if (Permission.blocked == permission) { return false; } else { return true; } } else { // Access is limited to those present in the whitelist if (Permission.allowed == permission) { return true; } else { return false; } } }