You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2009/11/16 12:06:04 UTC
svn commit: r880705 - in /mina/sshd/trunk/sshd-core/src:
main/java/org/apache/sshd/server/ main/java/org/apache/sshd/server/auth/
main/java/org/apache/sshd/server/session/ test/resources/
Author: gnodet
Date: Mon Nov 16 11:06:02 2009
New Revision: 880705
URL: http://svn.apache.org/viewvc?rev=880705&view=rev
Log:
SSHD-53: make sure PublickeyAuthenticator and PasswordAuthenticator interfaces are consistent
Modified:
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
mina/sshd/trunk/sshd-core/src/test/resources/log4j.properties
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java?rev=880705&r1=880704&r2=880705&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java Mon Nov 16 11:06:02 2009
@@ -42,6 +42,6 @@
* is not finished yet
* @throws Exception if the authentication fails
*/
- boolean auth(ServerSession session, String username, Buffer buffer) throws Exception;
+ Boolean auth(ServerSession session, String username, Buffer buffer) throws Exception;
}
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java?rev=880705&r1=880704&r2=880705&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java Mon Nov 16 11:06:02 2009
@@ -39,7 +39,7 @@
}
}
- public boolean auth(ServerSession session, String username, Buffer buffer) {
+ public Boolean auth(ServerSession session, String username, Buffer buffer) {
return true;
}
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java?rev=880705&r1=880704&r2=880705&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java Mon Nov 16 11:06:02 2009
@@ -40,7 +40,7 @@
}
}
- public boolean auth(ServerSession session, String username, Buffer buffer) throws Exception {
+ public Boolean auth(ServerSession session, String username, Buffer buffer) throws Exception {
boolean newPassword = buffer.getBoolean();
if (newPassword) {
throw new IllegalStateException("Password changes are not supported");
@@ -52,11 +52,7 @@
private boolean checkPassword(ServerSession session, String username, String password) throws Exception {
PasswordAuthenticator auth = session.getServerFactoryManager().getPasswordAuthenticator();
if (auth != null) {
- if (auth.authenticate(username, password, session)) {
- return true;
- } else {
- throw new Exception("Authentication failed: bad username or password supplied");
- }
+ return auth.authenticate(username, password, session);
}
throw new Exception("No PasswordAuthenticator configured");
}
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java?rev=880705&r1=880704&r2=880705&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java Mon Nov 16 11:06:02 2009
@@ -46,7 +46,7 @@
}
}
- public boolean auth(ServerSession session, String username, Buffer buffer) throws Exception {
+ public Boolean auth(ServerSession session, String username, Buffer buffer) throws Exception {
boolean hasSig = buffer.getBoolean();
String alg = buffer.getString();
@@ -69,14 +69,14 @@
}
if (!authenticator.authenticate(username, key, session)) {
- throw new Exception("Unsupported key for user");
+ return false;
}
if (!hasSig) {
Buffer buf = session.createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_PK_OK);
buf.putString(alg);
buf.putRawBytes(buffer.array(), oldPos, 4 + len);
session.writePacket(buf);
- return false;
+ return null;
} else {
Buffer buf = new Buffer();
buf.putString(session.getKex().getH());
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java?rev=880705&r1=880704&r2=880705&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java Mon Nov 16 11:06:02 2009
@@ -315,31 +315,32 @@
String method = buffer.getString();
log.info("Authenticating user '{}' with method '{}'", username, method);
- Object identity = null;
+ Boolean authed = null;
NamedFactory<UserAuth> factory = NamedFactory.Utils.get(userAuthFactories, method);
if (factory != null) {
UserAuth auth = factory.create();
try {
- identity = auth.auth(this, username, buffer);
- if (identity == null) {
+ authed = auth.auth(this, username, buffer);
+ if (authed == null) {
// authentication is still ongoing
log.info("Authentication not finished");
return;
} else {
- log.info("Authentication succeeded");
+ log.info(authed ? "Authentication succeeded" : "Authentication failed");
}
} catch (Exception e) {
// Continue
+ authed = false;
log.info("Authentication failed: {}", e.getMessage());
}
} else {
log.info("Unsupported authentication method '{}'", method);
}
- if (identity != null) {
+ if (authed != null && authed) {
buffer = createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_SUCCESS);
writePacket(buffer);
state = State.Running;
- authed = true;
+ this.authed = true;
this.username = username;
unscheduleAuthTimer();
} else {
Modified: mina/sshd/trunk/sshd-core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/test/resources/log4j.properties?rev=880705&r1=880704&r2=880705&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/test/resources/log4j.properties (original)
+++ mina/sshd/trunk/sshd-core/src/test/resources/log4j.properties Mon Nov 16 11:06:02 2009
@@ -21,7 +21,7 @@
#
# The logging properties used during tests..
#
-log4j.rootLogger=DEBUG, stdout
+log4j.rootLogger=TRACE, stdout
#log4j.logger.org.apache.mina=TRACE
#log4j.logger.org.apache.sshd.common.channel.Window=DEBUG