23
23
import java .security .KeyPair ;
24
24
import java .security .KeyPairGenerator ;
25
25
import java .text .MessageFormat ;
26
+ import java .util .List ;
26
27
import java .util .concurrent .atomic .AtomicBoolean ;
27
28
28
29
import org .apache .sshd .common .io .IoServiceFactoryFactory ;
@@ -55,6 +56,13 @@ public class SshDaemon {
55
56
56
57
private final Logger log = LoggerFactory .getLogger (SshDaemon .class );
57
58
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
+
58
66
public static enum SshSessionBackend {
59
67
MINA , NIO2
60
68
}
@@ -97,9 +105,6 @@ public SshDaemon(IGitblit gitblit, WorkQueue workQueue) {
97
105
FileKeyPairProvider hostKeyPairProvider = new FileKeyPairProvider ();
98
106
hostKeyPairProvider .setFiles (new String [] { rsaKeyStore .getPath (), dsaKeyStore .getPath (), dsaKeyStore .getPath () });
99
107
100
- // Client public key authenticator
101
- SshKeyAuthenticator keyAuthenticator =
102
- new SshKeyAuthenticator (gitblit .getPublicKeyManager (), gitblit );
103
108
104
109
// Configure the preferred SSHD backend
105
110
String sshBackendStr = settings .getString (Keys .git .sshBackend ,
@@ -125,11 +130,34 @@ public SshDaemon(IGitblit gitblit, WorkQueue workQueue) {
125
130
sshd .setPort (addr .getPort ());
126
131
sshd .setHost (addr .getHostName ());
127
132
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 )) {
131
157
sshd .setGSSAuthenticator (new SshKrbAuthenticator (settings , gitblit ));
158
+ log .info ("SSH: adding GSSAPI authentication method." );
132
159
}
160
+
133
161
sshd .setSessionFactory (new SshServerSessionFactory ());
134
162
sshd .setFileSystemFactory (new DisabledFilesystemFactory ());
135
163
sshd .setTcpipForwardingFilter (new NonForwardingFilter ());
0 commit comments