@Test(expectedExceptions = LoginException.class) public void testLookUpFakeUser() throws Exception { Authenticator connector = new Authenticator(connection); connector.lookUpUser("This User Doesn't Exist."); }
public User lookUpUser(String username) throws LoginException { try (ResultSet results = makeUserQuery(username)) { if (!results.next()) { throw new LoginException("User " + username + " does not exist."); } boolean loggedIn = results.getBoolean(LOGGED_IN); String salt = results.getString(SALT); String dbPass = results.getString(PASSWORD); User user = new User(); user.setUsername(username); user.setPassword(dbPass); user.setSalt(salt); user.setLoggedIn(loggedIn); return user; } catch (SQLException e) { throw new LoginException("Unable to retrieve user " + username + " because of SQL Exception.", e); } }
Authenticator { public User lookUpUser(String username) throws LoginException { try (ResultSet results = makeUserQuery(username)) { if (!results.next()) { throw new LoginException("User " + username + " does not exist."); } boolean loggedIn = results.getBoolean(LOGGED_IN); String salt = results.getString(SALT); String dbPass = results.getString(PASSWORD); User user = new User(); user.setUsername(username); user.setPassword(dbPass); user.setSalt(salt); user.setLoggedIn(loggedIn); return user; } catch (SQLException e) { throw new LoginException("Unable to retrieve user " + username + " because of SQL Exception.", e); } } }
Authenticator { public User lookUpUser(String username) throws LoginException { try (ResultSet results = makeUserQuery(username)) { if (!results.next()) { throw new LoginException("User " + username + " does not exist."); } boolean loggedIn = results.getBoolean(LOGGED_IN); String salt = results.getString(SALT); String dbPass = results.getString(PASSWORD); User user = new User(); user.setUsername(username); user.setPassword(dbPass); user.setSalt(salt); user.setLoggedIn(loggedIn); return user; } catch (SQLException e) { throw new LoginException("Unable to retrieve user " + username + " because of SQL Exception.", e); } } Authenticator(Connection dbConnection); }
Authenticator { public User lookUpUser(String username) throws LoginException { try (ResultSet results = makeUserQuery(username)) { if (!results.next()) { throw new LoginException("User " + username + " does not exist."); } boolean loggedIn = results.getBoolean(LOGGED_IN); String salt = results.getString(SALT); String dbPass = results.getString(PASSWORD); User user = new User(); user.setUsername(username); user.setPassword(dbPass); user.setSalt(salt); user.setLoggedIn(loggedIn); return user; } catch (SQLException e) { throw new LoginException("Unable to retrieve user " + username + " because of SQL Exception.", e); } } Authenticator(Connection dbConnection); static String getSaltedSHA256String(String input, String salt); User logInUser(String username, String password); User lookUpUser(String username); Map<String, Object> lookUpUserProperties(String username); User logOutUser(String username); Object lookUpUserProperty(String username, String propertyName); static boolean isWrapperType(Class<?> clazz); }
Authenticator { public User lookUpUser(String username) throws LoginException { try (ResultSet results = makeUserQuery(username)) { if (!results.next()) { throw new LoginException("User " + username + " does not exist."); } boolean loggedIn = results.getBoolean(LOGGED_IN); String salt = results.getString(SALT); String dbPass = results.getString(PASSWORD); User user = new User(); user.setUsername(username); user.setPassword(dbPass); user.setSalt(salt); user.setLoggedIn(loggedIn); return user; } catch (SQLException e) { throw new LoginException("Unable to retrieve user " + username + " because of SQL Exception.", e); } } Authenticator(Connection dbConnection); static String getSaltedSHA256String(String input, String salt); User logInUser(String username, String password); User lookUpUser(String username); Map<String, Object> lookUpUserProperties(String username); User logOutUser(String username); Object lookUpUserProperty(String username, String propertyName); static boolean isWrapperType(Class<?> clazz); static final int HEX_CONVERSION_CONSTANT; }