[java-identity-provider] 06/07: IDP-1364 Fix JNDIConnectionPropertyHandle handling.
Rod Widdowson
rdw at steadingsoftware.com
Sat Dec 8 09:27:29 EST 2018
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch maint-3.4
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=69a4e060df5f2472a766e7ade61d7d031f538080
commit 69a4e060df5f2472a766e7ade61d7d031f538080
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Nov 19 16:26:01 2018 +0000
IDP-1364 Fix JNDIConnectionPropertyHandle handling.
https://issues.shibboleth.net/jira/browse/IDP-1364
This checkin also adds a test, which is supressed because it spits (very hard) on the JNDI namespace
handlers and thus causes surefire to fail (somewhere completely different).
---
.../spring/dc/impl/ManagedConnectionParser.java | 8 +-
.../resolver/spring/dc/ManagedConnectionTest.java | 357 +++++++++++++++++++++
.../spring/dc/containerManagedConnection.xml | 20 ++
.../dc/resolver/containerManagedConnection.xml | 19 ++
4 files changed, 400 insertions(+), 4 deletions(-)
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ManagedConnectionParser.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ManagedConnectionParser.java
index 3168513..e5022a8 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ManagedConnectionParser.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ManagedConnectionParser.java
@@ -148,10 +148,10 @@ public class ManagedConnectionParser {
AttributeSupport.getAttributeValue(containerManagedElement, new QName("resourceName"));
final ManagedMap<String, String> props = new ManagedMap<>();
- final Element propertyElement =
- ElementSupport.getFirstChildElement(containerManagedElement, new QName(
- DataConnectorNamespaceHandler.NAMESPACE, "JNDIConnectionProperty"));
- final List<Element> elements = ElementSupport.getChildElements(propertyElement);
+ final List<Element> elements = ElementSupport.getChildElementsByTagNameNS(containerManagedElement,
+ DataConnectorNamespaceHandler.NAMESPACE, "JNDIConnectionProperty");
+ elements.addAll(ElementSupport.getChildElementsByTagNameNS(containerManagedElement,
+ AttributeResolverNamespaceHandler.NAMESPACE, "JNDIConnectionProperty"));
for (final Element e : elements) {
props.put(AttributeSupport.getAttributeValue(e, new QName("name")),
AttributeSupport.getAttributeValue(e, new QName("value")));
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/ManagedConnectionTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/ManagedConnectionTest.java
new file mode 100644
index 0000000..c9f04df
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/ManagedConnectionTest.java
@@ -0,0 +1,357 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.idp.attribute.resolver.spring.dc;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Hashtable;
+import java.util.logging.Logger;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+import javax.sql.DataSource;
+
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.attribute.resolver.spring.BaseAttributeDefinitionParserTest;
+import net.shibboleth.idp.saml.attribute.resolver.impl.StoredIDDataConnector;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+/**
+ *
+ */
+public class ManagedConnectionTest extends BaseAttributeDefinitionParserTest {
+
+ @Test(enabled=false) public void simple() throws ComponentInitializationException, NamingException {
+ if (!NamingManager.hasInitialContextFactoryBuilder()) {
+ NamingManager.setInitialContextFactoryBuilder(new ContextFactoryBuilder() );
+ }
+
+ final StoredIDDataConnector connector = getDataConnector("containerManagedConnection.xml", StoredIDDataConnector.class);
+ MyDataSource source = (MyDataSource) connector.getDataSource();
+ assertEquals(source.getEnvironment().size(), 2);
+ assertEquals(source.getEnvironment().get("foo"), "Bar");
+ assertEquals(source.getEnvironment().get("yellow"), "green");
+ }
+
+ @Test(enabled=false) public void resolver() throws ComponentInitializationException, NamingException {
+ if (!NamingManager.hasInitialContextFactoryBuilder()) {
+ NamingManager.setInitialContextFactoryBuilder(new ContextFactoryBuilder() );
+ }
+
+ final StoredIDDataConnector connector = getDataConnector("resolver/containerManagedConnection.xml", StoredIDDataConnector.class);
+ MyDataSource source = (MyDataSource) connector.getDataSource();
+ assertEquals(source.getEnvironment().size(), 2);
+ assertEquals(source.getEnvironment().get("foo"), "Bar");
+ assertEquals(source.getEnvironment().get("yellow"), "green");
+ }
+
+
+
+ /** Hard wiring for JNDI. This is an {@link InitialContextFactoryBuilder} Its only job is to return a {@link MyContextFactory} */
+ private class ContextFactoryBuilder implements InitialContextFactoryBuilder {
+
+ /** {@inheritDoc} */
+ public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) throws NamingException {
+ return new MyContextFactory();
+ }
+ }
+
+ /** Hard wiring for JNDI. This is an {@link InitialContextFactory}. Its only job is to return an {@link MyInitialContext} */
+ private class MyContextFactory implements InitialContextFactory {
+
+ /** {@inheritDoc} */
+ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
+ return new MyInitialContext(environment);
+ }
+
+ }
+
+
+ /** Hard wiring for JNDI. This is a {@link Context}. Its only job is to return an {@link DataSource} called "myConnnector"
+ */
+ private class MyInitialContext implements Context {
+
+ private final Hashtable<?, ?> environment;
+
+ /**
+ * Constructor.
+ *
+ * @param environment
+ */
+ public MyInitialContext(Hashtable<?, ?> env) {
+ environment = env;
+ }
+
+ /** {@inheritDoc} */
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public void bind(Name name, Object obj) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void bind(String name, Object obj) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public String composeName(String name, String prefix) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public Context createSubcontext(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public Context createSubcontext(String name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public void destroySubcontext(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void destroySubcontext(String name) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public Hashtable<?, ?> getEnvironment() throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public String getNameInNamespace() throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public NameParser getNameParser(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public NameParser getNameParser(String name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public Object lookup(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public Object lookup(String name) throws NamingException {
+ if ("myConnnector".equals(name)) {
+ return new MyDataSource(environment);
+ }
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public Object lookupLink(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public Object lookupLink(String name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public void rebind(Name name, Object obj) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void rebind(String name, Object obj) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public Object removeFromEnvironment(String propName) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ public void rename(Name oldName, Name newName) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void rename(String oldName, String newName) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void unbind(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void unbind(String name) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+ /** Hard wiring for JNDI. This is a {@link DataSource}. Its only job is to return hold the environment so
+ * we can test it later
+ */
+
+ private final class MyDataSource implements DataSource {
+
+ private final Hashtable<?, ?> environment;
+
+ /**
+ * Constructor.
+ *
+ * @param environment
+ */
+ public MyDataSource(Hashtable<?, ?> env) {
+ environment = env;
+ }
+
+ public Hashtable<?, ?> getEnvironment() {
+ return environment;
+ }
+
+ /** {@inheritDoc} */
+ public PrintWriter getLogWriter() throws SQLException {
+ throw new SQLException();
+ }
+
+ /** {@inheritDoc} */
+ public int getLoginTimeout() throws SQLException {
+ throw new SQLException();
+ }
+
+ /** {@inheritDoc} */
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ /** {@inheritDoc} */
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ throw new SQLException();
+ }
+
+ /** {@inheritDoc} */
+ public void setLoginTimeout(int seconds) throws SQLException {
+ throw new SQLException();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isWrapperFor(Class<?> arg0) throws SQLException {
+ throw new SQLException();
+ }
+
+ /** {@inheritDoc} */
+ public <T> T unwrap(Class<T> arg0) throws SQLException {
+ throw new SQLException();
+ }
+
+ /** {@inheritDoc} */
+ public Connection getConnection() throws SQLException {
+ throw new SQLException();
+ }
+
+ /** {@inheritDoc} */
+ public Connection getConnection(String username, String password) throws SQLException {
+ throw new SQLException();
+ }
+
+ }
+}
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/containerManagedConnection.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/containerManagedConnection.xml
new file mode 100644
index 0000000..eeb8ec0
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/containerManagedConnection.xml
@@ -0,0 +1,20 @@
+<resolver:DataConnector id="stored"
+ xsi:type="dc:StoredId" xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pc="urn:mace:shibboleth:2.0:resolver:pc"
+ xmlns:ad="urn:mace:shibboleth:2.0:resolver:ad" xmlns:dc="urn:mace:shibboleth:2.0:resolver:dc"
+ xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" xmlns:sec="urn:mace:shibboleth:2.0:security"
+
+ failFast="false"
+ queryTimeout="PT5S"
+
+ transactionRetries="5"
+ retryableErrors="25000 25001"
+ sourceAttributeID="theSourceRemainsTheSame"
+ generatedAttributeID="jenny"
+ salt="abcdefghijklmnopqrst" xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd
+ urn:mace:shibboleth:2.0:resolver:dc http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-dc.xsd">
+ <dc:ContainerManagedConnection resourceName="myConnnector">
+ <dc:JNDIConnectionProperty name="foo" value="Bar"/>
+ <dc:JNDIConnectionProperty name="yellow" value="green"/>
+ </dc:ContainerManagedConnection>
+</resolver:DataConnector>
\ No newline at end of file
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/resolver/containerManagedConnection.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/resolver/containerManagedConnection.xml
new file mode 100644
index 0000000..b455431
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/resolver/containerManagedConnection.xml
@@ -0,0 +1,19 @@
+<DataConnector id="stored" xsi:type="StoredId"
+ xmlns="urn:mace:shibboleth:2.0:resolver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
+ failFast="false"
+ queryTimeout="PT5S"
+ transactionRetries="5"
+ retryableErrors="25000 25001"
+ generatedAttributeID="jenny"
+
+ salt="abcdefghijklmnopqrst"
+
+ xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
+ <ContainerManagedConnection resourceName="myConnnector">
+ <JNDIConnectionProperty name="foo" value="Bar"/>
+ <JNDIConnectionProperty name="yellow" value="green"/>
+ </ContainerManagedConnection>
+
+ <InputAttributeDefinition ref="TheAttributeRemainsTheSame"/>
+</DataConnector>
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list