[java-oidc-common] branch main updated: JCOMOIDC-38 - Move various support classes from the OP plugin
Phil Smart
philip.smart at jisc.ac.uk
Thu Nov 24 15:31:37 UTC 2022
This is an automated email from the git hooks/post-receive script.
philsmart 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=54dc34e645764b42629da39991dc31fb127786b5
The following commit(s) were added to refs/heads/main by this push:
new 54dc34e JCOMOIDC-38 - Move various support classes from the OP plugin
54dc34e is described below
commit 54dc34e645764b42629da39991dc31fb127786b5
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Nov 24 15:31:34 2022 +0000
JCOMOIDC-38 - Move various support classes from the OP plugin
- Copy OIDC response encoders. Use a simplified version of the
NimbusResponseEncoder - so that is not a direct copy.
https://shibboleth.atlassian.net/browse/JCOMOIDC-38
---
.../encoding/impl/OIDCResponseEncoderFactory.java | 83 ++++++++++++++++++++++
.../encoding/impl/SimpleNimbusResponseEncoder.java | 60 ++++++++++++++++
2 files changed, 143 insertions(+)
diff --git a/oidc-common-profile-impl/src/main/java/net/shibboleth/oidc/profile/encoding/impl/OIDCResponseEncoderFactory.java b/oidc-common-profile-impl/src/main/java/net/shibboleth/oidc/profile/encoding/impl/OIDCResponseEncoderFactory.java
new file mode 100644
index 0000000..1346da9
--- /dev/null
+++ b/oidc-common-profile-impl/src/main/java/net/shibboleth/oidc/profile/encoding/impl/OIDCResponseEncoderFactory.java
@@ -0,0 +1,83 @@
+/*
+ * 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.encoding.impl;
+
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.messaging.encoder.MessageEncoder;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.nimbusds.oauth2.sdk.Response;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * A source of encoders that first verifies a message being an instance of Nimbus
+ * {@link Response} and then returns the attached {@link MessageEncoder}.
+ */
+public class OIDCResponseEncoderFactory extends AbstractInitializableComponent
+ implements Function<ProfileRequestContext,MessageEncoder> {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(OIDCResponseEncoderFactory.class);
+
+ /** The message encoder to be returned by this factory. */
+ @NonnullAfterInit private MessageEncoder messageEncoder;
+
+ /**
+ * Set the message encoder to be returned by this factory.
+ * @param encoder What to set.
+ */
+ public void setMessageEncoder(@Nonnull final MessageEncoder encoder) {
+ messageEncoder = Constraint.isNotNull(encoder, "The message encoder cannot be null");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+
+ if (messageEncoder == null) {
+ throw new ComponentInitializationException("The message encoder cannot be null");
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Nullable public MessageEncoder apply(@Nullable final ProfileRequestContext input) {
+ final MessageContext messageContext = input != null ? input.getOutboundMessageContext() : null;
+ if (messageContext == null) {
+ log.error("No outbound message context available");
+ return null;
+ }
+ final Object message = messageContext.getMessage();
+ if (message == null || !(message instanceof Response)) {
+ log.error("Unexpected message in the outbound message context: {}", message);
+ }
+ return messageEncoder;
+ }
+
+}
\ No newline at end of file
diff --git a/oidc-common-profile-impl/src/main/java/net/shibboleth/oidc/profile/encoding/impl/SimpleNimbusResponseEncoder.java b/oidc-common-profile-impl/src/main/java/net/shibboleth/oidc/profile/encoding/impl/SimpleNimbusResponseEncoder.java
new file mode 100644
index 0000000..2c19d80
--- /dev/null
+++ b/oidc-common-profile-impl/src/main/java/net/shibboleth/oidc/profile/encoding/impl/SimpleNimbusResponseEncoder.java
@@ -0,0 +1,60 @@
+/*
+ * 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.encoding.impl;
+
+import java.io.IOException;
+
+import javax.annotation.Nonnull;
+import javax.servlet.http.HttpServletResponse;
+
+import org.opensaml.messaging.encoder.MessageEncodingException;
+import org.opensaml.messaging.encoder.servlet.AbstractHttpServletResponseMessageEncoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.nimbusds.oauth2.sdk.Response;
+import com.nimbusds.oauth2.sdk.http.HTTPResponse;
+import com.nimbusds.oauth2.sdk.http.ServletUtils;
+
+/**
+ * A message encodes that encodes the Nimbus a {@link Response} in the message context inside the attached
+ * {@link HttpServletResponse} by calling its {@link Response#toHTTPResponse()} method.
+ */
+public class SimpleNimbusResponseEncoder extends AbstractHttpServletResponseMessageEncoder {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(SimpleNimbusResponseEncoder.class);
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doEncode() throws MessageEncodingException {
+
+ if (!(getMessageContext().getMessage() instanceof Response)) {
+ throw new MessageEncodingException("Incorrect message type");
+ }
+
+ try {
+ final HttpServletResponse response = getHttpServletResponse();
+ final HTTPResponse resp = ((Response) getMessageContext().getMessage()).toHTTPResponse();
+ ServletUtils.applyHTTPResponse(resp, response);
+ } catch (final IOException e) {
+ throw new MessageEncodingException("Problem encoding response", e);
+ }
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list