[java-idp-oidc] 02/02: Removed obsolote classes.
Henri Mikkonen
henri.mikkonen at iki.fi
Mon Feb 17 12:00:32 EST 2020
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch master
in repository java-idp-oidc.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=734952ed154f8e9421b4f9c8dfba8a23879930ab
commit 734952ed154f8e9421b4f9c8dfba8a23879930ab
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Mon Feb 17 18:59:36 2020 +0200
Removed obsolote classes.
---
.../oidc/profile/action/impl/EncodeMessage.java | 186 ---------------------
.../oidc/profile/action/impl/package-info.java | 20 ---
.../profile/action/impl/EncodeMessageTest.java | 154 -----------------
3 files changed, 360 deletions(-)
diff --git a/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/profile/action/impl/EncodeMessage.java b/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/profile/action/impl/EncodeMessage.java
deleted file mode 100644
index f8d48ef..0000000
--- a/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/profile/action/impl/EncodeMessage.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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.profile.action.impl;
-
-import java.util.function.Function;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-
-import org.opensaml.messaging.context.MessageContext;
-import org.opensaml.messaging.encoder.MessageEncoder;
-import org.opensaml.messaging.encoder.MessageEncodingException;
-import org.opensaml.messaging.handler.MessageHandler;
-import org.opensaml.messaging.handler.MessageHandlerException;
-import org.opensaml.profile.action.AbstractProfileAction;
-import org.opensaml.profile.action.ActionSupport;
-import org.opensaml.profile.action.EventIds;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * Based on {@link org.opensaml.profile.action.impl.EncodeMessage}.
- *
- * The difference is having encoder also directly injected without factory. TODO: Consider if we want to apply message
- * encoder factory and loose the direct injection. In the long run we should get rid of this copied class.
- *
- * Action that encodes an outbound response from the outbound {@link MessageContext}.
- *
- * <p>
- * A function is used to obtain a new {@link MessageEncoder} to use, and the encoder is destroyed
- * upon completion.
- * </p>
- *
- *
- * @event {@link EventIds#PROCEED_EVENT_ID}
- * @event {@link EventIds#INVALID_MSG_CTX}
- * @event {@link EventIds#UNABLE_TO_ENCODE}
- *
- * @post If ProfileRequestContext.getOutboundMessageContext() != null, it will be injected and encoded.
- */
-public class EncodeMessage extends AbstractProfileAction {
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(EncodeMessage.class);
-
- /** The factory to use to obtain an encoder. */
- @NonnullAfterInit private Function<ProfileRequestContext,MessageEncoder> encoderFactory;
-
- /** Message encoder. */
- @Nullable private MessageEncoder encoder;
-
- /**
- * An optional {@link MessageHandler} instance to be invoked after {@link MessageEncoder#prepareContext()} and prior
- * to {@link MessageEncoder#encode()}.
- */
- @Nullable
- private MessageHandler messageHandler;
-
- /** The outbound MessageContext to encode. */
- @Nullable
- private MessageContext msgContext;
-
- /**
- * Set the encoder factory to use.
- *
- * @param factory factory to use
- */
- public void setMessageEncoderFactory(@Nonnull final Function<ProfileRequestContext,MessageEncoder> factory) {
- encoderFactory = Constraint.isNotNull(factory, "MessageEncoder factory cannot be null");
- }
-
- /**
- * <p>
- * The supplied {@link MessageHandler} will be invoked on the {@link MessageContext} after
- * {@link MessageEncoder#prepareContext()}, and prior to invoking {@link MessageEncoder#encode()}. Its use is
- * optional and primarily used for transport/binding-specific message handling, as opposed to more generalized
- * message handling operations which would typically be invoked earlier than this action. For more details see
- * {@link MessageEncoder}.
- * </p>
- *
- * @param handler a message handler
- */
- public void setMessageHandler(@Nullable final MessageHandler handler) {
- messageHandler = handler;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void doInitialize() throws ComponentInitializationException {
- super.doInitialize();
-
- if (encoderFactory == null) {
- throw new ComponentInitializationException("MessageEncoder factory cannot be null");
- }
- }
-
- /** {@inheritDoc} */
- @Override
- protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-
- if (!super.doPreExecute(profileRequestContext)) {
- return false;
- }
-
- msgContext = profileRequestContext.getOutboundMessageContext();
- if (msgContext == null) {
- log.debug("{} Outbound message context was null", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MSG_CTX);
- return false;
- }
-
- encoder = encoderFactory.apply(profileRequestContext);
- if (encoder == null) {
- log.error("{} Unable to locate an outbound message encoder", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.UNABLE_TO_ENCODE);
- return false;
- }
-
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-
- try {
- log.debug("{} Encoding outbound response using message encoder of type {} for this response",
- getLogPrefix(), encoder.getClass().getName());
-
- if (!encoder.isInitialized()) {
- log.debug("{} Encoder was not initialized, injecting MessageContext and initializing", getLogPrefix());
- encoder.setMessageContext(msgContext);
- encoder.initialize();
- } else {
- log.debug("{} Encoder was already initialized, skipping MessageContext injection and init",
- getLogPrefix());
- }
-
- encoder.prepareContext();
-
- if (messageHandler != null) {
- log.debug("{} Invoking message handler of type {} for this response", getLogPrefix(),
- messageHandler.getClass().getName());
- messageHandler.invoke(msgContext);
- }
-
- encoder.encode();
-
- if (msgContext.getMessage() != null) {
- log.debug("{} Outbound message encoded from a message of type {}", getLogPrefix(),
- msgContext.getMessage().getClass().getName());
- } else {
- log.debug("{} Outbound message was encoded from protocol-specific data "
- + "rather than MessageContext#getMessage()", getLogPrefix());
- }
-
- } catch (final MessageEncodingException | ComponentInitializationException | MessageHandlerException e) {
- log.error("{} Unable to encode outbound response", getLogPrefix(), e);
- ActionSupport.buildEvent(profileRequestContext, EventIds.UNABLE_TO_ENCODE);
- } finally {
- // TODO: do we want to destroy the encoder here?
- encoder.destroy();
- }
- }
-
-}
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/profile/action/impl/package-info.java b/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/profile/action/impl/package-info.java
deleted file mode 100644
index 8b484ac..0000000
--- a/idp-oidc-extension-impl/src/main/java/org/geant/idpextension/oidc/profile/action/impl/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * Profile action implementations related to OIDC.
- */
-package org.geant.idpextension.oidc.profile.action.impl;
\ No newline at end of file
diff --git a/idp-oidc-extension-impl/src/test/java/org/geant/idpextension/oidc/profile/action/impl/EncodeMessageTest.java b/idp-oidc-extension-impl/src/test/java/org/geant/idpextension/oidc/profile/action/impl/EncodeMessageTest.java
deleted file mode 100644
index b4ef49c..0000000
--- a/idp-oidc-extension-impl/src/test/java/org/geant/idpextension/oidc/profile/action/impl/EncodeMessageTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-package org.geant.idpextension.oidc.profile.action.impl;
-
-import java.util.function.Function;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-import org.opensaml.messaging.context.MessageContext;
-import org.opensaml.messaging.decoder.MessageDecodingException;
-import org.opensaml.messaging.encoder.AbstractMessageEncoder;
-import org.opensaml.messaging.encoder.MessageEncoder;
-import org.opensaml.messaging.encoder.MessageEncodingException;
-import org.opensaml.profile.action.ActionTestingSupport;
-import org.opensaml.profile.action.EventIds;
-import org.opensaml.profile.action.impl.MockMessage;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Unit test for {@link EncodeMessage}. Tests that the original copied
- * functionality works still. Based on
- * {@link org.opensaml.profile.action.impl.EncodeMessageTest}
- */
-public class EncodeMessageTest {
-
- private MockMessage message;
-
- private MockMessageEncoder encoder;
-
- private MessageContext messageContext;
-
- private ProfileRequestContext profileCtx;
-
- private String expectedMessage;
-
- @BeforeMethod
- public void setUp() throws ComponentInitializationException {
- message = new MockMessage();
- message.getProperties().put("foo", "3");
- message.getProperties().put("bar", "1");
- message.getProperties().put("baz", "2");
-
- // Encoded mock message, keys sorted alphabetically, per
- // MockMessage#toString
- expectedMessage = "bar=1&baz=2&foo=3";
-
- messageContext = new MessageContext();
- messageContext.setMessage(message);
-
- profileCtx = new ProfileRequestContext();
- profileCtx.setOutboundMessageContext(messageContext);
-
- encoder = new MockMessageEncoder();
- // Note: we don't init the encoder, b/c that is done by the action after
- // setting the message context
- }
-
- @Test(expectedExceptions = ComponentInitializationException.class)
- public void testNoFactory() throws ComponentInitializationException {
- final EncodeMessage action = new EncodeMessage();
- action.initialize();
- }
-
- /** Test that the action proceeds properly if the message can be decoded. */
- @SuppressWarnings("unchecked")
- @Test
- public void testDecodeMessage() throws Exception {
- final EncodeMessage action = new EncodeMessage();
- action.setMessageEncoderFactory(new MockEncoderFactory());
- action.initialize();
-
- action.execute(profileCtx);
- ActionTestingSupport.assertProceedEvent(profileCtx);
-
- Assert.assertEquals(encoder.getEncodedMessage(), expectedMessage);
- }
-
- /**
- * Test that the action errors out properly if the message can not be
- * decoded.
- */
- @Test
- public void testThrowException() throws Exception {
- encoder.setThrowException(true);
-
- final EncodeMessage action = new EncodeMessage();
- action.setMessageEncoderFactory(new MockEncoderFactory());
- action.initialize();
-
- action.execute(profileCtx);
- ActionTestingSupport.assertEvent(profileCtx, EventIds.UNABLE_TO_ENCODE);
- }
-
- /**
- * Mock implementation of {@link MessageEncoder} which either returns a
- * {@link MessageContext} with a mock message or throws a
- * {@link MessageDecodingException}.
- */
- private class MockMessageEncoder extends AbstractMessageEncoder {
-
- /**
- * Whether a {@link MessageEncodingException} should be thrown by
- * {@link #doEncode()}.
- */
- private boolean throwException;
-
- /** Mock encoded message. */
- private String message;
-
- /**
- * Get the encoded message
- *
- * @return the string buffer
- */
- public String getEncodedMessage() {
- return message;
- }
-
- /**
- * Sets whether a {@link MessageEncodingException} should be thrown by
- * {@link #doEncode()}.
- *
- * @param shouldThrowDecodeException
- * true if an exception should be thrown, false if not
- */
- public void setThrowException(final boolean shouldThrowDecodeException) {
- throwException = shouldThrowDecodeException;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void doEncode() throws MessageEncodingException {
- if (throwException) {
- throw new MessageEncodingException();
- } else {
- message = ((MockMessage) getMessageContext().getMessage()).getEncoded();
- }
- }
- }
-
- private class MockEncoderFactory implements Function<ProfileRequestContext,MessageEncoder> {
-
- /** {@inheritDoc} */
- @Nullable public MessageEncoder apply(@Nonnull final ProfileRequestContext profileRequestContext) {
- return encoder;
- }
-
- }
-
-}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list