@Test public void testAddUser() throws Exception { SqlUser sqlUser1 = (SqlUser) sqlUserRepository.addUser("abc", "test user1", null, "", new String[0]); assertEquals("abc", sqlUser1.getUsername()); assertEquals("test user1", sqlUser1.getDisplayName()); assertEquals(UserStatus.OFFLINE, sqlUser1.getUserStatus()); SqlUser sqlUser2 = (SqlUser) sqlUserRepository.addUser("def", "test user2", null, null, new String[0]); assertNull(sqlUser2.getPasswordHash()); assertNull(sqlUser2.getPasswordSalt()); assertEquals("def", sqlUser2.getUsername()); assertEquals("test user2", sqlUser2.getDisplayName()); assertEquals(UserStatus.OFFLINE, sqlUser2.getUserStatus()); SqlUser sqlUser3 = (SqlUser) sqlUserRepository.addUser("ghi", "test user3", null, "&gdja81", new String[0]); byte[] salt = sqlUser3.getPasswordSalt(); byte[] passwordHash = UserPasswordUtil.hashPassword("&gdja81", salt); assertTrue(UserPasswordUtil.validatePassword("&gdja81", salt, passwordHash)); assertEquals("ghi", sqlUser3.getUsername()); assertEquals("test user3", sqlUser3.getDisplayName()); assertEquals(UserStatus.OFFLINE, sqlUser3.getUserStatus()); }
@Override public User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations) { username = formatUsername(username); displayName = displayName.trim(); Session session = sessionManager.getSession(); if (findByUsername(username) != null) { throw new LumifyException("User already exists"); } Transaction transaction = null; SqlUser newUser = null; try { transaction = session.beginTransaction(); newUser = new SqlUser(); String id = "USER_" + graph.getIdGenerator().nextId(); newUser.setUserId(id); newUser.setUsername(username); newUser.setDisplayName(displayName); newUser.setCreateDate(new Date()); newUser.setEmailAddress(emailAddress); if (password != null && !password.equals("")) { byte[] salt = UserPasswordUtil.getSalt(); byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt); newUser.setPassword(salt, passwordHash); } newUser.setUserStatus(UserStatus.OFFLINE); newUser.setPrivilegesString(Privilege.toString(getDefaultPrivileges())); LOGGER.debug("add %s to user table", displayName); session.save(newUser); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } throw new LumifyException("HibernateException while adding user", e); } userListenerUtil.fireNewUserAddedEvent(newUser); return newUser; }
SqlUserRepository extends UserRepository { @Override public User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations) { username = formatUsername(username); displayName = displayName.trim(); Session session = sessionManager.getSession(); if (findByUsername(username) != null) { throw new LumifyException("User already exists"); } Transaction transaction = null; SqlUser newUser = null; try { transaction = session.beginTransaction(); newUser = new SqlUser(); String id = "USER_" + graph.getIdGenerator().nextId(); newUser.setUserId(id); newUser.setUsername(username); newUser.setDisplayName(displayName); newUser.setCreateDate(new Date()); newUser.setEmailAddress(emailAddress); if (password != null && !password.equals("")) { byte[] salt = UserPasswordUtil.getSalt(); byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt); newUser.setPassword(salt, passwordHash); } newUser.setUserStatus(UserStatus.OFFLINE); newUser.setPrivilegesString(Privilege.toString(getDefaultPrivileges())); LOGGER.debug("add %s to user table", displayName); session.save(newUser); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } throw new LumifyException("HibernateException while adding user", e); } userListenerUtil.fireNewUserAddedEvent(newUser); return newUser; } }
SqlUserRepository extends UserRepository { @Override public User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations) { username = formatUsername(username); displayName = displayName.trim(); Session session = sessionManager.getSession(); if (findByUsername(username) != null) { throw new LumifyException("User already exists"); } Transaction transaction = null; SqlUser newUser = null; try { transaction = session.beginTransaction(); newUser = new SqlUser(); String id = "USER_" + graph.getIdGenerator().nextId(); newUser.setUserId(id); newUser.setUsername(username); newUser.setDisplayName(displayName); newUser.setCreateDate(new Date()); newUser.setEmailAddress(emailAddress); if (password != null && !password.equals("")) { byte[] salt = UserPasswordUtil.getSalt(); byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt); newUser.setPassword(salt, passwordHash); } newUser.setUserStatus(UserStatus.OFFLINE); newUser.setPrivilegesString(Privilege.toString(getDefaultPrivileges())); LOGGER.debug("add %s to user table", displayName); session.save(newUser); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } throw new LumifyException("HibernateException while adding user", e); } userListenerUtil.fireNewUserAddedEvent(newUser); return newUser; } @Inject  SqlUserRepository(final Configuration configuration,
                             final HibernateSessionManager sessionManager,
                             final AuthorizationRepository authorizationRepository,
                             final UserListenerUtil userListenerUtil,
                             final Graph graph); }
SqlUserRepository extends UserRepository { @Override public User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations) { username = formatUsername(username); displayName = displayName.trim(); Session session = sessionManager.getSession(); if (findByUsername(username) != null) { throw new LumifyException("User already exists"); } Transaction transaction = null; SqlUser newUser = null; try { transaction = session.beginTransaction(); newUser = new SqlUser(); String id = "USER_" + graph.getIdGenerator().nextId(); newUser.setUserId(id); newUser.setUsername(username); newUser.setDisplayName(displayName); newUser.setCreateDate(new Date()); newUser.setEmailAddress(emailAddress); if (password != null && !password.equals("")) { byte[] salt = UserPasswordUtil.getSalt(); byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt); newUser.setPassword(salt, passwordHash); } newUser.setUserStatus(UserStatus.OFFLINE); newUser.setPrivilegesString(Privilege.toString(getDefaultPrivileges())); LOGGER.debug("add %s to user table", displayName); session.save(newUser); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } throw new LumifyException("HibernateException while adding user", e); } userListenerUtil.fireNewUserAddedEvent(newUser); return newUser; } @Inject  SqlUserRepository(final Configuration configuration,
                             final HibernateSessionManager sessionManager,
                             final AuthorizationRepository authorizationRepository,
                             final UserListenerUtil userListenerUtil,
                             final Graph graph); @Override User findByUsername(String username); @Override Iterable<User> find(int skip, int limit); @Override Iterable<User> findByStatus(int skip, int limit, UserStatus status); @Override User findById(String userId); @Override User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations); @Override void setPassword(User user, String password); @Override boolean isPasswordValid(User user, String password); @Override void recordLogin(User user, String remoteAddr); @Override User setCurrentWorkspace(String userId, String workspaceId); @Override String getCurrentWorkspaceId(String userId); @Override void setUiPreferences(User user, JSONObject preferences); @Override User setStatus(String userId, UserStatus status); @Override void addAuthorization(User userUser, String auth); @Override void removeAuthorization(User userUser, String auth); @Override org.securegraph.Authorizations getAuthorizations(User user, String... additionalAuthorizations); @Override void setDisplayName(User user, String displayName); @Override void setEmailAddress(User user, String emailAddress); @Override Set<Privilege> getPrivileges(User user); @Override void delete(User user); @Override void setPrivileges(User user, Set<Privilege> privileges); @Override User findByPasswordResetToken(String token); @Override void setPasswordResetTokenAndExpirationDate(User user, String token, Date expirationDate); @Override void clearPasswordResetTokenAndExpirationDate(User user); }
SqlUserRepository extends UserRepository { @Override public User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations) { username = formatUsername(username); displayName = displayName.trim(); Session session = sessionManager.getSession(); if (findByUsername(username) != null) { throw new LumifyException("User already exists"); } Transaction transaction = null; SqlUser newUser = null; try { transaction = session.beginTransaction(); newUser = new SqlUser(); String id = "USER_" + graph.getIdGenerator().nextId(); newUser.setUserId(id); newUser.setUsername(username); newUser.setDisplayName(displayName); newUser.setCreateDate(new Date()); newUser.setEmailAddress(emailAddress); if (password != null && !password.equals("")) { byte[] salt = UserPasswordUtil.getSalt(); byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt); newUser.setPassword(salt, passwordHash); } newUser.setUserStatus(UserStatus.OFFLINE); newUser.setPrivilegesString(Privilege.toString(getDefaultPrivileges())); LOGGER.debug("add %s to user table", displayName); session.save(newUser); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } throw new LumifyException("HibernateException while adding user", e); } userListenerUtil.fireNewUserAddedEvent(newUser); return newUser; } @Inject  SqlUserRepository(final Configuration configuration,
                             final HibernateSessionManager sessionManager,
                             final AuthorizationRepository authorizationRepository,
                             final UserListenerUtil userListenerUtil,
                             final Graph graph); @Override User findByUsername(String username); @Override Iterable<User> find(int skip, int limit); @Override Iterable<User> findByStatus(int skip, int limit, UserStatus status); @Override User findById(String userId); @Override User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations); @Override void setPassword(User user, String password); @Override boolean isPasswordValid(User user, String password); @Override void recordLogin(User user, String remoteAddr); @Override User setCurrentWorkspace(String userId, String workspaceId); @Override String getCurrentWorkspaceId(String userId); @Override void setUiPreferences(User user, JSONObject preferences); @Override User setStatus(String userId, UserStatus status); @Override void addAuthorization(User userUser, String auth); @Override void removeAuthorization(User userUser, String auth); @Override org.securegraph.Authorizations getAuthorizations(User user, String... additionalAuthorizations); @Override void setDisplayName(User user, String displayName); @Override void setEmailAddress(User user, String emailAddress); @Override Set<Privilege> getPrivileges(User user); @Override void delete(User user); @Override void setPrivileges(User user, Set<Privilege> privileges); @Override User findByPasswordResetToken(String token); @Override void setPasswordResetTokenAndExpirationDate(User user, String token, Date expirationDate); @Override void clearPasswordResetTokenAndExpirationDate(User user);  }