Skip to content

Adds command to list user sessions - #24675

Closed
MorrisJobke wants to merge 3 commits into
masterfrom
command-to-list-user-sessions
Closed

MorrisJobke wants to merge 3 commits into
masterfrom
command-to-list-user-sessions

Conversation

@MorrisJobke

@MorrisJobke MorrisJobke commented May 17, 2016 •

Copy link
Copy Markdown
Contributor

cc @LukasReschke @PVince81 @DeepDiver1975 @ChristophWurst @nickvergessen

@MorrisJobke MorrisJobke added this to the 9.1-current milestone May 17, 2016
@mention-bot

Copy link
Copy Markdown

By analyzing the blame information on this pull request, we identified @ChristophWurst, @nickvergessen and @schiesbn to be potential reviewers

* @param string $uid
* @return DefaultToken[]
*/
public function getTokenByUser($uid) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm open for naming suggestions :)

@ChristophWurst

Copy link
Copy Markdown
Contributor

Note that currently multiple IProviders could be used, but I'm working on a PR to remove that unnecessary complexity.

* @return IToken[]
* @since 9.1
*/
public function getTokenByUser($uid);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about passing an IUser object for greater flexibility?

@ChristophWurst

Copy link
Copy Markdown
Contributor

Since on master we're querying multiple providers, while this PR assumes there is only one, #24677 is required for this PR to work correctly.

@ChristophWurst

Copy link
Copy Markdown
Contributor

How about also showing the token type (browser/client)?

Comment thread core/register_command.php Outdated
$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Sessions(\OC::$server->query('OC\Authentication\Token\DefaultTokenProvider')));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd prefer to query the interface here, so we can easily swap the implementation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a get method to the server container, querying an interface is a good base idea, but not the final solution.
Basically query() should be used internally only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add a get method to the server container, querying an interface is a good base idea, but not the final solution.
Basically query() should be used internally only.

It is the interim solution until the auto injection also works in core ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well the problem is, with the class name being used it can not be replaced. It should use the interface and the interface should be a service using a factory, to allow "swapping" with a different provider.
Basically something like https://github.com/owncloud/core/blob/master/lib/private/Server.php#L160-L172 but with the public interface as service name for the auto-injection

@davitol

davitol commented May 18, 2016 •

Copy link
Copy Markdown
Contributor
sudo -u www-data ./occ user:sessions admin
+----+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------+
| id | name                                                                                                                            | last activity                    |
+----+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------+
| 1  | curl/7.35.0                                                                                                                     | 2016-05-18 13:21:41 UTC (+00:00) |
| 3  | Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36       | 2016-05-18 13:59:31 UTC (+00:00) |
| 4  | Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9            | 2016-05-18 13:59:42 UTC (+00:00) |
| 5  | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586 | 2016-05-18 14:00:04 UTC (+00:00) |
| 7  | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:46.0) Gecko/20100101 Firefox/46.0                                              | 2016-05-18 13:59:34 UTC (+00:00) |
| 8  | Mozilla/5.0 (iOS) ownCloud-iOS/3.4.9                                                                                            | 2016-05-18 14:00:07 UTC (+00:00) |
| 10 | Mozilla/5.0 (iOS) ownCloud-iOS/3.4.9                                                                                            | 2016-05-18 14:00:10 UTC (+00:00) |
+----+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------+

Why if I start a session from a iOS oC app, the command shows two active sessions of a user?

@ChristophWurst @MorrisJobke

@ChristophWurst

Copy link
Copy Markdown
Contributor

@davitol that might be a bug. We had to add a little hack that creates session tokens for DAV clients, which can cause multiple session tokens being created if the client does not use cookies.
@LukasReschke you said you'll add some magic to fix that, didn't you? :-)

@MorrisJobke
MorrisJobke force-pushed the command-to-list-user-sessions branch from 1c1e1f6 to 3dfc75d Compare May 18, 2016 14:43
Comment thread lib/private/Server.php Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nickvergessen This is the interface thingy you requested - cc @ChristophWurst

@MorrisJobke
MorrisJobke force-pushed the command-to-list-user-sessions branch from 3dfc75d to 904d50c Compare May 18, 2016 14:56
@MorrisJobke

Copy link
Copy Markdown
Contributor Author

I rebased this on top of #24686 - this now uses the proposed methods from @ChristophWurst PR :)

@nickvergessen @ChristophWurst Please re-review

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

This is the stuff, that is added here: 904d50c

@ChristophWurst

Copy link
Copy Markdown
Contributor

👍 very nice

Comment thread core/Command/User/Sessions.php Outdated
$user = $this->userManager->get($uid);
if(is_null($user)) {
$output->writeln('<error>User "' . $uid . '" does not exist</error>');
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Error means return != 0 ? 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@georgehrke

Copy link
Copy Markdown
Contributor

please rebase

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@ChristophWurst Feel free to take over

@PVince81

Copy link
Copy Markdown
Contributor

We're past feature freeze, moving to 9.2.

CC @cmonteroluque @MTRichards

@PVince81 PVince81 modified the milestones: 9.2-next, 9.1-current May 30, 2016
@ghost

ghost commented May 31, 2016

Copy link
Copy Markdown

nod

@mmattel

mmattel commented Aug 17, 2016

Copy link
Copy Markdown
Contributor

@ChristophWurst

We had to add a little hack that creates session tokens for DAV clients, which can cause multiple session tokens being created if the client does not use cookies.

Is this hack still necessary respectively can that be fixed that a DAV client produces only one session entry? Reason: querying table authtoken for statistical or access purposes via occ user command (see also referenced issue #25708)

@ChristophWurst

Copy link
Copy Markdown
Contributor

Is this hack still necessary respectively can that be fixed that a DAV client produces only one session entry?

AFAIK that is more or less impossible. Clients can be stateless, hence there's nothing that identifies/groups a set of related requests.

MorrisJobke and others added 3 commits September 22, 2016 08:53
* extends public interface IToken to expose name and lastActivity
* extends public interface Provider to expose tokens by user
* add command to list sessions per user
@DeepDiver1975
DeepDiver1975 force-pushed the command-to-list-user-sessions branch from 5a0f1a7 to 5d5d017 Compare September 22, 2016 07:18
@ChristophWurst ChristophWurst removed their assignment Dec 5, 2016
@PVince81

PVince81 commented Dec 8, 2016

Copy link
Copy Markdown
Contributor

@PhilippSchaffrath FYI

@PVince81

PVince81 commented Apr 6, 2017

Copy link
Copy Markdown
Contributor

@pmaier1 not sure if you have a concept in regards to session / token management completeness.

I think the purpose was for an admin to be able to list all user sessions (or search by a user) and then be able to terminate such sessions with another OCC command.

Moving to backlog until we can find time to finalize this

@PVince81 PVince81 modified the milestones: backlog, 10.0 Apr 6, 2017
@PVince81 PVince81 closed this Jul 19, 2017
@PVince81
PVince81 deleted the command-to-list-user-sessions branch July 19, 2017 10:24
@lock

lock Bot commented Aug 3, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants