[java-shib-shared] branch main updated: JSSH-36 - Factory beans for some HttpClient-related classes

Scott Cantor cantor.2 at osu.edu
Mon Jul 24 20:48:35 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-shared.

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

The following commit(s) were added to refs/heads/main by this push:
     new aac7d5eb JSSH-36 - Factory beans for some HttpClient-related classes
aac7d5eb is described below

commit aac7d5eb96e4810c3f43ea5e55a9f70983163363
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Jul 24 16:48:29 2023 -0400

    JSSH-36 - Factory beans for some HttpClient-related classes
    
    https://shibboleth.atlassian.net/browse/JSSH-36
    
    HttpHost and basic-auth credentials beans.
---
 shib-networking-spring/pom.xml                     | 12 ++-
 .../httpclient/factory/HttpHostFactoryBean.java    | 88 ++++++++++++++++++++++
 .../UsernamePasswoordCredentialsFactoryBean.java   | 79 +++++++++++++++++++
 .../shared/spring/factory/PatternFactoryBean.java  | 12 +--
 4 files changed, 178 insertions(+), 13 deletions(-)

diff --git a/shib-networking-spring/pom.xml b/shib-networking-spring/pom.xml
index 10c87792..32e6688b 100644
--- a/shib-networking-spring/pom.xml
+++ b/shib-networking-spring/pom.xml
@@ -26,6 +26,11 @@
             <artifactId>shib-networking</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>shib-spring</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>shib-support</artifactId>
@@ -77,13 +82,6 @@
         <!-- Runtime Dependencies -->
 
         <!-- Test Dependencies -->
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>shib-spring</artifactId>
-            <version>${project.version}</version>
-          <scope>test</scope>
-        </dependency>
-
         <dependency>
           <groupId>${spring.groupId}</groupId>
           <artifactId>spring-test</artifactId>
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/HttpHostFactoryBean.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/HttpHostFactoryBean.java
new file mode 100644
index 00000000..f0c4959c
--- /dev/null
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/HttpHostFactoryBean.java
@@ -0,0 +1,88 @@
+/*
+ * 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.shared.spring.httpclient.factory;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.hc.core5.http.HttpHost;
+
+import net.shibboleth.shared.spring.factory.AbstractComponentAwareFactoryBean;
+
+/**
+ * Factory bean for {@link HttpHost}.
+ * 
+ * <p>Mainly for insulation from Apache client API.</p>
+ * 
+ * @since 9.0.0
+ */
+public class HttpHostFactoryBean extends AbstractComponentAwareFactoryBean<HttpHost> {
+
+    /** The scheme. */
+    @Nullable private String scheme;
+
+    /** The hostname. */
+    @Nullable private String hostname;
+
+    /** The port. */
+    @Nullable private Integer port;
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull public Class<?> getObjectType() {
+        return HttpHost.class;
+    }
+
+    /**
+     * Set the scheme.
+     * 
+     * @param what value to set
+     */
+    public void setScheme(@Nullable final String what) {
+        scheme = what;
+    }
+
+    /**
+     * Set the hostname.
+     * 
+     * @param what value to set
+     */
+    public void setHostname(@Nullable final String what) {
+        hostname = what;
+    }
+
+    /**
+     * Set the port.
+     * 
+     * @param what value to set
+     */
+    public void setPort(@Nullable final Integer what) {
+        port = what;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull protected HttpHost doCreateInstance() throws Exception {
+        if (port != null) {
+            return new HttpHost(scheme, hostname, port);
+        } else {
+            return new HttpHost(scheme, hostname);
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/UsernamePasswoordCredentialsFactoryBean.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/UsernamePasswoordCredentialsFactoryBean.java
new file mode 100644
index 00000000..51354ac1
--- /dev/null
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/UsernamePasswoordCredentialsFactoryBean.java
@@ -0,0 +1,79 @@
+/*
+ * 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.shared.spring.httpclient.factory;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.springframework.beans.factory.BeanCreationException;
+
+import net.shibboleth.shared.spring.factory.AbstractComponentAwareFactoryBean;
+
+/**
+ * Factory bean for {@link UsernamePasswordCredentials}.
+ * 
+ * <p>Mainly for insulation from Apache client API.</p>
+ * 
+ * @since 9.0.0
+ */
+public class UsernamePasswoordCredentialsFactoryBean
+        extends AbstractComponentAwareFactoryBean<UsernamePasswordCredentials> {
+
+    /** The username. */
+    @Nullable private String username;
+
+    /** The password. */
+    @Nullable private String password;
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull public Class<?> getObjectType() {
+        return UsernamePasswordCredentials.class;
+    }
+
+    /**
+     * Set the username.
+     * 
+     * @param what value to set
+     */
+    public void setUsername(@Nullable final String what) {
+        username = what;
+    }
+
+    /**
+     * Set the password.
+     * 
+     * @param what value to set
+     */
+    public void setPassword(@Nullable final String what) {
+        password = what;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull protected UsernamePasswordCredentials doCreateInstance() throws Exception {
+        if (username == null || password == null) {
+            throw new BeanCreationException("Username and password cannot be null");
+        }
+        
+        assert password != null;
+        return new UsernamePasswordCredentials(username, password.toCharArray());
+    }
+
+}
\ No newline at end of file
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/PatternFactoryBean.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/PatternFactoryBean.java
index cd9f6dc7..3ec495fa 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/PatternFactoryBean.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/PatternFactoryBean.java
@@ -45,18 +45,18 @@ public class PatternFactoryBean extends AbstractComponentAwareFactoryBean<Patter
     }
 
     /**
-     * set case sensitivity.
+     * Get case sensitivity.
      * 
-     * @return Returns the caseSensitive.
+     * @return the case sensitivity
      */
     @Nullable public String getCaseSensitive() {
         return caseSensitive;
     }
 
     /**
-     * get case sensitivity.
+     * Set case sensitivity.
      * 
-     * @param what The value to set.
+     * @param what value to set
      */
     public void setCaseSensitive(@Nullable final String what) {
         caseSensitive = what;
@@ -65,7 +65,7 @@ public class PatternFactoryBean extends AbstractComponentAwareFactoryBean<Patter
     /**
      * Get the regular expression.
      * 
-     * @return Returns the regexp.
+     * @return the regexp
      */
     @Nullable public String getRegexp() {
         return regexp;
@@ -74,7 +74,7 @@ public class PatternFactoryBean extends AbstractComponentAwareFactoryBean<Patter
     /**
      * Set the regular expression.
      * 
-     * @param what what to set.
+     * @param what what to set
      */
     public void setRegexp(@Nullable final String what) {
         regexp = what;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list