James Moger
2014-03-14 44e2ee1d05a9d455ae60dd64058b31f006d551b7
src/main/java/com/gitblit/transport/ssh/SshPasswordAuthenticator.java
@@ -19,6 +19,8 @@
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.session.ServerSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.manager.IAuthenticationManager;
import com.gitblit.models.UserModel;
@@ -30,6 +32,8 @@
 */
public class SshPasswordAuthenticator implements PasswordAuthenticator {
   protected final Logger log = LoggerFactory.getLogger(getClass());
   protected final IAuthenticationManager authManager;
   public SshPasswordAuthenticator(IAuthenticationManager authManager) {
@@ -38,13 +42,20 @@
   @Override
   public boolean authenticate(String username, String password, ServerSession session) {
      SshSession client = session.getAttribute(SshSession.KEY);
      if (client.getRemoteUser() != null) {
         log.info("{} has already authenticated!", username);
         return true;
      }
      username = username.toLowerCase(Locale.US);
      UserModel user = authManager.authenticate(username, password.toCharArray());
      if (user != null) {
         SshSession sd = session.getAttribute(SshSession.KEY);
         sd.authenticationSuccess(username);
         client.authenticationSuccess(username);
         return true;
      }
      log.warn("could not authenticate {} for SSH using the supplied password", username);
      return false;
   }
}