jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r762711 - in /incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH: src/com/ecyrd/jspwiki/auth/login/WikiCallbackHandler.java tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java
Date Wed, 08 Apr 2009 04:10:15 GMT
Author: ajaquith
Date: Tue Apr  7 11:51:23 2009
New Revision: 762711

URL: http://svn.apache.org/viewvc?rev=762711&view=rev
Log:
Added support in WikiCallbackHandler for HttpRequestCallback and WikiEngineCallback. This
means LoginModules used for JSPWiki integrated (custom) authentication can now access the
WikiEngine and the HTTP request. Thanks to Lou Peters and many, many others for bringing this
issue to my attention. Please test this function! This change has been forward-ported to the
(3.0) trunk. 

Modified:
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/auth/login/WikiCallbackHandler.java
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/auth/login/WikiCallbackHandler.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/auth/login/WikiCallbackHandler.java?rev=762711&r1=762710&r2=762711&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/auth/login/WikiCallbackHandler.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/auth/login/WikiCallbackHandler.java
Tue Apr  7 11:51:23 2009
@@ -22,18 +22,16 @@
 
 import java.io.IOException;
 
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.callback.*;
+import javax.servlet.http.HttpServletRequest;
 
-import com.ecyrd.jspwiki.auth.user.UserDatabase;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiSession;
 
 /**
  * Handles logins made from inside the wiki application, rather than via the web
  * container. This handler is instantiated in
- * {@link com.ecyrd.jspwiki.auth.AuthenticationManager#login(WikiSession, String, String)}.
+ * {@link com.ecyrd.jspwiki.auth.AuthenticationManager#login(WikiSession,HttpServletRequest,
String, String)}.
  * If container-managed authentication is used, the
  * {@link WebContainerCallbackHandler}is used instead. This callback handler is
  * designed to be used with {@link UserDatabaseLoginModule}.
@@ -42,22 +40,26 @@
  */
 public class WikiCallbackHandler implements CallbackHandler
 {
-    private final UserDatabase m_database;
+    private final HttpServletRequest m_request;
 
+    private final WikiEngine m_engine;
+    
     private final String       m_password;
 
     private final String       m_username;
 
     /**
      *  Create a new callback handler.
-     *  
-     *  @param database The Userdatabase to use
-     *  @param username The username
-     *  @param password The password
+     * @param engine the WikiEngine
+     * @param request the user's HTTP request. If passed as <code>null</code>,
+     *  later requests for {@link HttpRequestCallback} will return an UnsupportedCallbackException
+     * @param username the username
+     * @param password the password
      */
-    public WikiCallbackHandler( UserDatabase database, String username, String password )
+    public WikiCallbackHandler( WikiEngine engine, HttpServletRequest request, String username,
String password )
     {
-        m_database = database;
+        m_request = request;
+        m_engine = engine;
         m_username = username;
         m_password = password;
     }
@@ -72,9 +74,17 @@
         for( int i = 0; i < callbacks.length; i++ )
         {
             Callback callback = callbacks[i];
-            if ( callback instanceof UserDatabaseCallback )
+            if ( callback instanceof HttpRequestCallback )
             {
-                ( (UserDatabaseCallback) callback ).setUserDatabase( m_database );
+                ( (HttpRequestCallback) callback ).setRequest( m_request );
+            }
+            else if( callback instanceof WikiEngineCallback )
+            {
+                ( (WikiEngineCallback) callback ).setEngine( m_engine );
+            }
+            else if ( callback instanceof UserDatabaseCallback )
+            {
+                ( (UserDatabaseCallback) callback ).setUserDatabase( m_engine.getUserManager().getUserDatabase()
);
             }
             else if ( callback instanceof NameCallback )
             {

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java?rev=762711&r1=762710&r2=762711&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java
Tue Apr  7 11:51:23 2009
@@ -44,6 +44,8 @@
  */
 public class UserDatabaseLoginModuleTest extends TestCase
 {
+    WikiEngine m_engine;
+
     UserDatabase m_db;
 
     Subject      m_subject;
@@ -53,7 +55,7 @@
         try
         {
             // Log in with a user that isn't in the database
-            CallbackHandler handler = new WikiCallbackHandler( m_db, "user", "password" );
+            CallbackHandler handler = new WikiCallbackHandler( m_engine, null, "user", "password"
);
             LoginModule module = new UserDatabaseLoginModule();
             module.initialize( m_subject, handler, 
                               new HashMap<String, Object>(), 
@@ -68,7 +70,7 @@
             
             // Login with a user that IS in the database
             m_subject = new Subject();
-            handler = new WikiCallbackHandler( m_db, "janne", "myP@5sw0rd" );
+            handler = new WikiCallbackHandler( m_engine, null, "janne", "myP@5sw0rd" );
             module = new UserDatabaseLoginModule();
             module.initialize( m_subject, handler, 
                               new HashMap<String, Object>(), 
@@ -92,7 +94,7 @@
     {
         try
         {
-            CallbackHandler handler = new WikiCallbackHandler( m_db, "user", "password" );
+            CallbackHandler handler = new WikiCallbackHandler( m_engine, null, "user", "password"
);
             LoginModule module = new UserDatabaseLoginModule();
             module.initialize( m_subject, handler, 
                               new HashMap<String, Object>(), 
@@ -122,7 +124,7 @@
         Properties props = new Properties();
         props.load( TestEngine.findTestProperties() );
         props.put(XMLUserDatabase.PROP_USERDATABASE, "tests/etc/userdatabase.xml");
-        WikiEngine m_engine  = new TestEngine(props);
+        m_engine  = new TestEngine(props);
         m_db = new XMLUserDatabase();
         m_subject = new Subject();
         try



Mime
View raw message