James Moger
2014-03-14 aaecd8f2a36d2c0d780b42425aa57725fe708551
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) {
      SshDaemonClient client = session.getAttribute(SshDaemonClient.KEY);
      if (client.getUser() != 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.setUser(user);
         return true;
      }
      log.warn("could not authenticate {} for SSH using the supplied password", username);
      return false;
   }
}