Author: gnodet
Date: Tue Jan 20 10:41:45 2009
New Revision: 736062

URL: http://svn.apache.org/viewvc?rev=736062&view=rev
Log:
SSHD-11: Expose the ServerSession to PublickeyAuthenticators

Added:
    
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AttributeKey.java
Modified:
    
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AbstractSession.java
    
mina/sshd/trunk/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java
    
mina/sshd/trunk/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
    
mina/sshd/trunk/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java

Modified: 
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AbstractSession.java
URL: 
http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AbstractSession.java?rev=736062&r1=736061&r2=736062&view=diff
==============================================================================
--- 
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AbstractSession.java
 (original)
+++ 
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AbstractSession.java
 Tue Jan 20 10:41:45 2009
@@ -129,6 +129,7 @@
     protected int decoderLength;
     protected final Object encodeLock = new Object();
     protected final Object decodeLock = new Object();
+    protected final Map<AttributeKey<?>, Object> attributes = new 
ConcurrentHashMap<AttributeKey<?>, Object>();
 
     /**
      * Create a new session.
@@ -982,4 +983,26 @@
         return defaultValue;
     }
 
+    /**
+     * Returns the value of the user-defined attribute of this session.
+     *
+     * @param key the key of the attribute; must not be null.
+     * @return <tt>null</tt> if there is no attribute with the specified key
+     */
+    @SuppressWarnings("unchecked")
+    public <T> T getAttribute(AttributeKey<T> key) {
+        return (T)attributes.get(key);
+    }
+
+    /**
+     * Sets a user-defined attribute.
+     *
+     * @param key   the key of the attribute; must not be null.
+     * @param value the value of the attribute; must not be null.
+     * @return The old value of the attribute.  <tt>null</tt> if it is new.
+     */
+    @SuppressWarnings("unchecked")
+    public <T, E extends T> T setAttribute(AttributeKey<T> key, E value) {
+        return (T)attributes.put(key, value);
+    }
 }

Added: 
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AttributeKey.java
URL: 
http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AttributeKey.java?rev=736062&view=auto
==============================================================================
--- 
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AttributeKey.java 
(added)
+++ 
mina/sshd/trunk/src/main/java/org/apache/sshd/common/session/AttributeKey.java 
Tue Jan 20 10:41:45 2009
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.common.session;
+
+/**
+ * Type safe key for storage within the user attributes of {...@link 
AbstractSession}.
+ *
+ * @param T type of value stored in the attribute.
+ *
+ * @author <a href="mailto:d...@mina.apache.org";>Apache MINA SSHD Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeKey<T> {
+}

Modified: 
mina/sshd/trunk/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java
URL: 
http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java?rev=736062&r1=736061&r2=736062&view=diff
==============================================================================
--- 
mina/sshd/trunk/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java
 (original)
+++ 
mina/sshd/trunk/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java
 Tue Jan 20 10:41:45 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.sshd.server;
 
+import org.apache.sshd.server.session.ServerSession;
+
 import java.security.PublicKey;
 
 /**
@@ -28,6 +30,6 @@
  */
 public interface PublickeyAuthenticator {
 
-    boolean hasKey(String username, PublicKey key);
+    boolean hasKey(String username, PublicKey key, ServerSession session);
 
 }

Modified: 
mina/sshd/trunk/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
URL: 
http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java?rev=736062&r1=736061&r2=736062&view=diff
==============================================================================
--- 
mina/sshd/trunk/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
 (original)
+++ 
mina/sshd/trunk/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
 Tue Jan 20 10:41:45 2009
@@ -70,7 +70,7 @@
         }
 
         if (!hasSig) {
-            if (authenticator.hasKey(username, key)) {
+            if (authenticator.hasKey(username, key, session)) {
                 Buffer buf = 
session.createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_PK_OK);
                 buf.putString(alg);
                 buf.putRawBytes(buffer.array(), oldPos, 4 + len);
@@ -80,7 +80,7 @@
                 throw new Exception("Unsupported key for user");
             }
         } else {
-            if (!authenticator.hasKey(username, key)) {
+            if (!authenticator.hasKey(username, key, session)) {
                 throw new Exception("Unsupported key for user");
             }
             Buffer buf = new Buffer();

Modified: 
mina/sshd/trunk/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java
URL: 
http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java?rev=736062&r1=736061&r2=736062&view=diff
==============================================================================
--- 
mina/sshd/trunk/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java
 (original)
+++ 
mina/sshd/trunk/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java
 Tue Jan 20 10:41:45 2009
@@ -21,6 +21,7 @@
 import java.security.PublicKey;
 
 import org.apache.sshd.server.PublickeyAuthenticator;
+import org.apache.sshd.server.session.ServerSession;
 
 /**
  * TODO Add javadoc
@@ -30,7 +31,7 @@
  */
 public class BogusPublickeyAuthenticator implements PublickeyAuthenticator {
 
-    public boolean hasKey(String username, PublicKey key) {
+    public boolean hasKey(String username, PublicKey key, ServerSession 
session) {
         return true;
     }
 }


Reply via email to