[java-shib-profile] branch main updated: JSPROF-2 - Move OpenSAML config bean class from IdP into profile library

Scott Cantor cantor.2 at osu.edu
Tue Apr 18 17:49:51 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-shib-profile.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-profile.git;a=commit;h=66e41fb64a58ccae8b05192e10f82ea96f9d31c3

The following commit(s) were added to refs/heads/main by this push:
     new 66e41fb  JSPROF-2 - Move OpenSAML config bean class from IdP into profile library
66e41fb is described below

commit 66e41fb64a58ccae8b05192e10f82ea96f9d31c3
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Apr 18 13:49:49 2023 -0400

    JSPROF-2 - Move OpenSAML config bean class from IdP into profile library
    
    https://shibboleth.atlassian.net/browse/JSPROF-2
---
 shib-profile-impl/pom.xml                          |   9 ++
 .../profile/spring/impl/OpenSAMLConfigBean.java    | 148 +++++++++++++++++++++
 .../profile/spring/impl/package-info.java          |  21 +++
 3 files changed, 178 insertions(+)

diff --git a/shib-profile-impl/pom.xml b/shib-profile-impl/pom.xml
index 3d13574..a093f93 100644
--- a/shib-profile-impl/pom.xml
+++ b/shib-profile-impl/pom.xml
@@ -58,6 +58,10 @@
             <groupId>${opensaml.groupId}</groupId>
             <artifactId>opensaml-security-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${opensaml.groupId}</groupId>
+            <artifactId>opensaml-xmlsec-api</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>${shib-shared.groupId}</groupId>
@@ -68,6 +72,11 @@
             <groupId>${spring.groupId}</groupId>
             <artifactId>spring-beans</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-core</artifactId>
+        </dependency>
         
         <!-- Provided Dependencies -->
 
diff --git a/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBean.java b/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBean.java
new file mode 100644
index 0000000..0bb77cb
--- /dev/null
+++ b/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBean.java
@@ -0,0 +1,148 @@
+/*
+ * 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.profile.spring.impl;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.core.config.ConfigurationService;
+import org.opensaml.core.config.InitializationException;
+import org.opensaml.core.config.InitializationService;
+import org.opensaml.core.xml.config.XMLObjectProviderRegistry;
+import org.opensaml.xmlsec.config.DecryptionParserPool;
+import org.slf4j.Logger;
+
+import com.codahale.metrics.MetricRegistry;
+
+import net.shibboleth.shared.component.AbstractInitializableComponent;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.xml.ParserPool;
+
+/**
+ * A simple bean that may be used with Spring to initialize the OpenSAML library
+ * with injected instances of some critical objects.
+ */
+public class OpenSAMLConfigBean extends AbstractInitializableComponent {
+
+    /** Class logger. */
+    @Nonnull private final Logger log = LoggerFactory.getLogger(OpenSAMLConfigBean.class);
+    
+    /** Optional {@link ParserPool} to configure. */
+    @Nullable private ParserPool parserPool;
+    
+    /** Optional decryption {@link ParserPool} to configure. */
+    @Nullable private ParserPool decryptionParserPool;
+    
+    /** Optional {@link MetricRegistry} to configure. */
+    @Nullable private MetricRegistry metricRegistry;
+    
+    /**
+     * Get the global {@link ParserPool} to configure.
+     * 
+     * @return the parser pool
+     */
+    @Nullable public ParserPool getParserPool() {
+        return parserPool;
+    }
+
+    /**
+     * Set the global {@link ParserPool} to configure.
+     * 
+     * @param newParserPool the parser pool to set
+     */
+    public void setParserPool(@Nullable final ParserPool newParserPool) {
+        checkSetterPreconditions();
+        parserPool = newParserPool;
+    }
+    
+    /**
+     * Get the global decryption {@link ParserPool} to configure.
+     * 
+     * @return the decryption parser pool
+     */
+    @Nullable public ParserPool getDecryptionParserPool() {
+        return decryptionParserPool;
+    }
+
+    /**
+     * Set the global decryption {@link ParserPool} to configure.
+     * 
+     * @param newParserPool the decryption parser pool to set
+     */
+    public void setDecryptionParserPool(@Nullable final ParserPool newParserPool) {
+        checkSetterPreconditions();
+        decryptionParserPool = newParserPool;
+    }
+    
+    /**
+     * Get the global {@link MetricRegistry} to configure.
+     * 
+     * @return the metric registry to use
+     * 
+     * @since 3.3.0
+     */
+    @Nullable public MetricRegistry getMetricRegistry() {
+        return metricRegistry;
+    }
+    
+    /**
+     * Set the global {@link MetricRegistry} to configure.
+     * 
+     * @param registry the metric registry to use
+     * 
+     * @since 3.3.0
+     */
+    public void setMetricRegistry(@Nullable final MetricRegistry registry) {
+        metricRegistry = registry;
+    }
+    
+    /** {@inheritDoc} */
+    protected void doInitialize() throws ComponentInitializationException {
+
+        // Initialize OpenSAML.
+        try {
+            InitializationService.initialize();
+        } catch (final InitializationException e) {
+            throw new ComponentInitializationException("Exception initializing OpenSAML", e);
+        }
+        
+        XMLObjectProviderRegistry registry = null;
+        synchronized(ConfigurationService.class) {
+            if (metricRegistry != null) {
+                ConfigurationService.register(MetricRegistry.class, metricRegistry);
+            }
+            
+            registry = ConfigurationService.get(XMLObjectProviderRegistry.class);
+            if (registry == null) {
+                log.debug("XMLObjectProviderRegistry did not exist in ConfigurationService, will be created");
+                registry = new XMLObjectProviderRegistry();
+                ConfigurationService.register(XMLObjectProviderRegistry.class, registry);
+            }
+        }
+        
+        if (parserPool != null) {
+            registry.setParserPool(parserPool);
+        }
+        
+        if (decryptionParserPool != null) {
+            ConfigurationService.register(DecryptionParserPool.class, new DecryptionParserPool(decryptionParserPool));
+        }
+    }
+    
+}
\ No newline at end of file
diff --git a/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/package-info.java b/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/package-info.java
new file mode 100644
index 0000000..650f9db
--- /dev/null
+++ b/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Spring helper classes for profile-aware software.
+ */
+package net.shibboleth.profile.spring.impl;
\ 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