authorities.add(new TransferRatePermission(1, 5));
user.setAuthorities(authorities);
userManager.save(user);
UserManager newUserManager = createUserManagerFactory().createUserManager();
User actualUser = newUserManager.getUserByName("newuser");
assertEquals(user.getName(), actualUser.getName());
assertNull(actualUser.getPassword());
assertEquals(user.getHomeDirectory(), actualUser.getHomeDirectory());
assertEquals(user.getEnabled(), actualUser.getEnabled());
assertNotNull(user.authorize(new WriteRequest()));
assertEquals(getMaxDownloadRate(user), getMaxDownloadRate(actualUser));
assertEquals(user.getMaxIdleTime(), actualUser.getMaxIdleTime());
assertEquals(getMaxLoginNumber(user), getMaxLoginNumber(actualUser));
assertEquals(getMaxLoginPerIP(user), getMaxLoginPerIP(actualUser));
assertEquals(getMaxUploadRate(user), getMaxUploadRate(actualUser));
// verify the password
assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));
try {
newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "dummy"));
fail("Must throw AuthenticationFailedException");
} catch(AuthenticationFailedException e) {
// ok
}
// save without updating the users password (password==null)
userManager.save(user);
newUserManager = createUserManagerFactory().createUserManager();
assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));
try {
newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "dummy"));
fail("Must throw AuthenticationFailedException");
} catch(AuthenticationFailedException e) {
// ok
}
// save and update the users password
user.setPassword("newerpw");
userManager.save(user);
newUserManager = createUserManagerFactory().createUserManager();
assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newerpw")));
try {
newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw"));
fail("Must throw AuthenticationFailedException");
} catch(AuthenticationFailedException e) {
// ok
}