I am trying to extend the user authentication example, which is also presented here , so that multiple users can login to the server. I would also like to assign a different home directory for each user. So far, I haven't been able to find any such utility provided by the Apache SSHD API , so I have tried the following workaround, by using the utilities provided by the Apache FtpServer .
What I attempt to do is:
create a PasswordAuthenticator that makes use of the UserManager in its authenticate method, as follows:
public class MyPasswordAuthenticator implements PasswordAuthenticator { private UserManager userManager; public MyPasswordAuthenticator(){ this.userManager=null; } public MyPasswordAuthenticator(UserManager manager) { this.userManager=manager; } @Override public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException { if (this.userManager==null) return false; User usr=null; try { usr = userManager.getUserByName(username); } catch (FtpException e) { e.printStackTrace(); } if (usr==null) return false; else{ String pass=usr.getPassword(); return password.equals(pass); } } }
However, the usr.getPassword()
returns null, even though a) the password fields in the property file do have values b) I have checked the functions getName()
and getHomeDirectory()
and they return their respective String values.
My question is, why does this happen and what should be done to fix this?
我找到了一种使其工作的方法,它是:
usr = this.userManager.authenticate(new UsernamePasswordAuthentication(username, password));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.