Skip to content
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

Adds command to list user sessions #24675

Closed
wants to merge 3 commits into from

Conversation

MorrisJobke
Copy link
Contributor

@MorrisJobke MorrisJobke commented May 17, 2016

cc @LukasReschke @PVince81 @DeepDiver1975 @ChristophWurst @nickvergessen

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

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
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
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
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
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
Contributor

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

@@ -127,6 +127,7 @@
$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
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
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
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
Contributor

Choose a reason for hiding this comment

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

Copy link
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
Copy link
Contributor

davitol commented May 18, 2016

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
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
@@ -223,6 +223,7 @@ public function __construct($webRoot, \OC\Config $config) {
$timeFactory = new TimeFactory();
return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
});
$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
Copy link
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
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
Contributor Author

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

@ChristophWurst
Copy link
Contributor

👍 very nice

$user = $this->userManager->get($uid);
if(is_null($user)) {
$output->writeln('<error>User "' . $uid . '" does not exist</error>');
return;
Copy link
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
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
Contributor

please rebase

@MorrisJobke
Copy link
Contributor Author

@ChristophWurst Feel free to take over

@PVince81
Copy link
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
Copy link

ghost commented May 31, 2016

nod

@mmattel
Copy link
Contributor

mmattel commented Aug 17, 2016

@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
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
@ChristophWurst ChristophWurst removed their assignment Dec 5, 2016
@PVince81
Copy link
Contributor

PVince81 commented Dec 8, 2016

@PhilippSchaffrath FYI

@PVince81
Copy link
Contributor

PVince81 commented Apr 6, 2017

@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
Copy link

lock bot commented Aug 3, 2019

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