[java-idp-oidc] 04/09: JOIDC-5 Initial api+impl for resolving client secrets via key.

Henri Mikkonen henri.mikkonen at iki.fi
Fri Jun 5 13:54:56 UTC 2020


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

hjmikkon pushed a commit to branch dev/JOIDC-5
in repository java-idp-oidc.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=ab64f84416d5e8e646b58e931303c4a5806ba392

commit ab64f84416d5e8e646b58e931303c4a5806ba392
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Jun 5 16:15:11 2020 +0300

    JOIDC-5 Initial api+impl for resolving client secrets via key.
    
    https://issues.shibboleth.net/jira/browse/JOIDC-5
---
 .../resolver/ClientSecretValueResolver.java        |  29 ++++++
 .../impl/PropertiesClientSecretValueResolver.java  | 108 +++++++++++++++++++++
 2 files changed, 137 insertions(+)

diff --git a/idp-oidc-extension-api/src/main/java/org/geant/idpextension/oidc/metadata/resolver/ClientSecretValueResolver.java b/idp-oidc-extension-api/src/main/java/org/geant/idpextension/oidc/metadata/resolver/ClientSecretValueResolver.java
new file mode 100644
index 00000000..804ba34f
--- /dev/null
+++ b/idp-oidc-extension-api/src/main/java/org/geant/idpextension/oidc/metadata/resolver/ClientSecretValueResolver.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 - 2020, GÉANT
+ *
+ * Licensed 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.geant.idpextension.oidc.metadata.resolver;
+
+import net.shibboleth.utilities.java.support.component.IdentifiedComponent;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+import net.shibboleth.utilities.java.support.resolver.Resolver;
+
+/**
+ * A resolver that is capable of resolving client secret values (as {@link String}s) which meet certain supplied
+ * criteria.
+ */
+public interface ClientSecretValueResolver extends Resolver<String, CriteriaSet>, IdentifiedComponent {
+
+}
diff --git a/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/metadata/impl/PropertiesClientSecretValueResolver.java b/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/metadata/impl/PropertiesClientSecretValueResolver.java
new file mode 100644
index 00000000..3ce0743a
--- /dev/null
+++ b/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/metadata/impl/PropertiesClientSecretValueResolver.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2017 - 2020, GÉANT
+ *
+ * Licensed 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.geant.idpextension.oidc.metadata.impl;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Properties;
+
+import javax.annotation.Nonnull;
+
+import org.geant.idpextension.oidc.criterion.ClientSecretReferenceCriterion;
+import org.geant.idpextension.oidc.metadata.resolver.ClientSecretValueResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.Resource;
+
+import net.shibboleth.utilities.java.support.collection.LazySet;
+import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
+import net.shibboleth.utilities.java.support.component.ComponentSupport;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+import net.shibboleth.utilities.java.support.resolver.ResolverException;
+
+/**
+ * A client secret value resolver that fetches the values from the given Properties file.
+ */
+public class PropertiesClientSecretValueResolver extends AbstractIdentifiableInitializableComponent 
+    implements ClientSecretValueResolver {
+
+    /** Class logger. */
+    private final Logger log = LoggerFactory.getLogger(PropertiesClientSecretValueResolver.class);
+
+    /** The properties file. */
+    @Nonnull private Properties properties;
+    
+    /**
+     * Constructor.
+     *
+     * @param resource The properties resource.
+     */
+    public PropertiesClientSecretValueResolver(@Nonnull final Resource resource) {
+        super();
+        Constraint.isNotNull(resource, "Properties resource cannot be null");
+        properties = new Properties();
+        try {
+            properties.load(resource.getInputStream());
+        } catch (IOException e) {
+            log.warn("Could not read the properties from the given resource", e);
+            throw new ConstraintViolationException("The properties resource must be readable");
+        }
+    }
+    
+    @Override
+    /** {@inheritDoc} */
+    public Iterable<String> resolve(final CriteriaSet criteria) throws ResolverException {
+        final String value = fetchValue(criteria);
+        if (value != null) {
+            final LazySet<String> result = new LazySet<>();
+            result.add(value);
+            return result;
+        }
+        return Collections.emptySet();
+    }
+
+    @Override
+    /** {@inheritDoc} */
+    public String resolveSingle(final CriteriaSet criteria) throws ResolverException {
+        return fetchValue(criteria);
+    }
+    
+    /**
+     * Fetch the value from properties.
+     * 
+     * @param criteria The criteria containing {@link ClientSecretReferenceCriterion}.
+     * @return The value found from properties, or null if no value was found.
+     */
+    protected String fetchValue(final CriteriaSet criteria) {
+        ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
+        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+
+        final ClientSecretReferenceCriterion criterion = criteria.get(ClientSecretReferenceCriterion.class);
+        return properties.getProperty(criterion.getSecretReference());
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    protected void doDestroy() {
+        properties = null;
+          
+        super.doDestroy();
+    }
+
+}

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


More information about the commits mailing list