Author: markt Date: Wed Feb 3 21:04:10 2016 New Revision: 1728373 URL: http://svn.apache.org/viewvc?rev=1728373&view=rev Log: JASPIC Add a new container level configuration file for JASPIC providers, a utility class for parsing that configuration file and some basic test cases.
Added: tomcat/trunk/conf/jaspic-providers.xml (with props) tomcat/trunk/conf/jaspic-providers.xsd (with props) tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/ tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java (with props) tomcat/trunk/test/conf/ tomcat/trunk/test/conf/jaspic-test-01.xml (with props) tomcat/trunk/test/conf/jaspic-test-02.xml (with props) tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/ tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java (with props) Added: tomcat/trunk/conf/jaspic-providers.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/conf/jaspic-providers.xml?rev=1728373&view=auto ============================================================================== --- tomcat/trunk/conf/jaspic-providers.xml (added) +++ tomcat/trunk/conf/jaspic-providers.xml Wed Feb 3 21:04:10 2016 @@ -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"> + <!-- No JASPIC providers configured by default --> +</jaspic-providers> Propchange: tomcat/trunk/conf/jaspic-providers.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/conf/jaspic-providers.xsd URL: http://svn.apache.org/viewvc/tomcat/trunk/conf/jaspic-providers.xsd?rev=1728373&view=auto ============================================================================== --- tomcat/trunk/conf/jaspic-providers.xsd (added) +++ tomcat/trunk/conf/jaspic-providers.xsd Wed Feb 3 21:04:10 2016 @@ -0,0 +1,53 @@ +<?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. +--> +<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://tomcat.apache.org/xml" + xmlns:jaspic="http://tomcat.apache.org/xml" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + elementFormDefault="qualified" + attributeFormDefault="unqualified" + version="1.0"> + <xs:element name="jaspic-providers"> + <xs:complexType> + <xs:sequence> + <xs:element name="provider" minOccurs="0" maxOccurs="unbounded"> + <xs:complexType> + <xs:sequence> + <xs:element name="property" minOccurs="0" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="name" use="required" type="jaspic:propertyname" /> + <xs:attribute name="value" use="required" type="xs:string" /> + </xs:complexType> + </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="description" type="xs:string" /> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="version" type="xs:string" /> + </xs:complexType> + </xs:element> + <xs:simpleType name="propertyname"> + <xs:restriction base="xs:string"> + <xs:minLength value="1"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> \ No newline at end of file Propchange: tomcat/trunk/conf/jaspic-providers.xsd ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=1728373&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java (added) +++ tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java Wed Feb 3 21:04:10 2016 @@ -0,0 +1,155 @@ +/** + * 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.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tomcat.util.digester.Digester; +import org.xml.sax.SAXException; + +final class PersistentProviderRegistrations { + + private PersistentProviderRegistrations() { + // Utility class. Hide default constructor + } + + + static Providers getProviders(File configFile) { + try (InputStream is = new FileInputStream(configFile)) { + // Construct a digester to read the XML input file + Digester digester = new Digester(); + + try { + digester.setFeature("http://apache.org/xml/features/allow-java-encodings", true); + // TODO: Configure the digester to validate the input against + // the XSD + } catch (Exception e) { + throw new SecurityException(e); + } + + // Create an object to hold the parse results and put it on the top + // of the digester's stack + Providers result = new Providers(); + digester.push(result); + + // Configure the digester + digester.addObjectCreate("jaspic-providers/provider", Provider.class.getName()); + digester.addSetProperties("jaspic-providers/provider"); + digester.addSetNext("jaspic-providers/provider", "addProvider", Provider.class.getName()); + + digester.addObjectCreate("jaspic-providers/provider/property", Property.class.getName()); + digester.addSetProperties("jaspic-providers/provider/property"); + digester.addSetNext("jaspic-providers/provider/property", "addProperty", Property.class.getName()); + + // Parse the input + digester.parse(is); + + return result; + } catch (IOException | SAXException e) { + throw new SecurityException(e); + } + } + + + public static class Providers { + private final List<Provider> providers = new ArrayList<>(); + + public void addProvider(Provider provider) { + providers.add(provider); + } + + public List<Provider> getProviders() { + return providers; + } + } + + + public static class Provider { + private String className; + private String layer; + private String appContext; + private String description; + private final List<Property> properties = new ArrayList<>(); + + + public String getClassName() { + return className; + } + public void setClassName(String className) { + this.className = className; + } + + + public String getLayer() { + return layer; + } + public void setLayer(String layer) { + this.layer = layer; + } + + + public String getAppContext() { + return appContext; + } + public void setAppContext(String appContext) { + this.appContext = appContext; + } + + + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + + public void addProperty(Property property) { + properties.add(property); + } + public List<Property> getProperties() { + return properties; + } + } + + + public static class Property { + private String name; + private String value; + + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + } +} Propchange: tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/conf/jaspic-test-01.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/test/conf/jaspic-test-01.xml?rev=1728373&view=auto ============================================================================== --- tomcat/trunk/test/conf/jaspic-test-01.xml (added) +++ tomcat/trunk/test/conf/jaspic-test-01.xml Wed Feb 3 21:04:10 2016 @@ -0,0 +1,22 @@ +<?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"> +</jaspic-providers> \ No newline at end of file Propchange: tomcat/trunk/test/conf/jaspic-test-01.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/conf/jaspic-test-02.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/test/conf/jaspic-test-02.xml?rev=1728373&view=auto ============================================================================== --- tomcat/trunk/test/conf/jaspic-test-02.xml (added) +++ tomcat/trunk/test/conf/jaspic-test-02.xml Wed Feb 3 21:04:10 2016 @@ -0,0 +1,26 @@ +<?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" layer="b" appContext="c" description="d"> + <property name="e" value="f"/> + <property name="g" value="h"/> + </provider> +</jaspic-providers> \ No newline at end of file Propchange: tomcat/trunk/test/conf/jaspic-test-02.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=1728373&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java (added) +++ tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java Wed Feb 3 21:04:10 2016 @@ -0,0 +1,58 @@ + /** + * 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.io.File; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.authenticator.jaspic.PersistentProviderRegistrations.Property; +import org.apache.catalina.authenticator.jaspic.PersistentProviderRegistrations.Provider; +import org.apache.catalina.authenticator.jaspic.PersistentProviderRegistrations.Providers; + +public class TestPersistentProviderRegistrations { + + @Test + public void testLoadEmpty() { + File f = new File("test/conf/jaspic-test-01.xml"); + Providers result = PersistentProviderRegistrations.getProviders(f); + Assert.assertEquals(0, result.getProviders().size()); + } + + + @Test + public void testLoadSimple() { + File f = new File("test/conf/jaspic-test-02.xml"); + Providers result = PersistentProviderRegistrations.getProviders(f); + Assert.assertEquals(1, result.getProviders().size()); + Provider p = result.getProviders().get(0); + Assert.assertEquals("a", p.getClassName()); + Assert.assertEquals("b", p.getLayer()); + Assert.assertEquals("c", p.getAppContext()); + Assert.assertEquals("d", p.getDescription()); + + Assert.assertEquals(2, p.getProperties().size()); + Property prop1 = p.getProperties().get(0); + Assert.assertEquals("e", prop1.getName()); + Assert.assertEquals("f", prop1.getValue()); + Property prop2 = p.getProperties().get(1); + Assert.assertEquals("g", prop2.getName()); + Assert.assertEquals("h", prop2.getValue()); + } + +} Propchange: tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPersistentProviderRegistrations.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org