/** * Create a new DataSource Realm. * * @param parent MBean Name of the associated parent component * @param dataSourceName the datasource name * @param roleNameCol the column name for the role names * @param userCredCol the column name for the user credentials * @param userNameCol the column name for the user names * @param userRoleTable the table name for the roles table * @param userTable the table name for the users * @return the object name of the created realm * @exception Exception if an MBean cannot be created or registered */ public String createDataSourceRealm(String parent, String dataSourceName, String roleNameCol, String userCredCol, String userNameCol, String userRoleTable, String userTable) throws Exception { // Create a new DataSourceRealm instance DataSourceRealm realm = new DataSourceRealm(); realm.setDataSourceName(dataSourceName); realm.setRoleNameCol(roleNameCol); realm.setUserCredCol(userCredCol); realm.setUserNameCol(userNameCol); realm.setUserRoleTable(userRoleTable); realm.setUserTable(userTable); // Add the new instance to its parent component return addRealmToParent(parent, realm); }
dbConnection = open(); if (dbConnection == null) { Principal principal = authenticate(dbConnection, username, credentials); close(dbConnection);
/** * Return the Principal associated with the given user name. */ @Override protected Principal getPrincipal(String username) { Connection dbConnection = open(); if (dbConnection == null) { return new GenericPrincipal(username, null, null); } try { return (new GenericPrincipal(username, getPassword(dbConnection, username), getRoles(dbConnection, username))); } finally { close(dbConnection); } }
/** * @return the password associated with the given principal's user name. */ @Override protected String getPassword(String username) { Connection dbConnection = null; // Ensure that we have an open database connection dbConnection = open(); if (dbConnection == null) { return null; } try { return getPassword(dbConnection, username); } finally { close(dbConnection); } }
/** * Return the roles associated with the given user name. * @param username User name for which roles should be retrieved * @return an array list of the role names */ protected ArrayList<String> getRoles(String username) { Connection dbConnection = null; // Ensure that we have an open database connection dbConnection = open(); if (dbConnection == null) { return null; } try { return getRoles(dbConnection, username); } finally { close(dbConnection); } }
String credentials) throws SQLException{ String dbCredentials = getPassword(dbConnection, username); if (hasMessageDigest()) { validated = (digest(credentials).equalsIgnoreCase(dbCredentials)); } else validated = (digest(credentials).equals(dbCredentials)); ArrayList list = getRoles(dbConnection, username);
String dbCredentials = getPassword(dbConnection, username); getCredentialHandler().mutate(credentials); boolean validated = getCredentialHandler().matches(credentials, dbCredentials); ArrayList<String> list = getRoles(dbConnection, username);
/** * Return the password associated with the given principal's user name. * @param dbConnection The database connection to be used * @param username Username for which password should be retrieved * @return the password for the specified user */ protected String getPassword(Connection dbConnection, String username) { String dbCredentials = null; try (PreparedStatement stmt = credentials(dbConnection, username); ResultSet rs = stmt.executeQuery()) { if (rs.next()) { dbCredentials = rs.getString(1); } return (dbCredentials != null) ? dbCredentials.trim() : null; } catch (SQLException e) { containerLog.error( sm.getString("dataSourceRealm.getPassword.exception", username), e); } return null; }
String credentials) { String dbCredentials = getPassword(dbConnection, username); boolean validated = compareCredentials(credentials, dbCredentials); ArrayList<String> list = getRoles(dbConnection, username);
/** * Return the roles associated with the given user name * @param dbConnection The database connection to be used * @param username User name for which roles should be retrieved * @return an array list of the role names */ protected ArrayList<String> getRoles(Connection dbConnection, String username) { if (allRolesMode != AllRolesMode.STRICT_MODE && !isRoleStoreDefined()) { // Using an authentication only configuration and no role store has // been defined so don't spend cycles looking return null; } ArrayList<String> list = null; try (PreparedStatement stmt = roles(dbConnection, username); ResultSet rs = stmt.executeQuery()) { list = new ArrayList<>(); while (rs.next()) { String role = rs.getString(1); if (role != null) { list.add(role.trim()); } } return list; } catch(SQLException e) { containerLog.error( sm.getString("dataSourceRealm.getRoles.exception", username), e); } return null; }
stmt = roles(dbConnection, username); rs = stmt.executeQuery(); list = new ArrayList();
/** * Return the password associated with the given principal's user name. */ protected String getPassword(String username) { Connection dbConnection = null; // Ensure that we have an open database connection dbConnection = open(); if (dbConnection == null) { return null; } try { return getPassword(dbConnection, username); } finally { close(dbConnection); } }
/** * Return the roles associated with the given user name. * @param username Username for which roles should be retrieved */ protected ArrayList<String> getRoles(String username) { Connection dbConnection = null; // Ensure that we have an open database connection dbConnection = open(); if (dbConnection == null) { return null; } try { return getRoles(dbConnection, username); } finally { close(dbConnection); } }
String credentials) { String dbCredentials = getPassword(dbConnection, username); if (hasMessageDigest()) { validated = (digest(credentials).equalsIgnoreCase(dbCredentials)); } else validated = (digest(credentials).equals(dbCredentials)); ArrayList<String> list = getRoles(dbConnection, username);
String dbCredentials = getPassword(dbConnection, username); getCredentialHandler().mutate(credentials); boolean validated = getCredentialHandler().matches(credentials, dbCredentials); ArrayList<String> list = getRoles(dbConnection, username);
/** * Return the password associated with the given principal's user name. * @param dbConnection The database connection to be used * @param username Username for which password should be retrieved * @return the password for the specified user */ protected String getPassword(Connection dbConnection, String username) { String dbCredentials = null; try (PreparedStatement stmt = credentials(dbConnection, username); ResultSet rs = stmt.executeQuery()) { if (rs.next()) { dbCredentials = rs.getString(1); } return (dbCredentials != null) ? dbCredentials.trim() : null; } catch (SQLException e) { containerLog.error( sm.getString("dataSourceRealm.getPassword.exception", username), e); } return null; }
/** * Return the roles associated with the given user name * @param dbConnection The database connection to be used * @param username User name for which roles should be retrieved * @return an array list of the role names */ protected ArrayList<String> getRoles(Connection dbConnection, String username) { if (allRolesMode != AllRolesMode.STRICT_MODE && !isRoleStoreDefined()) { // Using an authentication only configuration and no role store has // been defined so don't spend cycles looking return null; } ArrayList<String> list = null; try (PreparedStatement stmt = roles(dbConnection, username); ResultSet rs = stmt.executeQuery()) { list = new ArrayList<>(); while (rs.next()) { String role = rs.getString(1); if (role != null) { list.add(role.trim()); } } return list; } catch(SQLException e) { containerLog.error( sm.getString("dataSourceRealm.getRoles.exception", username), e); } return null; }
stmt = roles(dbConnection, username); rs = stmt.executeQuery(); list = new ArrayList<String>();
/** * Create a new DataSource Realm. * * @param parent MBean Name of the associated parent component * @param dataSourceName the datasource name * @param roleNameCol the column name for the role names * @param userCredCol the column name for the user credentials * @param userNameCol the column name for the user names * @param userRoleTable the table name for the roles table * @param userTable the table name for the users * @return the object name of the created realm * @exception Exception if an MBean cannot be created or registered */ public String createDataSourceRealm(String parent, String dataSourceName, String roleNameCol, String userCredCol, String userNameCol, String userRoleTable, String userTable) throws Exception { // Create a new DataSourceRealm instance DataSourceRealm realm = new DataSourceRealm(); realm.setDataSourceName(dataSourceName); realm.setRoleNameCol(roleNameCol); realm.setUserCredCol(userCredCol); realm.setUserNameCol(userNameCol); realm.setUserRoleTable(userRoleTable); realm.setUserTable(userTable); // Add the new instance to its parent component return addRealmToParent(parent, realm); }
/** * Return the Principal associated with the given user name. */ @Override protected Principal getPrincipal(String username) { Connection dbConnection = open(); if (dbConnection == null) { return new GenericPrincipal(username, null, null); } try { return (new GenericPrincipal(username, getPassword(dbConnection, username), getRoles(dbConnection, username))); } finally { close(dbConnection); } }