Skip to content

Add session endpoints #5730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

eddumelendez
Copy link
Contributor

@eddumelendez eddumelendez commented Apr 19, 2016

  • I have signed the CLA

/cc @rwinch

/**
* Mark if the endpoint exposes sensitive information.
*/
private Boolean sensitive;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be wise to make this always sensitive

@eddumelendez eddumelendez force-pushed the session-endpoints branch 2 times, most recently from c000863 to ff4e449 Compare April 20, 2016 05:46
@jgoldhammer
Copy link

+1 for integrating it...

@philwebb
Copy link
Member

Does this expose session data for all users? Can you provide a bit more background about what use-cases are?

@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue for: team-attention An issue we'd like other members of the team to review and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 24, 2016
@vpavic
Copy link
Contributor

vpavic commented Apr 24, 2016

@philwebb See spring-projects/spring-session#407 for some background.

Exposing session data for all users is not possible since SessionRepository does not offer such functionality ATM.

@philwebb
Copy link
Member

@vpavic Thanks for the pointer.

@philwebb
Copy link
Member

@rwinch Any security considerations regarding exposing session data in this way?

@philwebb philwebb removed the status: waiting-for-feedback We need additional information before we can continue label Apr 24, 2016
@rwinch
Copy link
Member

rwinch commented Apr 25, 2016

@philwebb

I think this is going to be a very useful feature and would like to see it integrated. Eventually, I'd like to extend it to support log levels per user (I have a prototype of this working already).

Since this will allow access to any user's session, I view this as an opt in feature.

@philwebb
Copy link
Member

@rwinch OK, so perhaps like the shutdown endpoint users should specifically enable this one.

@philwebb philwebb added this to the 1.4.0.M3 milestone Apr 25, 2016
@jgoldhammer
Copy link

Anything to share, Rob? Just wanted to implement that for our application on top of a logbook and sifting appended to have a trac log for each user...

private FindByIndexNameSessionRepository<? extends ExpiringSession> sessionRepository;

@RequestMapping(path = "/{username}", method = RequestMethod.GET)
public Collection<? extends ExpiringSession> result(@PathVariable String username) {
Copy link
Contributor

@joshiste joshiste Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion it would be a better REST-style to turn username into a requestParameter.
I personally would expect a /{sessionId} to get a specific session and a ?username={username} to search for sessions asscoiated with the user.

@rwinch
Copy link
Member

rwinch commented Apr 25, 2016

@jgoldhammer Nothing new to report on that. I still haven't found time to put something formal together. You can find a sample at https://github.com/rwinch/spring-session-logging

@philwebb philwebb added the status: on-hold We can't start working on this issue yet label Apr 27, 2016
@philwebb
Copy link
Member

I think we'll need to refine this a little more. There are a couple of problems that we can foresee:

  • Returning ExpiringSession seems like it might cause problems since we're relying on Jackson to marshal it correctly. We should probably wrap it in a JSON friendly structure.
  • The rest calls are a little inconsistent. Calling GET /session/{var} expects a user, but DELETE /session/{var} expects the session ID. We should probably just use the session ID (as @joshiste suggests above).

@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Apr 27, 2016
@eddumelendez eddumelendez force-pushed the session-endpoints branch 2 times, most recently from adb3382 to 94c9eda Compare April 28, 2016 04:56
@eddumelendez
Copy link
Contributor Author

Thanks all for feedback. @philwebb I have updated the PR with your comments.

@joshiste
Copy link
Contributor

joshiste commented Apr 28, 2016

Currently your PR only provides a MvcEndpoint implementation, which doesn't gets registered as MBean and therefore is not accessible via JMX.
I would like to see the implementation split apart into a Endpoint implementation providing the functionality and the MvcEndpoint just providing the http interface for it. So it's also accessible with JMX.

... or is the SessionRepository already exported to JMX?

* @since 1.4.0
*/
@ConfigurationProperties("endpoints.session")
public class SessionMvcEndpoint extends WebMvcConfigurerAdapter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to extend the WebMvcConfigurerAdapter here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to let me know. I completely forget to remove this.

/**
* Session properties.
*/
public static class Session {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the representation of session should be modeled with more care considering the needs of potential consumer:

  • creationTime and lastAccessedTime should be converted to Date
  • is maxInactiveIntervalInSeconds really needed here?
  • consider providing at least some info about session attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right maxInactiveIntervalInSeconds doesn't make sense here.

Thanks for the suggestions

@wilkinsona
Copy link
Member

Thanks, @eddumelendez. I agree with @joshiste's latest comment. We don't do anything with the repository to export is as an MBean. I don't know if Spring Session does. For consistency, having our own JMX endpoint is appealing anyway.

A couple of other things to consider:

  • Should a delete of a non-existent session return a 404 rather than a 200 response?
  • Returning an array of sessions isn't very extensible. For example, it prevents the addition of HATEOAS links. I think it would be better to return a map with a single sessions entry.

One other thing that may just be my ignorance. How does an operator know the usernames to use when listing sessions? I realise that Spring Session does not provide an API for it, but would listing all sessions not be useful?

@vpavic
Copy link
Contributor

vpavic commented Apr 28, 2016

Any security considerations regarding exposing session data in this way?

OK, so perhaps like the shutdown endpoint users should specifically enable this one.

I'd like to see a more sophisticated approach to this:

  • it makes sense to provide every user with the ability to read and delete their own session(s)
  • reading and deleting sessions for any user should be limited to some role/authority

IMO this is better than simply disabling the endpoint by default.

@joshiste
Copy link
Contributor

joshiste commented Apr 28, 2016

it makes sense to provide every user with the ability to read and delete their own session(s)

What's the reasoning behind this? Usually this is exactly what a logout-button is for...
Since it's easier to have a all or nothing approach I don't think it should be done this way.

@vpavic
Copy link
Contributor

vpavic commented Apr 28, 2016

+1 for the JMX support, Spring Session does not export anything there by itself.

One other thing that may just be my ignorance. How does an operator know the usernames to use when listing sessions? I realise that Spring Session does not provide an API for it, but would listing all sessions not be useful?

Generally this is tied to security since this is where the Spring Session gets the info about the user. Spring Session itself and its APIs are not tied to security (check the FindByIndexNameSessionRepository#findByIndexNameAndIndexValue javadoc or reference manual on FindByIndexNameSessionRepository)

@vpavic
Copy link
Contributor

vpavic commented Apr 28, 2016

What's the reasoning behind this? Usually this is exactly what a logout-button is for...

Logout does the job for the current session. It is a common requirement to have an option to invalidate the session(s) you have on other clients.

See here (Sessions) as an example.

@joshiste
Copy link
Contributor

joshiste commented Apr 28, 2016

Logout does the job for the current session. It is a common requirement to have an option invalidate the session(s) you have on other clients.

Ok. Don't you think, when it's for your users (not your admins!), you should implement this with your own controller in your "business code" and not within an actuator endpoint?
Think of securing all endpoints a specific way (e.g. management.security.role) or binding them to some other port which doesn't get exposed to the user...

@vpavic
Copy link
Contributor

vpavic commented Apr 28, 2016

@joshiste I understand your reasoning but I don't see how having an option to do GET request that retrieves sessions for the currently authenticated user interferes with other functionalities?
Ultimately it's up to the user to decide how to use any given endpoint, that's why there are options to customize the behavior.

@wilkinsona
Copy link
Member

I agree with @joshiste. Actuator endpoints are intended for the operators of a service and not its users. If an app wants to support a user logging out across all devices, it should provide the UI and controller for it with appropriate authentication.

@joshiste
Copy link
Contributor

joshiste commented Apr 28, 2016

@joshiste I understand your reasoning but I don't see how having an option to do GET request that retrieves sessions for the currently authenticated user interferes with other functionalities?

My point was the finegrained security permissions and to keep a feature out, which is not in the scope of administration.

@vpavic
Copy link
Contributor

vpavic commented Apr 28, 2016

@joshiste Yes, the more I think of this the more I agree with you. Sorry for the noise and thanks for discussing!

@eddumelendez
Copy link
Contributor Author

Thanks all for the feedback and great discussion about this topic.

@wilkinsona I have updated the PR.

@philwebb philwebb modified the milestones: 1.4.0.RC1, 1.4.0.M3 May 14, 2016
@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label May 25, 2016
@philwebb philwebb removed this from the 1.4.0.RC1 milestone May 25, 2016
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Jun 22, 2016
@snicoll
Copy link
Member

snicoll commented Sep 20, 2017

Duplicate of #8342

@snicoll snicoll marked this as a duplicate of #8342 Sep 20, 2017
@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: on-hold We can't start working on this issue yet labels Sep 20, 2017
@eddumelendez eddumelendez deleted the session-endpoints branch January 17, 2018 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants