Skip to content

Commit b2ea0ba

Browse files
committed
Polish SessionIdChangedEvent
Add AbstractSessionEvent; clean up license headers and Javadocs Fixes: gh-5438
1 parent 5fc6414 commit b2ea0ba

File tree

6 files changed

+69
-26
lines changed

6 files changed

+69
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.core.session;
18+
19+
import org.springframework.context.ApplicationEvent;
20+
21+
/**
22+
* Abstract superclass for all session related events.
23+
*
24+
* @author Eleftheria Stein
25+
* @since 5.4
26+
*/
27+
public class AbstractSessionEvent extends ApplicationEvent {
28+
29+
public AbstractSessionEvent(Object source) {
30+
super(source);
31+
}
32+
}

core/src/main/java/org/springframework/security/core/session/SessionCreationEvent.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,16 +15,14 @@
1515
*/
1616
package org.springframework.security.core.session;
1717

18-
import org.springframework.context.ApplicationEvent;
19-
2018
/**
2119
* Generic session creation event which indicates that a session (potentially represented
2220
* by a security context) has begun.
2321
*
2422
* @author Luke Taylor
2523
* @since 3.0
2624
*/
27-
public abstract class SessionCreationEvent extends ApplicationEvent {
25+
public abstract class SessionCreationEvent extends AbstractSessionEvent {
2826

2927
public SessionCreationEvent(Object source) {
3028
super(source);

core/src/main/java/org/springframework/security/core/session/SessionDestroyedEvent.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.security.core.session;
1717

18-
import org.springframework.context.ApplicationEvent;
1918
import org.springframework.security.core.context.SecurityContext;
2019

2120
import java.util.*;
@@ -27,7 +26,7 @@
2726
* @author Luke Taylor
2827
* @since 3.0
2928
*/
30-
public abstract class SessionDestroyedEvent extends ApplicationEvent {
29+
public abstract class SessionDestroyedEvent extends AbstractSessionEvent {
3130

3231
public SessionDestroyedEvent(Object source) {
3332
super(source);
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,15 +15,30 @@
1515
*/
1616
package org.springframework.security.core.session;
1717

18-
import org.springframework.context.ApplicationEvent;
19-
20-
public abstract class SessionIdChangedEvent extends ApplicationEvent {
18+
/**
19+
* Generic "session ID changed" event which indicates that a session
20+
* identifier (potentially represented by a security context) has changed.
21+
*
22+
* @since 5.4
23+
*/
24+
public abstract class SessionIdChangedEvent extends AbstractSessionEvent {
2125

2226
public SessionIdChangedEvent(Object source) {
2327
super(source);
2428
}
2529

30+
/**
31+
* Returns the old session ID.
32+
*
33+
* @return the identifier that was previously associated with
34+
* the session.
35+
*/
2636
public abstract String getOldSessionId();
2737

38+
/**
39+
* Returns the new session ID.
40+
*
41+
* @return the new identifier that is associated with the session.
42+
*/
2843
public abstract String getNewSessionId();
2944
}

core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21-
import org.springframework.context.ApplicationEvent;
2221
import org.springframework.context.ApplicationListener;
2322
import org.springframework.util.Assert;
2423

@@ -41,7 +40,7 @@
4140
* @author Luke Taylor
4241
*/
4342
public class SessionRegistryImpl implements SessionRegistry,
44-
ApplicationListener<ApplicationEvent> {
43+
ApplicationListener<AbstractSessionEvent> {
4544

4645
// ~ Instance fields
4746
// ================================================================================================
@@ -102,7 +101,7 @@ public SessionInformation getSessionInformation(String sessionId) {
102101
return sessionIds.get(sessionId);
103102
}
104103

105-
public void onApplicationEvent(ApplicationEvent event) {
104+
public void onApplicationEvent(AbstractSessionEvent event) {
106105
if (event instanceof SessionDestroyedEvent) {
107106
SessionDestroyedEvent sessionDestroyedEvent = (SessionDestroyedEvent) event;
108107
String sessionId = sessionDestroyedEvent.getId();
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,33 +16,33 @@
1616

1717
package org.springframework.security.web.session;
1818

19-
import javax.servlet.http.HttpSession;
20-
2119
import org.springframework.security.core.session.SessionIdChangedEvent;
2220

21+
import javax.servlet.http.HttpSession;
22+
2323
/**
24-
* Published by the {@link HttpSessionEventPublisher} when an {@code HttpSession} id
25-
* is changed
24+
* Published by the {@link HttpSessionEventPublisher} when an {@link HttpSession} ID
25+
* is changed.
2626
*
27+
* @since 5.4
2728
*/
2829
public class HttpSessionIdChangedEvent extends SessionIdChangedEvent {
2930
private final String oldSessionId;
30-
private final String newSessionid;
31-
// ~ Constructors
32-
// ===================================================================================================
31+
private final String newSessionId;
3332

3433
public HttpSessionIdChangedEvent(HttpSession session, String oldSessionId) {
3534
super(session);
3635
this.oldSessionId = oldSessionId;
37-
this.newSessionid = session.getId();
36+
this.newSessionId = session.getId();
3837
}
3938

39+
@Override
4040
public String getOldSessionId() {
4141
return oldSessionId;
4242
}
4343

4444
@Override
4545
public String getNewSessionId() {
46-
return newSessionid;
46+
return newSessionId;
4747
}
4848
}

0 commit comments

Comments
 (0)