[java-opensaml] branch master updated: Remove deprecated storage service plugin.
Scott Cantor
cantor.2 at osu.edu
Fri Mar 8 13:16:07 EST 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=233f7c97f1e7ef4fae61e778d83e32c23d6e7461
The following commit(s) were added to refs/heads/master by this push:
new 233f7c9 Remove deprecated storage service plugin.
233f7c9 is described below
commit 233f7c97f1e7ef4fae61e778d83e32c23d6e7461
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Mar 8 13:16:02 2019 -0500
Remove deprecated storage service plugin.
---
.../storage/RequestScopedStorageService.java | 36 --
.../impl/ServletRequestScopedStorageService.java | 645 ---------------------
.../ServletRequestScopedStorageServiceTest.java | 161 -----
3 files changed, 842 deletions(-)
diff --git a/opensaml-storage-api/src/main/java/org/opensaml/storage/RequestScopedStorageService.java b/opensaml-storage-api/src/main/java/org/opensaml/storage/RequestScopedStorageService.java
deleted file mode 100644
index 5cc43d7..0000000
--- a/opensaml-storage-api/src/main/java/org/opensaml/storage/RequestScopedStorageService.java
+++ /dev/null
@@ -1,36 +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 org.opensaml.storage;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-/**
- * Specialization of {@link StorageService} that maintains its data on a per-request basis.
- *
- * <p>Implementations of this interface will typically be injected with objects or proxies
- * that supply access to the underlying request/response environment, such as servlets.</p>
- *
- * <p>Implementations of this interface are not required to guarantee coherency across requests
- * operating on the same initial data but must guarantee updates leave data in a consistent
- * state.</p>
- */
- at ThreadSafe
- at Deprecated
-public interface RequestScopedStorageService extends StorageService {
-
-}
\ No newline at end of file
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/ServletRequestScopedStorageService.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/ServletRequestScopedStorageService.java
deleted file mode 100644
index 7f99405..0000000
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/ServletRequestScopedStorageService.java
+++ /dev/null
@@ -1,645 +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 org.opensaml.storage.impl;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.security.KeyException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TimerTask;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import javax.json.Json;
-import javax.json.JsonException;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonStructure;
-import javax.json.JsonValue;
-import javax.json.stream.JsonGenerator;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
-
-import net.shibboleth.utilities.java.support.annotation.constraint.Live;
-import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
-import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.net.CookieManager;
-import net.shibboleth.utilities.java.support.net.URISupport;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
-import net.shibboleth.utilities.java.support.security.DataExpiredException;
-import net.shibboleth.utilities.java.support.security.DataSealer;
-import net.shibboleth.utilities.java.support.security.DataSealerException;
-import net.shibboleth.utilities.java.support.security.DataSealerKeyStrategy;
-
-import org.opensaml.storage.AbstractMapBackedStorageService;
-import org.opensaml.storage.MutableStorageRecord;
-import org.opensaml.storage.RequestScopedStorageService;
-import org.opensaml.storage.StorageCapabilitiesEx;
-import org.opensaml.storage.VersionMismatchException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Strings;
-import com.google.common.collect.Iterables;
-import com.google.common.escape.Escaper;
-import com.google.common.net.UrlEscapers;
-
-/**
- * Implementation of {@link RequestScopedStorageService} that stores data in-memory in a servlet request attribute,
- * and reads and writes the data with a secured string form using JSON as the underlying format.
- */
- at SuppressWarnings("deprecation")
-public class ServletRequestScopedStorageService extends AbstractMapBackedStorageService
- implements RequestScopedStorageService, Filter, StorageCapabilitiesEx {
-
- /** Name of request attribute for context map. */
- @Nonnull protected static final String CONTEXT_MAP_ATTRIBUTE =
- "org.opensaml.storage.impl.ServletRequestScopedStorageService.contextMap";
-
- /** Name of request attribute used as a dirty bit. */
- @Nonnull protected static final String DIRTY_BIT_ATTRIBUTE =
- "org.opensaml.storage.impl.ServletRequestScopedStorageService.dirty";
-
- /** Default cookie name for storage tracking. */
- @Nonnull @NotEmpty private static final String DEFAULT_COOKIE_NAME = "shib_idp_req_ss";
-
- /** A dummy lock implementation. */
- @Nonnull private static final ReadWriteLock DUMMY_LOCK;
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(ServletRequestScopedStorageService.class);
-
- /** Size to report for context, key, and value limits. */
- private int capabilitySize;
-
- /** Servlet request. */
- @NonnullAfterInit private HttpServletRequest httpServletRequest;
-
- /** Servlet response. */
- @NonnullAfterInit private HttpServletResponse httpServletResponse;
-
- /** Manages creation of cookies. */
- @NonnullAfterInit private CookieManager cookieManager;
-
- /** Name of cookie used to track storage. */
- @Nonnull @NotEmpty private String cookieName;
-
- /** DataSealer instance to secure data. */
- @NonnullAfterInit private DataSealer dataSealer;
-
- /** KeyStrategy enabling us to detect whether data has been sealed with an older key. */
- @Nullable private DataSealerKeyStrategy keyStrategy;
-
- /** URL encoder. */
- @Nonnull private Escaper escaper;
-
- /** Constructor. */
- public ServletRequestScopedStorageService() {
- cookieName = DEFAULT_COOKIE_NAME;
- capabilitySize = 4096;
- escaper = UrlEscapers.urlFormParameterEscaper();
- }
-
- /** {@inheritDoc} */
- @Override
- public synchronized void setCleanupInterval(final long interval) {
- // Don't allow a cleanup task.
- super.setCleanupInterval(0);
- }
-
- /**
- * Set the size to report via the {@link org.opensaml.storage.StorageCapabilities} interface for
- * context, key, and value maximums.
- *
- * <p>Defaults to 4096 to reflect the limitations of cookies on Safari.</p>
- *
- * @param size size in characters to report
- */
- public void setCapabilitySize(final int size) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- capabilitySize = size;
- }
-
- /**
- * Set the servlet request in which to manage per-request data.
- *
- * @param request servlet request in which to manage data
- */
- public void setHttpServletRequest(@Nonnull final HttpServletRequest request) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- httpServletRequest = Constraint.isNotNull(request, "HttpServletRequest cannot be null");
- }
-
- /**
- * Set the servlet response in which to manage per-request data.
- *
- * @param response servlet response in which to manage data
- */
- public void setHttpServletResponse(@Nonnull final HttpServletResponse response) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- httpServletResponse = Constraint.isNotNull(response, "HttpServletResponse cannot be null");
- }
-
- /**
- * Set the {@link CookieManager} to use.
- *
- * @param manager the CookieManager to use.
- */
- public void setCookieManager(@Nonnull final CookieManager manager) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- cookieManager = Constraint.isNotNull(manager, "CookieManager cannot be null");
- }
-
- /**
- * Get the cookie name to use for storage tracking.
- *
- * @return cookie name to use
- */
- @Nonnull @NotEmpty public String getCookieName() {
- return cookieName;
- }
-
- /**
- * Set the cookie name to use for storage tracking.
- *
- * @param name cookie name to use
- */
- public void setCookieName(@Nonnull @NotEmpty final String name) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- cookieName = Constraint.isNotNull(StringSupport.trimOrNull(name), "Cookie name cannot be null or empty");
- }
-
- /**
- * Set the {@link DataSealer} to use for data security.
- *
- * @param sealer {@link DataSealer} to use for data security
- */
- public void setDataSealer(@Nonnull final DataSealer sealer) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- dataSealer = Constraint.isNotNull(sealer, "DataSealer cannot be null");
- }
-
- /**
- * Set the {@link DataSealerKeyStrategy} to use for stale key detection.
- *
- * @param strategy {@link DataSealerKeyStrategy} to use for stale key detection
- */
- public void setKeyStrategy(@Nonnull final DataSealerKeyStrategy strategy) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- keyStrategy = strategy;
- }
-
- /** {@inheritDoc} */
- // Checkstyle: CyclomaticComplexity ON
-
- /** {@inheritDoc} */
- public boolean isServerSide() {
- return false;
- }
-
- /** {@inheritDoc} */
-
- /** {@inheritDoc} */
- public boolean isClustered() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void doInitialize() throws ComponentInitializationException {
- super.doInitialize();
-
- if (httpServletRequest == null || httpServletResponse == null) {
- throw new ComponentInitializationException("HttpServletRequest and HttpServletResponse must be set");
- } else if (dataSealer == null || cookieManager == null) {
- throw new ComponentInitializationException("DataSealer and CookieManager must be set");
- }
-
- setContextSize(capabilitySize);
- setKeySize(capabilitySize);
- setValueSize(capabilitySize);
- }
-
- /** {@inheritDoc} */
- @Override
- public void init(final FilterConfig filterConfig) throws ServletException {
-
- }
-
- /** {@inheritDoc} */
- @Override
- public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
- throws IOException,
- ServletException {
- if (!(response instanceof HttpServletResponse)) {
- throw new ServletException("Response was not an HttpServletResponse");
- }
-
- // Intercept output operations and inject a save() operation at all applicable points.
- chain.doFilter(request, new OutputInterceptingHttpServletResponseProxy((HttpServletResponse) response));
- }
-
-// Checkstyle: CyclomaticComplexity|MethodLength|ReturnCount OFF
- /**
- * Reconstitute stored data.
- *
- * @throws IOException if an error occurs reconstituting the data
- */
- protected void load() throws IOException {
-
- final Map<String,Map<String,MutableStorageRecord>> contextMap = getContextMap();
-
- // Check for recursion. If load() is called directly, the above getter will
- // call us, which means we need to short-circuit the "outer" load call by
- // detecting that data has been loaded already.
- if (!contextMap.isEmpty()) {
- return;
- }
-
- log.trace("Loading storage state from cookie in current request");
-
- setDirty(false);
-
- // Search for our cookie.
- final Cookie[] cookies = httpServletRequest.getCookies();
- if (cookies == null) {
- return;
- }
-
- final Optional<Cookie> cookie =
- Iterables.tryFind(Arrays.asList(cookies), c -> c != null && c.getName().equals(cookieName));
-
- if (!cookie.isPresent() || Strings.isNullOrEmpty(cookie.get().getValue())) {
- return;
- }
-
- try {
- final StringBuffer keyAliasUsed = new StringBuffer();
- final String decrypted = dataSealer.unwrap(URISupport.doURLDecode(cookie.get().getValue()), keyAliasUsed);
-
- log.trace("Data after decryption: {}", decrypted);
-
- final JsonReader reader = Json.createReader(new StringReader(decrypted));
- final JsonStructure st = reader.read();
- if (!(st instanceof JsonObject)) {
- throw new IOException("Found invalid data structure while parsing context map");
- }
- final JsonObject obj = (JsonObject) st;
-
- for (final Map.Entry<String,JsonValue> context : obj.entrySet()) {
- if (context.getValue().getValueType() != JsonValue.ValueType.OBJECT) {
- contextMap.clear();
- throw new IOException("Found invalid data structure while parsing context map");
- }
-
- final JsonObject contextRecords = (JsonObject) context.getValue();
- for (final Map.Entry<String,JsonValue> record : contextRecords.entrySet()) {
-
- final JsonObject fields = (JsonObject) record.getValue();
- Long exp = null;
- if (fields.containsKey("x")) {
- exp = fields.getJsonNumber("x").longValueExact();
- }
-
- create(context.getKey(), record.getKey(), fields.getString("v"), exp);
- }
- }
-
- if (keyStrategy != null) {
- try {
- setDirty(!keyStrategy.getDefaultKey().getFirst().equals(keyAliasUsed.toString()));
- } catch (final KeyException e) {
- log.error("Exception while accessing default key during stale key detection", e);
- setDirty(false);
- }
- } else {
- setDirty(false);
- }
- } catch (final NullPointerException | ClassCastException | ArithmeticException | JsonException e) {
- contextMap.clear();
- setDirty(true);
- log.error("Exception while parsing context map", e);
- throw new IOException("Found invalid data structure while parsing context map", e);
- } catch (final DataExpiredException e) {
- setDirty(true);
- log.debug("Secured data or key has expired");
- return;
- } catch (final DataSealerException e) {
- setDirty(true);
- log.error("Exception unwrapping secured data", e);
- throw new IOException("Exception unwrapping secured data", e);
- }
- }
-// Checkstyle: CyclomaticComplexity|MethodLength ON
-
-// Checkstyle: CyclomaticComplexity OFF
- /**
- * Write/preserve stored data for subsequent requests.
- *
- * @throws IOException if an error occurs preserving the data
- */
- @Nullable protected void save() throws IOException {
- if (!isDirty()) {
- log.trace("Storage state has not been modified during request, save operation skipped");
- return;
- }
-
- log.trace("Saving updated storage data to cookie");
-
- final Map<String, Map<String, MutableStorageRecord>> contextMap = getContextMap();
- if (contextMap.isEmpty()) {
- log.trace("Context map was empty, unsetting storage cookie");
- cookieManager.unsetCookie(cookieName);
- setDirty(false);
- return;
- }
-
- long exp = 0;
- final long now = System.currentTimeMillis();
- boolean empty = true;
-
- try {
- final StringWriter sink = new StringWriter(128);
- final JsonGenerator gen = Json.createGenerator(sink);
-
- gen.writeStartObject();
- for (final Map.Entry<String,Map<String, MutableStorageRecord>> context : contextMap.entrySet()) {
-
- gen.writeStartObject(context.getKey());
- for (final Map.Entry<String,MutableStorageRecord> entry : context.getValue().entrySet()) {
- final MutableStorageRecord record = entry.getValue();
- final Long recexp = record.getExpiration();
- if (recexp == null || recexp > now) {
- empty = false;
- gen.writeStartObject(entry.getKey())
- .write("v", record.getValue());
- if (recexp != null) {
- gen.write("x", record.getExpiration());
- exp = Math.max(exp, recexp);
- }
- gen.writeEnd();
- }
- }
- gen.writeEnd();
- }
- gen.writeEnd().close();
-
- if (empty) {
- log.trace("Context map was empty, unsetting storage cookie");
- cookieManager.unsetCookie(cookieName);
- setDirty(false);
- return;
- }
-
- final String toEncrypt = sink.toString();
- log.trace("Size of data before encryption is {}", toEncrypt.length());
- log.trace("Data before encryption is {}", toEncrypt);
-
- try {
- final String wrapped = dataSealer.wrap(toEncrypt, exp > 0 ? exp : now + 24 * 60 * 60 * 1000);
- log.trace("Size of data after encryption is {}", wrapped.length());
- cookieManager.addCookie(cookieName, escaper.escape(wrapped));
- setDirty(false);
- } catch (final DataSealerException e) {
- throw new IOException(e);
- }
- } catch (final JsonException e) {
- log.error("JsonException while serializing context map", e);
- throw new IOException(e);
- }
- }
-// Checkstyle: CyclomaticComplexity ON
-
- /** {@inheritDoc} */
- @Override
- @Nullable protected Long updateImpl(@Nullable final Long version, @Nonnull @NotEmpty final String context,
- @Nonnull @NotEmpty final String key, @Nullable final String value, @Nullable final Long expiration)
- throws IOException, VersionMismatchException {
- final Long i = super.updateImpl(version, context, key, value, expiration);
- if (i != null) {
- setDirty(true);
- }
- return i;
- }
-
- /** {@inheritDoc} */
- @Override
- @Nullable protected TimerTask getCleanupTask() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override
- @Nonnull @NonnullElements @Live protected Map<String, Map<String, MutableStorageRecord>> getContextMap() {
-
- final Object contextMap = httpServletRequest.getAttribute(CONTEXT_MAP_ATTRIBUTE + '.' + cookieName);
- if (contextMap != null) {
- return (Map<String, Map<String, MutableStorageRecord>>) contextMap;
- }
-
- final Map<String, Map<String, MutableStorageRecord>> newMap = new HashMap<>();
- httpServletRequest.setAttribute(CONTEXT_MAP_ATTRIBUTE + '.' + cookieName, newMap);
-
- // The first time through, do a load from the cookie.
- // Any subsequent calls to get the context map will return the previously set map.
- try {
- load();
- } catch (final IOException e) {
- setDirty(true);
- log.error("Error loading data from cookie, starting fresh", e);
- }
-
- return newMap;
- }
-
- /** {@inheritDoc} */
- @Override
- @Nonnull protected ReadWriteLock getLock() {
- return DUMMY_LOCK;
- }
-
- /** {@inheritDoc} */
- @Override
- public void setDirty() {
- setDirty(true);
- }
-
- /**
- * Set the dirty bit for the current request.
- *
- * @param flag dirty bit to set
- */
- private void setDirty(final boolean flag) {
- if (flag) {
- httpServletRequest.setAttribute(DIRTY_BIT_ATTRIBUTE + '.' + cookieName, Boolean.TRUE);
- } else {
- httpServletRequest.removeAttribute(DIRTY_BIT_ATTRIBUTE + '.' + cookieName);
- }
- }
-
- /**
- * Get the dirty bit for the current request.
- *
- * @return status of dirty bit
- */
- private boolean isDirty() {
- final Object dirty = httpServletRequest.getAttribute(DIRTY_BIT_ATTRIBUTE + '.' + cookieName);
- if (dirty != null && dirty instanceof Boolean) {
- return (Boolean) dirty;
- } else {
- return false;
- }
- }
-
- /**
- * An implementation of {@link HttpServletResponse} which detects a response going out
- * from a servlet and executes a save operation.
- */
- private class OutputInterceptingHttpServletResponseProxy extends HttpServletResponseWrapper {
-
- /**
- * Constructor.
- *
- * @param response the response to delegate to
- */
- public OutputInterceptingHttpServletResponseProxy(@Nonnull final HttpServletResponse response) {
- super(response);
- }
-
- /** {@inheritDoc} */
- public ServletOutputStream getOutputStream() throws IOException {
- save();
- return super.getOutputStream();
- }
-
- /** {@inheritDoc} */
- public PrintWriter getWriter() throws IOException {
- save();
- return super.getWriter();
- }
-
- /** {@inheritDoc} */
- public void sendError(final int sc, final String msg) throws IOException {
- save();
- super.sendError(sc, msg);
- }
-
- /** {@inheritDoc} */
- public void sendError(final int sc) throws IOException {
- save();
- super.sendError(sc);
- }
-
- /** {@inheritDoc} */
- public void sendRedirect(final String location) throws IOException {
- save();
- super.sendRedirect(location);
- }
-
-}
-
- /** Dummy shared lock that no-ops. */
- private static class DummyReadWriteLock implements ReadWriteLock {
-
- /** Dummy lock to return. */
- private static DummyLock lock;
-
- /** Constructor. */
- public DummyReadWriteLock() {
- lock = new DummyLock();
- }
-
- /** {@inheritDoc} */
- public Lock readLock() {
- return lock;
- }
-
- /** {@inheritDoc} */
- public Lock writeLock() {
- return lock;
- }
-
- /** Dummy lock that no-ops. */
- private static class DummyLock implements Lock {
-
- /** {@inheritDoc} */
- public void lock() {
-
- }
-
- /** {@inheritDoc} */
- public void lockInterruptibly() throws InterruptedException {
-
- }
-
- /** {@inheritDoc} */
- public boolean tryLock() {
- return true;
- }
-
- /** {@inheritDoc} */
- public boolean tryLock(final long time, final TimeUnit unit) throws InterruptedException {
- return true;
- }
-
- /** {@inheritDoc} */
- public void unlock() {
-
- }
-
- /** {@inheritDoc} */
- public Condition newCondition() {
- throw new UnsupportedOperationException("Conditions not supported");
- }
-
- }
- }
-
- static {
- DUMMY_LOCK = new DummyReadWriteLock();
- }
-}
\ No newline at end of file
diff --git a/opensaml-storage-impl/src/test/java/org/opensaml/storage/impl/ServletRequestScopedStorageServiceTest.java b/opensaml-storage-impl/src/test/java/org/opensaml/storage/impl/ServletRequestScopedStorageServiceTest.java
deleted file mode 100644
index 7b505cd..0000000
--- a/opensaml-storage-impl/src/test/java/org/opensaml/storage/impl/ServletRequestScopedStorageServiceTest.java
+++ /dev/null
@@ -1,161 +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 org.opensaml.storage.impl;
-
-import java.io.IOException;
-
-import javax.annotation.Nonnull;
-
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.net.CookieManager;
-import net.shibboleth.utilities.java.support.net.HttpServletRequestResponseContext;
-import net.shibboleth.utilities.java.support.net.ThreadLocalHttpServletRequestProxy;
-import net.shibboleth.utilities.java.support.net.ThreadLocalHttpServletResponseProxy;
-import net.shibboleth.utilities.java.support.resource.Resource;
-import net.shibboleth.utilities.java.support.resource.TestResourceConverter;
-import net.shibboleth.utilities.java.support.security.BasicKeystoreKeyStrategy;
-import net.shibboleth.utilities.java.support.security.DataSealer;
-
-import org.opensaml.storage.StorageRecord;
-import org.opensaml.storage.StorageService;
-import org.opensaml.storage.StorageServiceTest;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-/**
- * Test of {@link ServletRequestScopedStorageService} implementation.
- */
-public class ServletRequestScopedStorageServiceTest extends StorageServiceTest {
-
- private Resource keystoreResource;
- private Resource versionResource;
-
- /**
- * Convert the Spring resource to a java-support resource.
- *
- * @throws ComponentInitializationException
- */
- @BeforeClass public void setUp() throws ComponentInitializationException {
- ClassPathResource resource = new ClassPathResource("/org/opensaml/storage/impl/SealerKeyStore.jks");
- Assert.assertTrue(resource.exists());
- keystoreResource = TestResourceConverter.of(resource);
-
- resource = new ClassPathResource("/org/opensaml/storage/impl/SealerKeyStore.kver");
- Assert.assertTrue(resource.exists());
- versionResource = TestResourceConverter.of(resource);
-
- super.setUp();
- }
-
- /** {@inheritDoc} */
- @Override
- @Nonnull protected StorageService getStorageService() {
- final ServletRequestScopedStorageService ss = new ServletRequestScopedStorageService();
- ss.setId("test");
- ss.setCleanupInterval(0);
-
- final BasicKeystoreKeyStrategy strategy = new BasicKeystoreKeyStrategy();
-
- strategy.setKeyAlias("secret");
- strategy.setKeyPassword("kpassword");
- strategy.setKeystorePassword("password");
- strategy.setKeystoreResource(keystoreResource);
- strategy.setKeyVersionResource(versionResource);
-
- final DataSealer sealer = new DataSealer();
- sealer.setKeyStrategy(strategy);
-
- final CookieManager cookieManager = new CookieManager();
- cookieManager.setHttpServletRequest(new ThreadLocalHttpServletRequestProxy());
- cookieManager.setHttpServletResponse(new ThreadLocalHttpServletResponseProxy());
-
- try {
- strategy.initialize();
- sealer.initialize();
- cookieManager.initialize();
- } catch (ComponentInitializationException e) {
- Assert.fail(e.getMessage());
- }
-
- ss.setDataSealer(sealer);
- ss.setCookieManager(cookieManager);
- ss.setCookieName("test");
-
- ss.setHttpServletRequest(new ThreadLocalHttpServletRequestProxy());
- ss.setHttpServletResponse(new ThreadLocalHttpServletResponseProxy());
- return ss;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void threadInit() {
- super.threadInit();
- HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- }
-
- @Test public void invalidConfig() {
- ServletRequestScopedStorageService ss = new ServletRequestScopedStorageService();
-
- try {
- ss.initialize();
- Assert.fail();
- } catch (ComponentInitializationException e) {
-
- }
- }
-
- @Test(threadPoolSize = 10, invocationCount = 10, timeOut = 10000)
- public void loadSave() throws IOException {
- threadInit();
-
- MockHttpServletRequest mockRequest = (MockHttpServletRequest) HttpServletRequestResponseContext.getRequest();
- MockHttpServletResponse mockResponse = (MockHttpServletResponse) HttpServletRequestResponseContext.getResponse();
-
- ServletRequestScopedStorageService ss = (ServletRequestScopedStorageService) shared;
-
- ss.load();
-
- String context = Long.toString(random.nextLong());
-
- for (int i = 1; i <= 10; i++) {
- ss.create(context, Integer.toString(i), Integer.toString(i + 1), System.currentTimeMillis() + 300000);
- }
-
- ss.save();
- Assert.assertNotNull(mockResponse.getCookie("test"));
- mockRequest.setAttribute(ServletRequestScopedStorageService.CONTEXT_MAP_ATTRIBUTE + "." + ss.getCookieName(), null);
-
- for (int i = 1; i <= 10; i++) {
- Assert.assertNull(ss.read(context, Integer.toString(i)));
- }
-
- mockRequest.setCookies(mockResponse.getCookie("test"));
- ss.load();
- for (int i = 1; i <= 10; i++) {
- StorageRecord record = ss.read(context, Integer.toString(i));
- Assert.assertNotNull(record);
- Assert.assertEquals(record.getValue(), Integer.toString(i + 1));
- Assert.assertTrue(record.getExpiration() < System.currentTimeMillis() + 300000);
- }
- }
-
-}
\ 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