[java-plugin-shibd] branch main updated: Add pass-through state token manager.
Scott Cantor
cantor.2 at osu.edu
Tue Aug 20 16:30:27 UTC 2024
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-plugin-shibd.
View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-shibd.git;a=commit;h=2fadac9d6df7f33aadc7dca4521741c82d6eb3ac
The following commit(s) were added to refs/heads/main by this push:
new 2fadac9 Add pass-through state token manager.
2fadac9 is described below
commit 2fadac9d6df7f33aadc7dca4521741c82d6eb3ac
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Aug 20 12:30:24 2024 -0400
Add pass-through state token manager.
---
.../net/shibboleth/sp/conf/agents-system.xml | 2 +
.../sp/impl/PassthroughStateTokenManager.java | 67 +++++++++++++++++++++
.../sp/impl/PassthroughStateTokenManagerTest.java | 69 ++++++++++++++++++++++
3 files changed, 138 insertions(+)
diff --git a/sp-conf-impl/src/main/resources/net/shibboleth/sp/conf/agents-system.xml b/sp-conf-impl/src/main/resources/net/shibboleth/sp/conf/agents-system.xml
index c40ac33..5d1f1ac 100644
--- a/sp-conf-impl/src/main/resources/net/shibboleth/sp/conf/agents-system.xml
+++ b/sp-conf-impl/src/main/resources/net/shibboleth/sp/conf/agents-system.xml
@@ -40,6 +40,8 @@
<bean id="shibboleth.SessionInitiators" parent="shibboleth.CommaDelimStringArray"
c:_0="%{sp.application.sessionInitiators:}" />
+ <bean id="shibboleth.PassthroughStateTokenManager" class="net.shibboleth.sp.impl.PassthroughStateTokenManager" lazy-init="true" />
+
<bean id="shibboleth.StorageStateTokenManager" class="net.shibboleth.sp.impl.StorageServiceStateTokenManager" lazy-init="true"
p:storageService-ref="#{'%{sp.stateToken.StorageService:shibboleth.StorageService}'.trim()}" />
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/impl/PassthroughStateTokenManager.java b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/PassthroughStateTokenManager.java
new file mode 100644
index 0000000..1ad88db
--- /dev/null
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/PassthroughStateTokenManager.java
@@ -0,0 +1,67 @@
+/*
+ * 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 net.shibboleth.sp.impl;
+
+import java.io.IOException;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+
+import net.shibboleth.shared.codec.Base64Support;
+import net.shibboleth.shared.codec.DecodingException;
+import net.shibboleth.shared.codec.EncodingException;
+import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.sp.Agent;
+import net.shibboleth.sp.Application;
+import net.shibboleth.sp.StateTokenManager;
+
+/**
+ * {@link StateTokenManager} implemented as a simple pass-through that doesn't mask the data.
+ */
+public class PassthroughStateTokenManager extends AbstractIdentifiableInitializableComponent
+ implements StateTokenManager {
+
+ /** Class logger. */
+ @Nonnull private Logger log = LoggerFactory.getLogger(PassthroughStateTokenManager.class);
+
+ /** {@inheritDoc} */
+ @Override
+ @Nonnull public String preserveToStateToken(@Nonnull final Agent agent, @Nonnull final Application application,
+ @Nonnull final byte[] value) throws IOException {
+
+ try {
+ return Base64Support.encodeURLSafe(value);
+ } catch (final EncodingException e) {
+ throw new IOException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable public byte[] recoverFromStateToken(@Nonnull final Agent agent, @Nonnull final Application application,
+ @Nonnull final String token) throws IOException {
+
+ try {
+ return Base64Support.decodeURLSafe(token);
+ } catch (final DecodingException e) {
+ log.warn("Unable to Base64-decode state token: {}", token);
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/impl/PassthroughStateTokenManagerTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/impl/PassthroughStateTokenManagerTest.java
new file mode 100644
index 0000000..d20e3f3
--- /dev/null
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/impl/PassthroughStateTokenManagerTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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 net.shibboleth.sp.impl;
+
+import java.io.IOException;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.sp.profile.impl.BaseAgplicationActionTest;
+
+/**
+ * Unit tests for {@link PassthroughStateTokenManager}.
+ */
+ at SuppressWarnings("javadoc")
+public class PassthroughStateTokenManagerTest extends BaseAgplicationActionTest {
+
+ private PassthroughStateTokenManager stateManager;
+
+ @BeforeClass
+ public void setUp() throws ComponentInitializationException {
+
+ stateManager = new PassthroughStateTokenManager();
+ stateManager.setId("test");
+ stateManager.initialize();
+ }
+
+ @AfterClass
+ public void tearDown() {
+ stateManager.destroy();
+ }
+
+ @BeforeMethod
+ public void beforeMethod() throws ComponentInitializationException {
+ super.beforeMethod();
+ }
+
+ @Test
+ public void testInvalid() throws IOException {
+ Assert.assertNull(stateManager.recoverFromStateToken(agent, application, "123"));
+ }
+
+ @Test
+ public void testMapRecover() throws IOException {
+
+ final String token = stateManager.preserveToStateToken(agent, application, "foo".getBytes());
+ assert token != null;
+
+ final byte[] original = stateManager.recoverFromStateToken(agent, application, token);
+ Assert.assertEquals(original, "foo".getBytes());
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list