geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r720415 - in /geronimo/gshell/trunk: gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/ gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/ gshell-support/gshell-security/
Date Tue, 25 Nov 2008 04:56:24 GMT
Author: jdillon
Date: Mon Nov 24 20:56:23 2008
New Revision: 720415

URL: http://svn.apache.org/viewvc?rev=720415&view=rev
Log:
Add JSecurity-based password auth

Added:
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/BogusPasswordAuthenticator.java
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
    geronimo/gshell/trunk/gshell-support/gshell-security/pom.xml

Modified: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/BogusPasswordAuthenticator.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/BogusPasswordAuthenticator.java?rev=720415&r1=720414&r2=720415&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/BogusPasswordAuthenticator.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/BogusPasswordAuthenticator.java
Mon Nov 24 20:56:23 2008
@@ -22,14 +22,14 @@
 import com.google.code.sshd.server.PasswordAuthenticator;
 
 /**
- * ???
+ * Bogus {@link PasswordAuthenticator}. 
  *
  * @version $Rev$ $Date$
  */
 public class BogusPasswordAuthenticator
     implements PasswordAuthenticator
 {
-   public Object authenticate(final String username, final String password) {
-       return (username != null && username.equals(password)) ? username : null;
-   }
+    public Object authenticate(final String username, final String password) {
+        return (username != null && username.equals(password)) ? username : null;
+    }
 }
\ No newline at end of file

Added: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java?rev=720415&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java
(added)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java
Mon Nov 24 20:56:23 2008
@@ -0,0 +1,61 @@
+/*
+ * 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.geronimo.gshell.commands.ssh;
+
+import com.google.code.sshd.server.PasswordAuthenticator;
+import org.jsecurity.SecurityUtils;
+import org.jsecurity.authc.AuthenticationException;
+import org.jsecurity.authc.UsernamePasswordToken;
+import org.jsecurity.subject.Subject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <a href="http://jsecurity.org">JSecurity</a> {@link PasswordAuthenticator}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JSecurityPasswordAuthenticator
+    implements PasswordAuthenticator
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    public Object authenticate(final String username, final String password) {
+        assert username != null;
+        assert password != null;
+        
+        Subject currentUser = SecurityUtils.getSubject();
+
+        if (!currentUser.isAuthenticated()) {
+            UsernamePasswordToken token = new UsernamePasswordToken(username, password);
+
+            try {
+                currentUser.login(token);
+                log.info("User [" + currentUser.getPrincipal() + "] logged in successfully");
+            }
+            catch (AuthenticationException e) {
+                log.error("Authentication failed: " + e, e);
+                return null;
+            }
+        }
+
+        return currentUser.getPrincipal();
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/JSecurityPasswordAuthenticator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml?rev=720415&r1=720414&r2=720415&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
Mon Nov 24 20:56:23 2008
@@ -81,4 +81,8 @@
 
     <bean name="passwordAuthenticator" class="org.apache.geronimo.gshell.commands.ssh.BogusPasswordAuthenticator"/>
 
+    <!--
+    <bean name="passwordAuthenticator" class="org.apache.geronimo.gshell.commands.ssh.JSecurityPasswordAuthenticator"/>
+    -->
+
 </beans>
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-support/gshell-security/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-security/pom.xml?rev=720415&r1=720414&r2=720415&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-security/pom.xml (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-security/pom.xml Mon Nov 24 20:56:23 2008
@@ -50,9 +50,9 @@
 
         <!--
         NOTE: The POM installed in central for this puppy are not valid, RC2 shows version
is RC1
-              and both have the file named *.pom.xml instead *.pom.
+              and both have the file named *.pom.xml instead *.pom.  0.9.0 is out but artifacts
are fucked.
         -->
-        
+
         <dependency>
             <groupId>org.jsecurity</groupId>
             <artifactId>jsecurity</artifactId>



Mime
View raw message