| | |
| | | |
| | | 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; |
| | |
| | | */ |
| | | public class SshPasswordAuthenticator implements PasswordAuthenticator { |
| | | |
| | | protected final Logger log = LoggerFactory.getLogger(getClass()); |
| | | |
| | | protected final IAuthenticationManager authManager; |
| | | |
| | | public SshPasswordAuthenticator(IAuthenticationManager authManager) { |
| | |
| | | |
| | | @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; |
| | | } |
| | | } |