Author: markt
Date: Mon Nov 20 18:13:15 2017
New Revision: 1815826

URL: http://svn.apache.org/viewvc?rev=1815826&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=61781
Enable JASPIC provider registrations to be persisted when the layer and/or 
application context are null.
Patch provided by Lazar.
This closes #89

Added:
    tomcat/trunk/test/conf/jaspic-test-04.xml   (with props)
Modified:
    tomcat/trunk/conf/jaspic-providers.xsd
    
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/conf/jaspic-providers.xsd
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/conf/jaspic-providers.xsd?rev=1815826&r1=1815825&r2=1815826&view=diff
==============================================================================
--- tomcat/trunk/conf/jaspic-providers.xsd (original)
+++ tomcat/trunk/conf/jaspic-providers.xsd Mon Nov 20 18:13:15 2017
@@ -36,8 +36,8 @@
               </xs:element>
             </xs:sequence>
             <xs:attribute name="className" use="required" type="xs:string" />
-            <xs:attribute name="layer" use="required" type="xs:string" />
-            <xs:attribute name="appContext" use="required" type="xs:string" />
+            <xs:attribute name="layer" type="xs:string" />
+            <xs:attribute name="appContext" type="xs:string" />
             <xs:attribute name="description" type="xs:string" />
           </xs:complexType>
         </xs:element>

Modified: 
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java?rev=1815826&r1=1815825&r2=1815826&view=diff
==============================================================================
--- 
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java
 (original)
+++ 
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java
 Mon Nov 20 18:13:15 2017
@@ -123,14 +123,9 @@ final class PersistentProviderRegistrati
             for (Provider provider : providers.providers) {
                 writer.write("  <provider className=\"");
                 writer.write(provider.getClassName());
-                writer.write("\" layer=\"");
-                writer.write(provider.getLayer());
-                writer.write("\" appContext=\"");
-                writer.write(provider.getAppContext());
-                if (provider.getDescription() != null) {
-                    writer.write("\" description=\"");
-                    writer.write(provider.getDescription());
-                }
+                writeOptional("layer", provider.getLayer(), writer);
+                writeOptional("appContext", provider.getAppContext(), writer);
+                writeOptional("description", provider.getDescription(), 
writer);
                 writer.write("\">\n");
                 for (Entry<String,String> entry : 
provider.getProperties().entrySet()) {
                     writer.write("    <property name=\"");
@@ -171,6 +166,14 @@ final class PersistentProviderRegistrati
         }
     }
 
+
+    private static void writeOptional(String name, String value, Writer 
writer) throws IOException {
+        if (value != null) {
+            writer.write("\" " + name + "=\"");
+            writer.write(value);
+        }
+    }
+
 
     public static class Providers {
         private final List<Provider> providers = new ArrayList<>();

Added: tomcat/trunk/test/conf/jaspic-test-04.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/conf/jaspic-test-04.xml?rev=1815826&view=auto
==============================================================================
--- tomcat/trunk/test/conf/jaspic-test-04.xml (added)
+++ tomcat/trunk/test/conf/jaspic-test-04.xml Mon Nov 20 18:13:15 2017
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<jaspic-providers xmlns="http://tomcat.apache.org/xml";
+                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+                  xsi:schemaLocation="http://tomcat.apache.org/xml 
jaspic-providers.xsd"
+                  version="1.0">
+  <provider className="a" description="d"/>
+</jaspic-providers>
\ No newline at end of file

Propchange: tomcat/trunk/test/conf/jaspic-test-04.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java?rev=1815826&r1=1815825&r2=1815826&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java
 (original)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java
 Mon Nov 20 18:13:15 2017
@@ -84,4 +84,50 @@ public class TestPersistentProviderRegis
             Assert.assertTrue("Failed to clean up [" + f + "]", f.delete());
         }
     }
+
+
+    @Test
+    public void testLoadProviderWithoutLayerAndAC() {
+        File f = new File("test/conf/jaspic-test-04.xml");
+        Providers providers = PersistentProviderRegistrations.loadProviders(f);
+        validateNoLayerAndAC(providers);
+    }
+
+
+    private void validateNoLayerAndAC(Providers providers) {
+        Assert.assertEquals(1,  providers.getProviders().size());
+        Provider p = providers.getProviders().get(0);
+        Assert.assertEquals("a", p.getClassName());
+        Assert.assertNull(p.getLayer());
+        Assert.assertNull(p.getAppContext());
+        Assert.assertEquals("d", p.getDescription());
+    }
+
+
+    @Test
+    public void testSaveProviderWithoutLayerAndAC() {
+        File f = new File("test/conf/jaspic-test-05.xml");
+        if (f.exists()) {
+            Assert.assertTrue(f.delete());
+        }
+
+        // Create a config and write it out
+        Providers initialProviders = new Providers();
+        Provider p = new Provider();
+        p.setClassName("a");
+        p.setDescription("d");
+        initialProviders.addProvider(p);
+        PersistentProviderRegistrations.writeProviders(initialProviders, f);
+
+        // Read it back
+        Providers loadedProviders = 
PersistentProviderRegistrations.loadProviders(f);
+
+        try {
+            validateNoLayerAndAC(loadedProviders);
+        } finally {
+            if (f.exists()) {
+                f.delete();
+            }
+        }
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1815826&r1=1815825&r2=1815826&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Nov 20 18:13:15 2017
@@ -104,6 +104,11 @@
         <code>RegistrationContext</code> has been registered using the default
         registration ID. Patch provided by Lazar. (markt)
       </fix>
+      <fix>
+        <bug>61781</bug>: Enable JASPIC provider registrations to be persisted
+        when the layer and/or application context are <code>null</code>. Patch
+        provided by Lazar. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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

Reply via email to