3

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:

  1. create a UserManager object to manage a list of users and store their information in a property file, in a way similar to this example
  2. 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?

Community
  • 1
  • 1
fyts
  • 493
  • 5
  • 12
  • There's no actual implementation of `PasswordAuthenticator` for multi-user server in Apache SSHD. You are supposed to implement your own. It's not a workaround. It's a part of the implementation. – Martin Prikryl Mar 10 '16 at 09:11
  • 1
    So your actual question is, why the your implementation of the `UserManager` interface is not working. But didn't show us anything about its implementation. – Martin Prikryl Mar 10 '16 at 09:13
  • You are actually asking two completely unrelated questions. Split them in two posts. Or decide which of them you want to ask. – Martin Prikryl Mar 10 '16 at 09:14
  • You are correct about the implementation, I am using the `PropertiesUserManager`. I have located the problem, this class loads all properties of a `User` in its `getUserByName` function, except from its password. I'll try to work it out, thanks. – fyts Mar 10 '16 at 11:37
  • I have found a way to make it work, it is: `usr = this.userManager.authenticate(new UsernamePasswordAuthentication(username, password));` – fyts Mar 10 '16 at 14:54

1 Answers1

2

I have found a way to make it work, it is:

usr = this.userManager.authenticate(new UsernamePasswordAuthentication(username, password));
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
fyts
  • 493
  • 5
  • 12