From b2ea0ba7754dfc78c47598c7f97b70dbb8718eb7 Mon Sep 17 00:00:00 2001 From: Eleftheria Stein Date: Fri, 6 Mar 2020 12:04:49 -0500 Subject: [PATCH] Polish SessionIdChangedEvent Add AbstractSessionEvent; clean up license headers and Javadocs Fixes: gh-5438 --- .../core/session/AbstractSessionEvent.java | 32 +++++++++++++++++++ .../core/session/SessionCreationEvent.java | 6 ++-- .../core/session/SessionDestroyedEvent.java | 5 ++- .../core/session/SessionIdChangedEvent.java | 25 ++++++++++++--- .../core/session/SessionRegistryImpl.java | 5 ++- .../session/HttpSessionIdChangedEvent.java | 22 ++++++------- 6 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 core/src/main/java/org/springframework/security/core/session/AbstractSessionEvent.java diff --git a/core/src/main/java/org/springframework/security/core/session/AbstractSessionEvent.java b/core/src/main/java/org/springframework/security/core/session/AbstractSessionEvent.java new file mode 100644 index 0000000000..5a43b2d6de --- /dev/null +++ b/core/src/main/java/org/springframework/security/core/session/AbstractSessionEvent.java @@ -0,0 +1,32 @@ +/* + * Copyright 2002-2020 the original author or authors. + * + * 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 + * + * https://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.springframework.security.core.session; + +import org.springframework.context.ApplicationEvent; + +/** + * Abstract superclass for all session related events. + * + * @author Eleftheria Stein + * @since 5.4 + */ +public class AbstractSessionEvent extends ApplicationEvent { + + public AbstractSessionEvent(Object source) { + super(source); + } +} diff --git a/core/src/main/java/org/springframework/security/core/session/SessionCreationEvent.java b/core/src/main/java/org/springframework/security/core/session/SessionCreationEvent.java index 677c40b721..97471c85e1 100644 --- a/core/src/main/java/org/springframework/security/core/session/SessionCreationEvent.java +++ b/core/src/main/java/org/springframework/security/core/session/SessionCreationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,6 @@ */ package org.springframework.security.core.session; -import org.springframework.context.ApplicationEvent; - /** * Generic session creation event which indicates that a session (potentially represented * by a security context) has begun. @@ -24,7 +22,7 @@ import org.springframework.context.ApplicationEvent; * @author Luke Taylor * @since 3.0 */ -public abstract class SessionCreationEvent extends ApplicationEvent { +public abstract class SessionCreationEvent extends AbstractSessionEvent { public SessionCreationEvent(Object source) { super(source); diff --git a/core/src/main/java/org/springframework/security/core/session/SessionDestroyedEvent.java b/core/src/main/java/org/springframework/security/core/session/SessionDestroyedEvent.java index e9e633f7d6..785c40c0e6 100644 --- a/core/src/main/java/org/springframework/security/core/session/SessionDestroyedEvent.java +++ b/core/src/main/java/org/springframework/security/core/session/SessionDestroyedEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package org.springframework.security.core.session; -import org.springframework.context.ApplicationEvent; import org.springframework.security.core.context.SecurityContext; import java.util.*; @@ -27,7 +26,7 @@ import java.util.*; * @author Luke Taylor * @since 3.0 */ -public abstract class SessionDestroyedEvent extends ApplicationEvent { +public abstract class SessionDestroyedEvent extends AbstractSessionEvent { public SessionDestroyedEvent(Object source) { super(source); diff --git a/core/src/main/java/org/springframework/security/core/session/SessionIdChangedEvent.java b/core/src/main/java/org/springframework/security/core/session/SessionIdChangedEvent.java index 8cefdeb348..640cdf7618 100644 --- a/core/src/main/java/org/springframework/security/core/session/SessionIdChangedEvent.java +++ b/core/src/main/java/org/springframework/security/core/session/SessionIdChangedEvent.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * 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 + * https://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, @@ -15,15 +15,30 @@ */ package org.springframework.security.core.session; -import org.springframework.context.ApplicationEvent; - -public abstract class SessionIdChangedEvent extends ApplicationEvent { +/** + * Generic "session ID changed" event which indicates that a session + * identifier (potentially represented by a security context) has changed. + * + * @since 5.4 + */ +public abstract class SessionIdChangedEvent extends AbstractSessionEvent { public SessionIdChangedEvent(Object source) { super(source); } + /** + * Returns the old session ID. + * + * @return the identifier that was previously associated with + * the session. + */ public abstract String getOldSessionId(); + /** + * Returns the new session ID. + * + * @return the new identifier that is associated with the session. + */ public abstract String getNewSessionId(); } diff --git a/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java b/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java index 041009cef7..fa00255902 100644 --- a/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java +++ b/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java @@ -18,7 +18,6 @@ package org.springframework.security.core.session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.util.Assert; @@ -41,7 +40,7 @@ import java.util.concurrent.CopyOnWriteArraySet; * @author Luke Taylor */ public class SessionRegistryImpl implements SessionRegistry, - ApplicationListener { + ApplicationListener { // ~ Instance fields // ================================================================================================ @@ -102,7 +101,7 @@ public class SessionRegistryImpl implements SessionRegistry, return sessionIds.get(sessionId); } - public void onApplicationEvent(ApplicationEvent event) { + public void onApplicationEvent(AbstractSessionEvent event) { if (event instanceof SessionDestroyedEvent) { SessionDestroyedEvent sessionDestroyedEvent = (SessionDestroyedEvent) event; String sessionId = sessionDestroyedEvent.getId(); diff --git a/web/src/main/java/org/springframework/security/web/session/HttpSessionIdChangedEvent.java b/web/src/main/java/org/springframework/security/web/session/HttpSessionIdChangedEvent.java index 9c824eafa4..28a0651be0 100644 --- a/web/src/main/java/org/springframework/security/web/session/HttpSessionIdChangedEvent.java +++ b/web/src/main/java/org/springframework/security/web/session/HttpSessionIdChangedEvent.java @@ -1,11 +1,11 @@ /* - * Copyright 2004, 2005, 2006 Acegi Technology Pty Limited + * Copyright 2002-2020 the original author or authors. * * 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 + * https://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, @@ -16,33 +16,33 @@ package org.springframework.security.web.session; -import javax.servlet.http.HttpSession; - import org.springframework.security.core.session.SessionIdChangedEvent; +import javax.servlet.http.HttpSession; + /** - * Published by the {@link HttpSessionEventPublisher} when an {@code HttpSession} id - * is changed + * Published by the {@link HttpSessionEventPublisher} when an {@link HttpSession} ID + * is changed. * + * @since 5.4 */ public class HttpSessionIdChangedEvent extends SessionIdChangedEvent { private final String oldSessionId; - private final String newSessionid; - // ~ Constructors - // =================================================================================================== + private final String newSessionId; public HttpSessionIdChangedEvent(HttpSession session, String oldSessionId) { super(session); this.oldSessionId = oldSessionId; - this.newSessionid = session.getId(); + this.newSessionId = session.getId(); } + @Override public String getOldSessionId() { return oldSessionId; } @Override public String getNewSessionId() { - return newSessionid; + return newSessionId; } }