Skip to content

Commit

Permalink
Polish SessionIdChangedEvent
Browse files Browse the repository at this point in the history
Add AbstractSessionEvent; clean up license headers and Javadocs

Fixes: gh-5438
  • Loading branch information
eleftherias committed Mar 6, 2020
1 parent 5fc6414 commit b2ea0ba
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,16 +15,14 @@
*/
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.
*
* @author Luke Taylor
* @since 3.0
*/
public abstract class SessionCreationEvent extends ApplicationEvent {
public abstract class SessionCreationEvent extends AbstractSessionEvent {

public SessionCreationEvent(Object source) {
super(source);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.*;
Expand All @@ -27,7 +26,7 @@
* @author Luke Taylor
* @since 3.0
*/
public abstract class SessionDestroyedEvent extends ApplicationEvent {
public abstract class SessionDestroyedEvent extends AbstractSessionEvent {

public SessionDestroyedEvent(Object source) {
super(source);
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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;

Expand All @@ -41,7 +40,7 @@
* @author Luke Taylor
*/
public class SessionRegistryImpl implements SessionRegistry,
ApplicationListener<ApplicationEvent> {
ApplicationListener<AbstractSessionEvent> {

// ~ Instance fields
// ================================================================================================
Expand Down Expand Up @@ -102,7 +101,7 @@ public SessionInformation getSessionInformation(String sessionId) {
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}
}

0 comments on commit b2ea0ba

Please sign in to comment.