You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/04/14 22:50:11 UTC

svn commit: r1739191 - in /tomcat/trunk: java/org/apache/catalina/authenticator/jaspic/ test/org/apache/catalina/authenticator/jaspic/ webapps/docs/

Author: markt
Date: Thu Apr 14 20:50:11 2016
New Revision: 1739191

URL: http://svn.apache.org/viewvc?rev=1739191&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=59284
Allow the Tomcat provided JASPIC SimpleServerAuthConfig to pick up module confiuration properties from either the property set passed to its constructor or from the properties passed in the call to getAuthContext.
Based on a patch by Thomas Maslen.

Added:
    tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestSimpleServerAuthConfig.java   (with props)
    tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterMessageInfo.java   (with props)
    tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterServerAuthModuleA.java   (with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/SimpleServerAuthConfig.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/SimpleServerAuthConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/SimpleServerAuthConfig.java?rev=1739191&r1=1739190&r2=1739191&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/SimpleServerAuthConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/SimpleServerAuthConfig.java Thu Apr 14 20:50:11 2016
@@ -102,16 +102,14 @@ public class SimpleServerAuthConfig impl
                     if (this.properties != null) {
                         mergedProperties.putAll(this.properties);
                     }
-                    if (properties == null) {
-                        throw new AuthException(sm.getString("simpleServerAuthConfig.noModules"));
-                    } else {
+                    if (properties != null) {
                         mergedProperties.putAll(properties);
                     }
 
                     List<ServerAuthModule> modules = new ArrayList<>();
                     int moduleIndex = 1;
                     String key = SERVER_AUTH_MODULE_KEY_PREFIX + moduleIndex;
-                    String moduleClassName = (String) properties.get(key);
+                    String moduleClassName = mergedProperties.get(key);
                     while (moduleClassName != null) {
                         try {
                             Class<?> clazz = Class.forName(moduleClassName);
@@ -127,7 +125,7 @@ public class SimpleServerAuthConfig impl
                         // Look for the next module
                         moduleIndex++;
                         key = SERVER_AUTH_MODULE_KEY_PREFIX + moduleIndex;
-                        moduleClassName = (String) properties.get(key);
+                        moduleClassName = mergedProperties.get(key);
                     }
 
                     if (modules.size() == 0) {

Added: tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestSimpleServerAuthConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestSimpleServerAuthConfig.java?rev=1739191&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestSimpleServerAuthConfig.java (added)
+++ tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestSimpleServerAuthConfig.java Thu Apr 14 20:50:11 2016
@@ -0,0 +1,74 @@
+/**
+ *  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.catalina.authenticator.jaspic;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.config.ServerAuthConfig;
+import javax.security.auth.message.config.ServerAuthContext;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSimpleServerAuthConfig {
+
+    private static final String SERVER_AUTH_MODULE_KEY_PREFIX =
+            "org.apache.catalina.authenticator.jaspic.ServerAuthModule.";
+
+    private static final Map<String,String> CONFIG_PROPERTIES;
+    static {
+        CONFIG_PROPERTIES = new HashMap<>();
+        CONFIG_PROPERTIES.put(SERVER_AUTH_MODULE_KEY_PREFIX + "1",
+                TesterServerAuthModuleA.class.getName());
+    }
+
+    @Test
+    public void testConfigOnServerAuthConfig() throws Exception {
+        ServerAuthConfig serverAuthConfig =
+                new SimpleServerAuthConfig(null,  null, null, CONFIG_PROPERTIES);
+        ServerAuthContext serverAuthContext = serverAuthConfig.getAuthContext(null, null, null);
+
+        validateServerAuthContext(serverAuthContext);
+    }
+
+
+    @Test
+    public void testConfigOnGetAuthContext() throws Exception {
+        ServerAuthConfig serverAuthConfig = new SimpleServerAuthConfig(null,  null, null, null);
+        ServerAuthContext serverAuthContext =
+                serverAuthConfig.getAuthContext(null, null, CONFIG_PROPERTIES);
+
+        validateServerAuthContext(serverAuthContext);
+    }
+
+
+    @Test(expected=AuthException.class)
+    public void testConfigNone() throws Exception {
+        ServerAuthConfig serverAuthConfig = new SimpleServerAuthConfig(null,  null, null, null);
+        serverAuthConfig.getAuthContext(null, null, null);
+    }
+
+
+    private void validateServerAuthContext(ServerAuthContext serverAuthContext) throws Exception {
+        MessageInfo msgInfo = new TesterMessageInfo();
+        serverAuthContext.cleanSubject(msgInfo, null);
+        Assert.assertEquals("init()-cleanSubject()-", msgInfo.getMap().get("trace"));
+    }
+}

Propchange: tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestSimpleServerAuthConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterMessageInfo.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterMessageInfo.java?rev=1739191&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterMessageInfo.java (added)
+++ tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterMessageInfo.java Thu Apr 14 20:50:11 2016
@@ -0,0 +1,55 @@
+/**
+ *  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.catalina.authenticator.jaspic;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.message.MessageInfo;
+
+public class TesterMessageInfo implements MessageInfo {
+
+    private Object requestMessage;
+    private Object responseMessage;
+    private final Map<String,String> map = new HashMap<>();
+
+    @Override
+    public Object getRequestMessage() {
+        return requestMessage;
+    }
+
+    @Override
+    public Object getResponseMessage() {
+        return responseMessage;
+    }
+
+    @Override
+    public void setRequestMessage(Object request) {
+        requestMessage = request;
+    }
+
+    @Override
+    public void setResponseMessage(Object response) {
+        responseMessage = response;
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    public Map getMap() {
+        return map;
+    }
+}

Propchange: tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterMessageInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterServerAuthModuleA.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterServerAuthModuleA.java?rev=1739191&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterServerAuthModuleA.java (added)
+++ tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterServerAuthModuleA.java Thu Apr 14 20:50:11 2016
@@ -0,0 +1,64 @@
+/**
+ *  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.catalina.authenticator.jaspic;
+
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.AuthStatus;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.MessagePolicy;
+import javax.security.auth.message.module.ServerAuthModule;
+
+public class TesterServerAuthModuleA implements ServerAuthModule {
+
+    private StringBuilder trace = new StringBuilder("init()-");
+
+    @Override
+    public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
+            Subject serviceSubject) throws AuthException {
+        return null;
+    }
+
+    @Override
+    public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject)
+            throws AuthException {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException {
+        trace.append("cleanSubject()-");
+        messageInfo.getMap().put("trace", trace.toString());
+    }
+
+    @Override
+    public void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy,
+            CallbackHandler handler, @SuppressWarnings("rawtypes") Map options)
+                    throws AuthException {
+        // NO-OP
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    public Class[] getSupportedMessageTypes() {
+        return null;
+    }
+}

Propchange: tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TesterServerAuthModuleA.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1739191&r1=1739190&r2=1739191&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Apr 14 20:50:11 2016
@@ -133,6 +133,13 @@
         express a preference, use the server order to determine the preferred
         format. Based on a patch by gmokki. (markt)
       </add>
+      <fix>
+        <bug>59284</bug>: Allow the Tomcat provided JASPIC
+        <code>SimpleServerAuthConfig</code> to pick up module confiuration
+        properties from either the property set passed to its constructor or
+        from the properties passed in the call to <code>getAuthContext</code>.
+        Based on a patch by Thomas Maslen. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org