forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide an Actuator endpoint for non-indexed session repositories
At present, Actuator sessions endpoint is supported only on a Servlet stack and also requires an indexed session repository. With Spring Session moving to non-indexed session repositories as a default for some session stores, this means that sessions endpoint won't be available unless users opt into a (non-default) indexed session repository. This commit updates SessionEndpoint so that it is able to work with a non-indexed session repository. In such setup, it exposes operations for fetching session by id and deleting the session. Additionally, this also adds support for reactive stack by introducing ReactiveSessionEndpoint and its auto-configuration support. See spring-projectsgh-32046
- Loading branch information
1 parent
a1071f6
commit 478e4db
Showing
11 changed files
with
479 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ator/src/main/java/org/springframework/boot/actuate/session/ReactiveSessionsEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2012-2022 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.boot.actuate.session; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation; | ||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; | ||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; | ||
import org.springframework.boot.actuate.endpoint.annotation.Selector; | ||
import org.springframework.session.ReactiveSessionRepository; | ||
import org.springframework.session.Session; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* {@link Endpoint @Endpoint} to expose information about HTTP {@link Session}s on a | ||
* reactive stack. | ||
* | ||
* @author Vedran Pavic | ||
* @since 3.0.0 | ||
*/ | ||
@Endpoint(id = "sessions") | ||
public class ReactiveSessionsEndpoint { | ||
|
||
private final ReactiveSessionRepository<? extends Session> sessionRepository; | ||
|
||
/** | ||
* Create a new {@link ReactiveSessionsEndpoint} instance. | ||
* @param sessionRepository the session repository | ||
*/ | ||
public ReactiveSessionsEndpoint(ReactiveSessionRepository<? extends Session> sessionRepository) { | ||
Assert.notNull(sessionRepository, "ReactiveSessionRepository must not be null"); | ||
this.sessionRepository = sessionRepository; | ||
} | ||
|
||
@ReadOperation | ||
public Mono<SessionDescriptor> getSession(@Selector String sessionId) { | ||
return this.sessionRepository.findById(sessionId).map(SessionDescriptor::new); | ||
} | ||
|
||
@DeleteOperation | ||
public Mono<Void> deleteSession(@Selector String sessionId) { | ||
return this.sessionRepository.deleteById(sessionId); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...ot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2012-2022 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.boot.actuate.session; | ||
|
||
import java.time.Instant; | ||
import java.util.Set; | ||
|
||
import org.springframework.session.Session; | ||
|
||
/** | ||
* A description of user's {@link Session session} exposed by {@code sessions} endpoint. | ||
* Primarily intended for serialization to JSON. | ||
* | ||
* @author Vedran Pavic | ||
* @since 3.0.0 | ||
*/ | ||
public final class SessionDescriptor { | ||
|
||
private final String id; | ||
|
||
private final Set<String> attributeNames; | ||
|
||
private final Instant creationTime; | ||
|
||
private final Instant lastAccessedTime; | ||
|
||
private final long maxInactiveInterval; | ||
|
||
private final boolean expired; | ||
|
||
SessionDescriptor(Session session) { | ||
this.id = session.getId(); | ||
this.attributeNames = session.getAttributeNames(); | ||
this.creationTime = session.getCreationTime(); | ||
this.lastAccessedTime = session.getLastAccessedTime(); | ||
this.maxInactiveInterval = session.getMaxInactiveInterval().getSeconds(); | ||
this.expired = session.isExpired(); | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public Set<String> getAttributeNames() { | ||
return this.attributeNames; | ||
} | ||
|
||
public Instant getCreationTime() { | ||
return this.creationTime; | ||
} | ||
|
||
public Instant getLastAccessedTime() { | ||
return this.lastAccessedTime; | ||
} | ||
|
||
public long getMaxInactiveInterval() { | ||
return this.maxInactiveInterval; | ||
} | ||
|
||
public boolean isExpired() { | ||
return this.expired; | ||
} | ||
|
||
} |
Oops, something went wrong.