[java-idp-oidc] 01/02: Use BasicJWKCredentialFactoryBean from commons.

Henri Mikkonen henri.mikkonen at iki.fi
Fri Jan 27 15:36:11 UTC 2023


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

hjmikkon pushed a commit to branch main
in repository java-idp-oidc.

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

commit 0276df99be1781ad783fba49de7ab2e1120dd4f9
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Jan 27 17:33:42 2023 +0200

    Use BasicJWKCredentialFactoryBean from commons.
---
 .../factory/BasicJWKCredentialFactoryBean.java     | 103 ---------------------
 .../op/profile/spring/factory/package-info.java    |  19 ----
 .../META-INF/net.shibboleth.idp/postconfig.xml     |   2 +-
 .../impl/CredentialMetadataValueResolverTest.java  |   2 +-
 .../profile/impl/BaseOIDCResponseActionTest.java   |   2 +-
 5 files changed, 3 insertions(+), 125 deletions(-)

diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/factory/BasicJWKCredentialFactoryBean.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/factory/BasicJWKCredentialFactoryBean.java
deleted file mode 100644
index adcc509b..00000000
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/factory/BasicJWKCredentialFactoryBean.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.plugin.oidc.op.profile.spring.factory;
-
-import java.io.IOException;
-import java.io.InputStream;
-import javax.annotation.Nonnull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.FatalBeanException;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.core.io.Resource;
-import java.text.ParseException;
-import java.util.List;
-import net.shibboleth.idp.profile.spring.factory.AbstractCredentialFactoryBean;
-import net.shibboleth.oidc.security.credential.BasicJWKCredential;
-import net.shibboleth.oidc.security.impl.CredentialConversionUtil;
-
-import com.nimbusds.jose.jwk.JWK;
-import com.nimbusds.jose.jwk.AsymmetricJWK;
-import com.nimbusds.jose.jwk.OctetSequenceKey;
-import com.nimbusds.jose.jwk.KeyType;
-import com.google.common.io.ByteStreams;
-
-/** factory bean for Basic JSON Web Keys (JWK). */
-public class BasicJWKCredentialFactoryBean extends AbstractCredentialFactoryBean<BasicJWKCredential> {
-
-    /** Class logger. */
-    private final Logger log = LoggerFactory.getLogger(BasicJWKCredentialFactoryBean.class);
-
-    /** Where the private key is to be found. */
-    private Resource jwkResource;
-
-    /**
-     * Set the resource containing the private key.
-     * 
-     * @param res private key resource, never <code>null</code>
-     */
-    public void setResource(@Nonnull final Resource res) {
-        jwkResource = res;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    protected BasicJWKCredential doCreateInstance() throws Exception {
-
-        if (jwkResource == null) {
-            log.error("{}: No JWK credential provided", getConfigDescription());
-            throw new BeanCreationException("No JWK credential provided");
-        }
-        JWK jwk = null;
-        BasicJWKCredential jwkCredential = null;
-        try (InputStream is = jwkResource.getInputStream()) {
-            jwk = JWK.parse(new String(ByteStreams.toByteArray(is)));
-            jwkCredential = new BasicJWKCredential();
-            if (jwk.getKeyType() == KeyType.EC || jwk.getKeyType() == KeyType.RSA) {
-                if (jwk.isPrivate()) {
-                    jwkCredential.setPrivateKey(((AsymmetricJWK) jwk).toPrivateKey());
-                }
-                jwkCredential.setPublicKey(((AsymmetricJWK) jwk).toPublicKey());
-            } else if (jwk.getKeyType() == KeyType.OCT) {
-                jwkCredential.setSecretKey(((OctetSequenceKey) jwk).toSecretKey());
-            } else {
-                throw new FatalBeanException("Unsupported KeyFile at " + jwkResource.getDescription());
-            }
-        } catch (final IOException | ParseException e) {
-            log.error("{}: Could not decode KeyFile at {}: {}", getConfigDescription(), jwkResource.getDescription(),
-                    e);
-            throw new FatalBeanException("Could not decode provided KeyFile " + jwkResource.getDescription(), e);
-        }
-        jwkCredential.setUsageType(CredentialConversionUtil.getUsageType(jwk));
-        jwkCredential.setEntityId(getEntityID());
-        jwkCredential.setAlgorithm(jwk.getAlgorithm());
-        jwkCredential.setKid(jwk.getKeyID());
-        final List<String> keyNames = getKeyNames();
-        if (keyNames != null) {
-            jwkCredential.getKeyNames().addAll(keyNames);
-        }
-        return jwkCredential;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public Class<?> getObjectType() {
-        return BasicJWKCredential.class;
-    }
-
-}
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/factory/package-info.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/factory/package-info.java
deleted file mode 100644
index f052a8c1..00000000
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/spring/factory/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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.
- */
-
-/** Factory beans for idp-oidc-extension-impl project. */
-package net.shibboleth.idp.plugin.oidc.op.profile.spring.factory;
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
index a9beac45..b32a87ac 100644
--- a/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ b/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
@@ -12,7 +12,7 @@
     <!-- System beans needed for extension to function, loaded after global.xml -->
 
     <bean id="shibboleth.JWKCredential" abstract="true"
-        class="net.shibboleth.idp.plugin.oidc.op.profile.spring.factory.BasicJWKCredentialFactoryBean" />
+        class="net.shibboleth.oidc.security.credential.impl.BasicJWKCredentialFactoryBean" />
 
     <!-- OIDC authentication context class reference parent declaration -->
     <bean id="shibboleth.OIDCAuthnContextClassReference" abstract="true"
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java
index 03204dc9..c40c38c2 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/metadata/impl/CredentialMetadataValueResolverTest.java
@@ -32,12 +32,12 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import net.shibboleth.idp.plugin.oidc.op.profile.spring.factory.BasicJWKCredentialFactoryBean;
 import net.shibboleth.idp.profile.config.SecurityConfiguration;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
 import net.shibboleth.idp.profile.testing.RequestContextBuilder;
 import net.shibboleth.oidc.profile.config.OIDCProviderInformationConfiguration;
+import net.shibboleth.oidc.security.credential.impl.BasicJWKCredentialFactoryBean;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 
 /**
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java
index 1391def6..20638931 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/BaseOIDCResponseActionTest.java
@@ -30,12 +30,12 @@ import java.util.stream.Stream;
 import javax.annotation.Nonnull;
 
 import net.shibboleth.idp.plugin.oidc.op.messaging.context.OIDCAuthenticationResponseContext;
-import net.shibboleth.idp.plugin.oidc.op.profile.spring.factory.BasicJWKCredentialFactoryBean;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
 import net.shibboleth.idp.profile.testing.RequestContextBuilder;
 import net.shibboleth.oidc.metadata.context.OIDCMetadataContext;
 import net.shibboleth.oidc.profile.config.OIDCAuthorizationConfiguration;
+import net.shibboleth.oidc.security.credential.impl.BasicJWKCredentialFactoryBean;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.security.DataSealer;

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


More information about the commits mailing list