@Test public void testSetPassword() throws Exception { User user = userMgr.createUser(testUserId, "pw"); List<String> pwds = new ArrayList<String>(); pwds.add("pw"); pwds.add(""); pwds.add("{sha1}pw"); Tree userTree = root.getTree(user.getPath()); for (String pw : pwds) { userMgr.setPassword(userTree, testUserId, pw, false); String pwHash = userTree.getProperty(UserConstants.REP_PASSWORD).getValue(Type.STRING); assertNotNull(pwHash); assertTrue(PasswordUtil.isSame(pwHash, pw)); } for (String pw : pwds) { userMgr.setPassword(userTree, testUserId, pw, true); String pwHash = userTree.getProperty(UserConstants.REP_PASSWORD).getValue(Type.STRING); assertNotNull(pwHash); if (!pw.startsWith("{")) { assertTrue(PasswordUtil.isSame(pwHash, pw)); } else { assertFalse(PasswordUtil.isSame(pwHash, pw)); assertEquals(pw, pwHash); } } }
void setPassword(@NotNull Tree userTree, @NotNull String userId, @NotNull String password, boolean isImport) throws RepositoryException { String pwHash; if (!isImport || PasswordUtil.isPlainTextPassword(password)) { try { pwHash = PasswordUtil.buildPasswordHash(password, config); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new RepositoryException(e); } } else { pwHash = password; } userTree.setProperty(UserConstants.REP_PASSWORD, pwHash); if (Utils.canHavePasswordExpired(userId, config) && setPasswordLastModified(userTree, isImport)) { Tree pwdTree = TreeUtil.getOrAddChild(userTree, UserConstants.REP_PWD, UserConstants.NT_REP_PASSWORD); pwdTree.setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, System.currentTimeMillis(), Type.LONG); } }
UserManagerImpl implements UserManager { void setPassword(@NotNull Tree userTree, @NotNull String userId, @NotNull String password, boolean isImport) throws RepositoryException { String pwHash; if (!isImport || PasswordUtil.isPlainTextPassword(password)) { try { pwHash = PasswordUtil.buildPasswordHash(password, config); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new RepositoryException(e); } } else { pwHash = password; } userTree.setProperty(UserConstants.REP_PASSWORD, pwHash); if (Utils.canHavePasswordExpired(userId, config) && setPasswordLastModified(userTree, isImport)) { Tree pwdTree = TreeUtil.getOrAddChild(userTree, UserConstants.REP_PWD, UserConstants.NT_REP_PASSWORD); pwdTree.setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, System.currentTimeMillis(), Type.LONG); } } }
UserManagerImpl implements UserManager { void setPassword(@NotNull Tree userTree, @NotNull String userId, @NotNull String password, boolean isImport) throws RepositoryException { String pwHash; if (!isImport || PasswordUtil.isPlainTextPassword(password)) { try { pwHash = PasswordUtil.buildPasswordHash(password, config); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new RepositoryException(e); } } else { pwHash = password; } userTree.setProperty(UserConstants.REP_PASSWORD, pwHash); if (Utils.canHavePasswordExpired(userId, config) && setPasswordLastModified(userTree, isImport)) { Tree pwdTree = TreeUtil.getOrAddChild(userTree, UserConstants.REP_PWD, UserConstants.NT_REP_PASSWORD); pwdTree.setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, System.currentTimeMillis(), Type.LONG); } } UserManagerImpl(@NotNull Root root,
                           @NotNull PartialValueFactory valueFactory,
                           @NotNull SecurityProvider securityProvider); }
UserManagerImpl implements UserManager { void setPassword(@NotNull Tree userTree, @NotNull String userId, @NotNull String password, boolean isImport) throws RepositoryException { String pwHash; if (!isImport || PasswordUtil.isPlainTextPassword(password)) { try { pwHash = PasswordUtil.buildPasswordHash(password, config); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new RepositoryException(e); } } else { pwHash = password; } userTree.setProperty(UserConstants.REP_PASSWORD, pwHash); if (Utils.canHavePasswordExpired(userId, config) && setPasswordLastModified(userTree, isImport)) { Tree pwdTree = TreeUtil.getOrAddChild(userTree, UserConstants.REP_PWD, UserConstants.NT_REP_PASSWORD); pwdTree.setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, System.currentTimeMillis(), Type.LONG); } } UserManagerImpl(@NotNull Root root,
                           @NotNull PartialValueFactory valueFactory,
                           @NotNull SecurityProvider securityProvider); @Nullable @Override Authorizable getAuthorizable(@NotNull String id); @Nullable @Override T getAuthorizable(@NotNull String id, @NotNull Class<T> authorizableClass); @Nullable @Override Authorizable getAuthorizable(@NotNull Principal principal); @Nullable @Override Authorizable getAuthorizableByPath(@NotNull String path); @NotNull @Override Iterator<Authorizable> findAuthorizables(@NotNull String relPath, @Nullable String value); @NotNull @Override Iterator<Authorizable> findAuthorizables(@NotNull String relPath, @Nullable String value, int searchType); @NotNull @Override Iterator<Authorizable> findAuthorizables(@NotNull Query query); @NotNull @Override User createUser(@NotNull final String userID, @Nullable String password); @NotNull @Override User createUser(@NotNull String userID, @Nullable String password, @NotNull Principal principal,
                           @Nullable String intermediatePath); @NotNull @Override User createSystemUser(@NotNull String userID, @Nullable String intermediatePath); @NotNull @Override Group createGroup(@NotNull String groupId); @NotNull @Override Group createGroup(@NotNull Principal principal); @NotNull @Override Group createGroup(@NotNull Principal principal, @Nullable String intermediatePath); @NotNull @Override Group createGroup(@NotNull String groupID, @NotNull Principal principal, @Nullable String intermediatePath); @Override boolean isAutoSave(); @Override void autoSave(boolean enable); @Nullable Authorizable getAuthorizable(@Nullable Tree tree); }
UserManagerImpl implements UserManager { void setPassword(@NotNull Tree userTree, @NotNull String userId, @NotNull String password, boolean isImport) throws RepositoryException { String pwHash; if (!isImport || PasswordUtil.isPlainTextPassword(password)) { try { pwHash = PasswordUtil.buildPasswordHash(password, config); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new RepositoryException(e); } } else { pwHash = password; } userTree.setProperty(UserConstants.REP_PASSWORD, pwHash); if (Utils.canHavePasswordExpired(userId, config) && setPasswordLastModified(userTree, isImport)) { Tree pwdTree = TreeUtil.getOrAddChild(userTree, UserConstants.REP_PWD, UserConstants.NT_REP_PASSWORD); pwdTree.setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, System.currentTimeMillis(), Type.LONG); } } UserManagerImpl(@NotNull Root root,
                           @NotNull PartialValueFactory valueFactory,
                           @NotNull SecurityProvider securityProvider); @Nullable @Override Authorizable getAuthorizable(@NotNull String id); @Nullable @Override T getAuthorizable(@NotNull String id, @NotNull Class<T> authorizableClass); @Nullable @Override Authorizable getAuthorizable(@NotNull Principal principal); @Nullable @Override Authorizable getAuthorizableByPath(@NotNull String path); @NotNull @Override Iterator<Authorizable> findAuthorizables(@NotNull String relPath, @Nullable String value); @NotNull @Override Iterator<Authorizable> findAuthorizables(@NotNull String relPath, @Nullable String value, int searchType); @NotNull @Override Iterator<Authorizable> findAuthorizables(@NotNull Query query); @NotNull @Override User createUser(@NotNull final String userID, @Nullable String password); @NotNull @Override User createUser(@NotNull String userID, @Nullable String password, @NotNull Principal principal,
                           @Nullable String intermediatePath); @NotNull @Override User createSystemUser(@NotNull String userID, @Nullable String intermediatePath); @NotNull @Override Group createGroup(@NotNull String groupId); @NotNull @Override Group createGroup(@NotNull Principal principal); @NotNull @Override Group createGroup(@NotNull Principal principal, @Nullable String intermediatePath); @NotNull @Override Group createGroup(@NotNull String groupID, @NotNull Principal principal, @Nullable String intermediatePath); @Override boolean isAutoSave(); @Override void autoSave(boolean enable); @Nullable Authorizable getAuthorizable(@Nullable Tree tree);  }