2323import java .security .KeyPair ;
2424import java .security .KeyPairGenerator ;
2525import java .text .MessageFormat ;
26+ import java .util .List ;
2627import java .util .concurrent .atomic .AtomicBoolean ;
2728
2829import org .apache .sshd .common .io .IoServiceFactoryFactory ;
@@ -55,6 +56,13 @@ public class SshDaemon {
5556
5657 private final Logger log = LoggerFactory .getLogger (SshDaemon .class );
5758
59+ private static final String AUTH_PUBLICKEY = "publickey" ;
60+ private static final String AUTH_PASSWORD = "password" ;
61+ private static final String AUTH_KBD_INTERACTIVE = "keyboard-interactive" ;
62+ private static final String AUTH_GSSAPI = "gssapi-with-mic" ;
63+
64+
65+
5866 public static enum SshSessionBackend {
5967 MINA , NIO2
6068 }
@@ -97,9 +105,6 @@ public SshDaemon(IGitblit gitblit, WorkQueue workQueue) {
97105 FileKeyPairProvider hostKeyPairProvider = new FileKeyPairProvider ();
98106 hostKeyPairProvider .setFiles (new String [] { rsaKeyStore .getPath (), dsaKeyStore .getPath (), dsaKeyStore .getPath () });
99107
100- // Client public key authenticator
101- SshKeyAuthenticator keyAuthenticator =
102- new SshKeyAuthenticator (gitblit .getPublicKeyManager (), gitblit );
103108
104109 // Configure the preferred SSHD backend
105110 String sshBackendStr = settings .getString (Keys .git .sshBackend ,
@@ -125,11 +130,34 @@ public SshDaemon(IGitblit gitblit, WorkQueue workQueue) {
125130 sshd .setPort (addr .getPort ());
126131 sshd .setHost (addr .getHostName ());
127132 sshd .setKeyPairProvider (hostKeyPairProvider );
128- sshd .setPublickeyAuthenticator (new CachingPublicKeyAuthenticator (keyAuthenticator ));
129- sshd .setPasswordAuthenticator (new UsernamePasswordAuthenticator (gitblit ));
130- if (settings .getBoolean (Keys .git .sshWithKrb5 , false )) {
133+
134+ List <String > authMethods = settings .getStrings (Keys .git .sshAuthenticationMethods );
135+ if (authMethods .isEmpty ()) {
136+ authMethods .add (AUTH_PUBLICKEY );
137+ authMethods .add (AUTH_PASSWORD );
138+ }
139+ // Keep backward compatibility with old setting files that use the git.sshWithKrb5 setting.
140+ if (settings .getBoolean ("git.sshWithKrb5" , false ) && !authMethods .contains (AUTH_GSSAPI )) {
141+ authMethods .add (AUTH_GSSAPI );
142+ log .warn ("git.sshWithKrb5 is obsolete!" );
143+ log .warn ("Please add {} to {} in gitblit.properties!" , AUTH_GSSAPI , Keys .git .sshAuthenticationMethods );
144+ settings .overrideSetting (Keys .git .sshAuthenticationMethods ,
145+ settings .getString (Keys .git .sshAuthenticationMethods , AUTH_PUBLICKEY + " " + AUTH_PASSWORD ) + " " + AUTH_GSSAPI );
146+ }
147+ if (authMethods .contains (AUTH_PUBLICKEY )) {
148+ SshKeyAuthenticator keyAuthenticator = new SshKeyAuthenticator (gitblit .getPublicKeyManager (), gitblit );
149+ sshd .setPublickeyAuthenticator (new CachingPublicKeyAuthenticator (keyAuthenticator ));
150+ log .info ("SSH: adding public key authentication method." );
151+ }
152+ if (authMethods .contains (AUTH_PASSWORD ) || authMethods .contains (AUTH_KBD_INTERACTIVE )) {
153+ sshd .setPasswordAuthenticator (new UsernamePasswordAuthenticator (gitblit ));
154+ log .info ("SSH: adding password authentication method." );
155+ }
156+ if (authMethods .contains (AUTH_GSSAPI )) {
131157 sshd .setGSSAuthenticator (new SshKrbAuthenticator (settings , gitblit ));
158+ log .info ("SSH: adding GSSAPI authentication method." );
132159 }
160+
133161 sshd .setSessionFactory (new SshServerSessionFactory ());
134162 sshd .setFileSystemFactory (new DisabledFilesystemFactory ());
135163 sshd .setTcpipForwardingFilter (new NonForwardingFilter ());
0 commit comments