[java-oidc-common] branch main updated: JCOMOIDC-38 - Move various support classes from the OP plugin

Henri Mikkonen henri.mikkonen at iki.fi
Fri Dec 2 12:39:05 UTC 2022


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

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

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

The following commit(s) were added to refs/heads/main by this push:
     new 0f501fd  JCOMOIDC-38 - Move various support classes from the OP plugin
0f501fd is described below

commit 0f501fd375f2e0929c96c5e2925fdfd1a85bfac5
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Dec 2 14:37:34 2022 +0200

    JCOMOIDC-38 - Move various support classes from the OP plugin
    
    https://shibboleth.atlassian.net/browse/JCOMOIDC-38
    
    Imported and modified the unit tests for FormOutboundKeySetResponseMessage
    from OP.
---
 oidc-common-profile-impl/pom.xml                   |   5 +
 .../FormOutboundKeySetResponseMessageTest.java     | 181 +++++++++++++++++++++
 .../resources/credentials/idp-encryption-rsa.jwk   |   8 +
 .../test/resources/credentials/idp-signing-es.jwk  |  10 ++
 .../test/resources/credentials/idp-signing-rs.jwk  |   8 +
 5 files changed, 212 insertions(+)

diff --git a/oidc-common-profile-impl/pom.xml b/oidc-common-profile-impl/pom.xml
index 1e85540..d591eeb 100644
--- a/oidc-common-profile-impl/pom.xml
+++ b/oidc-common-profile-impl/pom.xml
@@ -73,6 +73,11 @@
             <scope>test</scope>
             <type>test-jar</type>
         </dependency>
+        <dependency>
+            <groupId>net.shibboleth.idp</groupId>
+            <artifactId>idp-profile-spring</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 
diff --git a/oidc-common-profile-impl/src/test/java/net/shibboleth/oidc/profile/impl/FormOutboundKeySetResponseMessageTest.java b/oidc-common-profile-impl/src/test/java/net/shibboleth/oidc/profile/impl/FormOutboundKeySetResponseMessageTest.java
new file mode 100644
index 0000000..31569ed
--- /dev/null
+++ b/oidc-common-profile-impl/src/test/java/net/shibboleth/oidc/profile/impl/FormOutboundKeySetResponseMessageTest.java
@@ -0,0 +1,181 @@
+/*
+ * 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.oidc.profile.impl;
+
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.minidev.json.JSONArray;
+import net.minidev.json.JSONObject;
+import net.shibboleth.idp.profile.IdPEventIds;
+import net.shibboleth.idp.profile.context.RelyingPartyContext;
+import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
+import net.shibboleth.idp.profile.testing.ActionTestingSupport;
+import net.shibboleth.idp.profile.testing.RequestContextBuilder;
+import net.shibboleth.oidc.profile.config.OIDCPublishKeySetConfiguration;
+import net.shibboleth.oidc.profile.config.OIDCSecurityConfiguration;
+import net.shibboleth.oidc.profile.config.navigate.JWKCredentialsToPublishLookupStrategy;
+import net.shibboleth.oidc.profile.messaging.JSONSuccessResponse;
+import net.shibboleth.oidc.security.JWTDecryptionConfiguration;
+import net.shibboleth.oidc.security.JWTSignatureSigningConfiguration;
+import net.shibboleth.oidc.security.credential.impl.ReturnAllCollectionJOSEObjectCredentialResolver;
+import net.shibboleth.oidc.security.impl.BasicJWKCredentialFactoryBean;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+import org.mockito.Mockito;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.security.credential.Credential;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.webflow.execution.Event;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import com.nimbusds.jose.JOSEException;
+import com.nimbusds.oauth2.sdk.ParseException;
+
+/** {@link FormOutboundKeySetResponseMessage} unit test. */
+public class FormOutboundKeySetResponseMessageTest {
+
+    private ProfileRequestContext profileRequestCtx;
+
+    private FormOutboundKeySetResponseMessage action;
+
+    private RequestContext requestCtx;
+
+    private OIDCPublishKeySetConfiguration profileConf;
+
+    private RelyingPartyContext rpCtx;
+
+    @BeforeMethod
+    public void init() throws Exception {
+        requestCtx = new RequestContextBuilder().buildRequestContext();
+        final MessageContext msgCtx = new MessageContext();
+        profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+        profileRequestCtx.setOutboundMessageContext(msgCtx);
+        rpCtx = profileRequestCtx.getSubcontext(RelyingPartyContext.class, true);
+
+        final List<Credential> signCreds = new ArrayList<Credential>();
+        BasicJWKCredentialFactoryBean factory = new BasicJWKCredentialFactoryBean();
+        factory.setResource(new ClassPathResource("credentials/idp-signing-es.jwk"));
+        factory.afterPropertiesSet();
+        signCreds.add(factory.getObject());
+
+        factory = new BasicJWKCredentialFactoryBean();
+        factory.setResource(new ClassPathResource("credentials/idp-signing-rs.jwk"));
+        factory.afterPropertiesSet();
+        signCreds.add(factory.getObject());
+
+        factory = new BasicJWKCredentialFactoryBean();
+        factory.setResource(new ClassPathResource("credentials/idp-encryption-rsa.jwk"));
+        factory.afterPropertiesSet();
+        final List<Credential> encCreds = new ArrayList<>();
+        encCreds.add(factory.getObject());
+
+        final JWTSignatureSigningConfiguration signConfig = Mockito.mock(JWTSignatureSigningConfiguration.class);
+        Mockito.when(signConfig.getSigningCredentials()).thenReturn(signCreds);
+        final JWTDecryptionConfiguration decConfig = Mockito.mock(JWTDecryptionConfiguration.class);
+        final ReturnAllCollectionJOSEObjectCredentialResolver resolver = new ReturnAllCollectionJOSEObjectCredentialResolver(encCreds);
+        Mockito.when(decConfig.getKEKCredentialResolver()).thenReturn(resolver);
+        final OIDCSecurityConfiguration secConf = new OIDCSecurityConfiguration();
+        secConf.setJwtSignatureSigningConfiguration(signConfig);
+        secConf.setJwtDecryptionConfiguration(decConfig);
+
+        profileConf = new OIDCPublishKeySetConfiguration();
+        profileConf.setSecurityConfiguration(secConf);
+        rpCtx.setProfileConfig(profileConf);
+        action = new FormOutboundKeySetResponseMessage();
+        action.setCredentialsToPublishLookupStrategy(new JWKCredentialsToPublishLookupStrategy());
+        action.initialize();
+    }
+
+    /**
+     * Test that action is able to form success message.
+     * 
+     * @throws ComponentInitializationException 
+     * @throws URISyntaxException 
+     * @throws java.text.ParseException
+     * @throws JOSEException 
+     */
+    @Test
+    public void testSuccessMessage() throws ComponentInitializationException, URISyntaxException, ParseException,
+            JOSEException, java.text.ParseException {
+        final Event event = action.execute(requestCtx);
+        ActionTestingSupport.assertProceedEvent(event);
+        Assert.assertTrue(profileRequestCtx.getOutboundMessageContext().getMessage() instanceof JSONSuccessResponse);
+        final JSONSuccessResponse resp =
+                (JSONSuccessResponse) profileRequestCtx.getOutboundMessageContext().getMessage();
+        Assert.assertTrue(resp.indicatesSuccess());
+        final JSONObject keyset = resp.toHTTPResponse().getContentAsJSONObject();
+        final JSONArray keys = (JSONArray) keyset.get("keys");
+        //The test for content could be more thorough
+        Assert.assertEquals(keys.size(), 3);
+    }
+
+    /**
+     * Test case of no sec conf.
+     * 
+     * @throws ComponentInitializationException 
+     * @throws URISyntaxException 
+     * @throws ParseException 
+     * @throws JOSEException 
+     */
+    @Test
+    public void testFailNoSecConf()
+            throws ComponentInitializationException, URISyntaxException, ParseException, JOSEException {
+        profileConf.setSecurityConfiguration(null);
+        final Event event = action.execute(requestCtx);
+        ActionTestingSupport.assertEvent(event, EventIds.INVALID_SEC_CFG);
+    }
+
+    /**
+     * Test case of no profile conf.
+     * 
+     * @throws ComponentInitializationException 
+     * @throws URISyntaxException 
+     * @throws ParseException 
+     * @throws JOSEException 
+     */
+    @Test
+    public void testFailNoProfileConf()
+            throws ComponentInitializationException, URISyntaxException, ParseException, JOSEException {
+        rpCtx.setProfileConfig(null);
+        final Event event = action.execute(requestCtx);
+        ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_RELYING_PARTY_CTX);
+    }
+
+    /**
+     * Test case of no rp ctx.
+     * 
+     * @throws ComponentInitializationException 
+     * @throws URISyntaxException 
+     * @throws ParseException 
+     * @throws JOSEException 
+     */
+    @Test
+    public void testFailNoRPCtx()
+            throws ComponentInitializationException, URISyntaxException, ParseException, JOSEException {
+        profileRequestCtx.removeSubcontext(RelyingPartyContext.class);
+        final Event event = action.execute(requestCtx);
+        ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_RELYING_PARTY_CTX);
+    }
+
+}
\ No newline at end of file
diff --git a/oidc-common-profile-impl/src/test/resources/credentials/idp-encryption-rsa.jwk b/oidc-common-profile-impl/src/test/resources/credentials/idp-encryption-rsa.jwk
new file mode 100644
index 0000000..eac1654
--- /dev/null
+++ b/oidc-common-profile-impl/src/test/resources/credentials/idp-encryption-rsa.jwk
@@ -0,0 +1,8 @@
+{
+  "kty": "RSA",
+  "d": "Esm7LsGF00otVYbCR7-D98bniDi6UpM9iAS10f_oSmGZjMmUWdSoeTfjHOTvC3mzten2aKxbDgBOT3_Xd2N3lx_z5P65Ui7dMkrgcuaKGkCsWMglHbNfNsUpKKuTGQ9dmujq7XGnxqoEi-ipWqeSqg0NJJh0qQAcR8fxjMFiUvx_iqxdTi0XzEgjQvBDvYcnPuB1ojR9QKboGgyxKLm9qlKZMs8tJciEsv0BCDovDVrStd9H3gRRBAOqP9XpgtoSGaBAWIsn4mofjxCAbwFedFva6EOcA6MyOzYa9eHfTubjD4BJBNFif9rUUfND7vgpig_eUs5Df-EMA4CBqxfK4Q",
+  "e": "AQAB",
+  "use": "enc",
+  "kid": "testkeyRSAEncryption",
+  "n": "47mkdLGrenv7QFkAWv1JryydVjq8HsEVCKz-qRttVe2II1-lQc-4sObf-9X0LtAwdtK0g1_EpRzZNuGaK2nFISr9uZQQ5evNHETgUKE2oKJs3r0wnfgvEZVHV6wXg4B7NRmDBgphExIYndBt__L-tC9_S_isaJOXQ_PAx17621pmxdyg8WEnJx9Azc23vH-Cii0ttMxDLNqUTu-tdgtZ8eo0IX7VPBWAnXVi0bRKHJuuvzJ4B8QqwsZsj8hGrwqNkRMoJVEiz-5M6ACLo-rgGNjtCBJRaezolrHSCc-r-hZbAaBKq0dOPRNPcMtRm8TUdmuRKBY7rXaFi7zGV7XDdw"
+}
diff --git a/oidc-common-profile-impl/src/test/resources/credentials/idp-signing-es.jwk b/oidc-common-profile-impl/src/test/resources/credentials/idp-signing-es.jwk
new file mode 100644
index 0000000..830b371
--- /dev/null
+++ b/oidc-common-profile-impl/src/test/resources/credentials/idp-signing-es.jwk
@@ -0,0 +1,10 @@
+{
+  "kty": "EC",
+  "d": "CO-ctmQcB-hS042i2omOIPpaaAaKkBAU6s_v4W09oA0",
+  "use": "sig",
+  "crv": "P-256",
+  "kid": "testkeyES",
+  "x": "2uzfE1oK0cf1_c11SFc9vFdGLnJoH3e0AKTrGPAmUis",
+  "y": "14410NGKqwLM58b26ZcvGOruFixpHt_SJTw8I5wwgLQ",
+  "alg": "ES256"
+}
diff --git a/oidc-common-profile-impl/src/test/resources/credentials/idp-signing-rs.jwk b/oidc-common-profile-impl/src/test/resources/credentials/idp-signing-rs.jwk
new file mode 100644
index 0000000..ffecaa1
--- /dev/null
+++ b/oidc-common-profile-impl/src/test/resources/credentials/idp-signing-rs.jwk
@@ -0,0 +1,8 @@
+{
+  "kty": "RSA",
+  "d": "gv7aqFcXV86jDcCn6-JCqEEIRcv1Rh1AEv4dKziFzQal1nROliDdtkJjELpOYlFY9CgI-xAXt8ivwJ4q1eA_G9WTId7qLxPdcQW4QjfRl8VVEPUhka6Gc8y95WUO4VONEwzZnZ4V7KobE0QGADXvXUw3MtIZdGgvRCS-6avQXITjhTnlkUONxeqpy2BE6l0cI8GSM1vlLy66vjsQ06aAizMB-g3yMMpbKNd73oYgrdpEjAtddH3-sLhv_TG7pMlbB_etnPGkWKdIbpvTKr2P2oZN_8Qvq7G4ETIe9nIv7i8T7GXZfTxWspYkszbrpRACM9Ic8fSctvil2j013JeSgQ",
+  "e": "AQAB",
+  "use": "sig",
+  "kid": "testkeyRS",
+  "n": "pNf03ghVzMAw5sWrwDAMAZdSYNY2q7OVlxMInljMgz8XB5mf8XKH3EtP7AKrb8IAf7rGhfuH3T1N1C7F-jwIeYjXxMm2nIAZ0hXApgbccvBpf4n2H7IZflMjt4A3tt587QQSxQ069drCP4sYevxhTcLplJy6RWA0cLj-5CHyWy94zPeeA4GRd6xgHFLz0RNiSF0pF0kE4rmRgQVZ-b4_BmD9SsWnIpwhms5Ihciw36WyAGQUeZqULGsfwAMwlNLIaTCBLAoRgv370p-XsLrgz86pTkNBJqXP5GwI-ZfgiLmJuHjQ9l85KqHM87f-QdsqiV8KoRcslgXPqb6VOTJBVw"
+}

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


More information about the commits mailing list