Skip to content

Commit bde1e88

Browse files
committed
Create local VO groups after user authenticates with AAI
1 parent 525104f commit bde1e88

File tree

5 files changed

+170
-1
lines changed

5 files changed

+170
-1
lines changed

.php-cs-fixer.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"php":"8.1.8","version":"3.4.0:v3.4.0#47177af1cfb9dab5d1cc4daf91b7179c2efe7fad","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":{"position_after_anonymous_constructs":"same","position_after_control_structures":"same","position_after_functions_and_oop_constructs":"same"},"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["property","method","const"]},"align_multiline_comment":true,"array_indentation":true,"binary_operator_spaces":{"default":"single_space"},"blank_line_after_opening_tag":true,"no_unused_imports":true},"hashes":{"tests\/Unit\/Controller\/PageControllerTest.php":2207155758,"tests\/Integration\/AppTest.php":2950225233,"tests\/bootstrap.php":41908297,"appinfo\/routes.php":2458579438,"templates\/adminSettings.php":805129342,"templates\/personalSettings.php":1395204514,"templates\/index.php":2734865279,"node_modules\/flatted\/php\/flatted.php":3670498728,"lib\/Settings\/Admin.php":4177689181,"lib\/Settings\/AdminSection.php":3667266050,"lib\/Settings\/Personal.php":774712035,"lib\/Settings\/PersonalSection.php":237427933,"lib\/Vendor\/Firebase\/JWT\/BeforeValidException.php":3387887423,"lib\/Vendor\/Firebase\/JWT\/Key.php":2086644246,"lib\/Vendor\/Firebase\/JWT\/ExpiredException.php":1091148461,"lib\/Vendor\/Firebase\/JWT\/SignatureInvalidException.php":3046842981,"lib\/Vendor\/Firebase\/JWT\/JWT.php":23558362,"lib\/Vendor\/Firebase\/JWT\/JWK.php":909127881,"lib\/Controller\/LoginController.php":3892407794,"lib\/Controller\/PageController.php":4113731223,"lib\/Controller\/ConfigController.php":2824957717,"lib\/Service\/ProviderService.php":661513495,"lib\/AppInfo\/Application.php":4168035612}}
1+
{"php":"8.1.8","version":"3.4.0:v3.4.0#47177af1cfb9dab5d1cc4daf91b7179c2efe7fad","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":{"position_after_anonymous_constructs":"same","position_after_control_structures":"same","position_after_functions_and_oop_constructs":"same"},"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["property","method","const"]},"align_multiline_comment":true,"array_indentation":true,"binary_operator_spaces":{"default":"single_space"},"blank_line_after_opening_tag":true,"no_unused_imports":true},"hashes":{"tests\/Unit\/Controller\/PageControllerTest.php":2207155758,"tests\/Integration\/AppTest.php":2950225233,"tests\/bootstrap.php":41908297,"appinfo\/routes.php":2458579438,"templates\/adminSettings.php":805129342,"templates\/personalSettings.php":1395204514,"templates\/index.php":2734865279,"node_modules\/flatted\/php\/flatted.php":3670498728,"lib\/Settings\/Admin.php":4177689181,"lib\/Settings\/AdminSection.php":3667266050,"lib\/Settings\/Personal.php":774712035,"lib\/Settings\/PersonalSection.php":237427933,"lib\/Vendor\/Firebase\/JWT\/BeforeValidException.php":3387887423,"lib\/Vendor\/Firebase\/JWT\/Key.php":2086644246,"lib\/Vendor\/Firebase\/JWT\/ExpiredException.php":1091148461,"lib\/Vendor\/Firebase\/JWT\/SignatureInvalidException.php":3046842981,"lib\/Vendor\/Firebase\/JWT\/JWT.php":23558362,"lib\/Vendor\/Firebase\/JWT\/JWK.php":909127881,"lib\/Controller\/LoginController.php":2413542052,"lib\/Controller\/PageController.php":4113731223,"lib\/Controller\/ConfigController.php":2824957717,"lib\/Service\/ProviderService.php":661513495,"lib\/AppInfo\/Application.php":3846310732,"lib\/Backend\/GroupBackend.php":986210557,"lib\/Service\/VirtualOrganisationService.php":3422386287}}

lib/AppInfo/Application.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
namespace OCA\VO_Federation\AppInfo;
1212

13+
use OCA\VO_Federation\Backend\GroupBackend;
14+
1315
use OCP\AppFramework\App;
1416
use OCP\AppFramework\Bootstrap\IRegistrationContext;
1517
use OCP\AppFramework\Bootstrap\IBootContext;
1618
use OCP\AppFramework\Bootstrap\IBootstrap;
19+
use OCP\IGroupManager;
1720

1821
/**
1922
* Class Application
@@ -37,5 +40,11 @@ public function register(IRegistrationContext $context): void {
3740
}
3841

3942
public function boot(IBootContext $context): void {
43+
$context->injectFn(function (
44+
IGroupManager $groupManager,
45+
GroupBackend $groupBackend
46+
) {
47+
$groupManager->addBackend($groupBackend);
48+
});
4049
}
4150
}

lib/Backend/GroupBackend.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016, ownCloud, Inc.
4+
*
5+
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
6+
* @author Knut Ahlers <knut@ahlers.me>
7+
* @author Roeland Jago Douma <roeland@famdouma.nl>
8+
* @author Vincent Petry <vincent@nextcloud.com>
9+
*
10+
* @license AGPL-3.0
11+
*
12+
* This code is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License, version 3,
14+
* as published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License, version 3,
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>
23+
*
24+
*/
25+
namespace OCA\VO_Federation\Backend;
26+
27+
use OCP\Group\Backend\ABackend;
28+
use OCP\Group\Backend\IGetDisplayNameBackend;
29+
use OCP\Group\Backend\IGroupDetailsBackend;
30+
31+
use OCP\ILogger;
32+
33+
/**
34+
* Abstract base class for user management
35+
*/
36+
class GroupBackend extends ABackend implements
37+
IGetDisplayNameBackend,
38+
IGroupDetailsBackend {
39+
40+
/**
41+
* @var string The application name.
42+
*/
43+
private $appName;
44+
/**
45+
* @var ILogger The logger instance.
46+
*/
47+
private $logger;
48+
49+
public function __construct($AppName, ILogger $logger) {
50+
$this->appName = $AppName;
51+
$this->logger = $logger;
52+
}
53+
54+
/**
55+
* is user in group?
56+
* @param string $uid uid of the user
57+
* @param string $gid gid of the group
58+
* @return bool
59+
*
60+
* Checks whether the user is member of a group or not.
61+
*/
62+
public function inGroup($uid, $gid) {
63+
return in_array($gid, $this->getUserGroups($uid));
64+
}
65+
66+
/**
67+
* Get all groups a user belongs to
68+
* @param string $uid Name of the user
69+
* @return array an array of group names
70+
*
71+
* This function fetches all groups a user belongs to. It does not check
72+
* if the user exists at all.
73+
*/
74+
public function getUserGroups($uid) {
75+
return [];
76+
}
77+
78+
/**
79+
* get a list of all groups
80+
* @param string $search
81+
* @param int $limit
82+
* @param int $offset
83+
* @return array an array of group names
84+
*
85+
* Returns a list with all groups
86+
*/
87+
88+
public function getGroups($search = '', $limit = -1, $offset = 0) {
89+
return [];
90+
}
91+
92+
/**
93+
* check if a group exists
94+
* @param string $gid
95+
* @return bool
96+
*/
97+
public function groupExists($gid) {
98+
return in_array($gid, $this->getGroups($gid, 1));
99+
}
100+
101+
/**
102+
* get a list of all users in a group
103+
* @param string $gid
104+
* @param string $search
105+
* @param int $limit
106+
* @param int $offset
107+
* @return array an array of user ids
108+
*/
109+
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
110+
return [];
111+
}
112+
113+
public function getDisplayName(string $gid): string {
114+
return $gid;
115+
}
116+
117+
public function getGroupDetails(string $gid): array {
118+
return [];
119+
}
120+
}

lib/Controller/LoginController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
use OCA\VO_Federation\Vendor\Firebase\JWT\JWK;
3232
use OCA\VO_Federation\AppInfo\Application;
3333
use OCA\VO_Federation\Service\ProviderService;
34+
use OCA\VO_Federation\Service\VirtualOrganisationService;
35+
3436
use OCP\AppFramework\Controller;
3537
use OCP\AppFramework\Http;
3638
use OCP\AppFramework\Http\JSONResponse;
@@ -75,6 +77,9 @@ class LoginController extends Controller {
7577
/** @var ProviderService */
7678
private $providerService;
7779

80+
/** @var ProviderService */
81+
private $voService;
82+
7883
/** @var ILogger */
7984
private $logger;
8085

@@ -99,6 +104,7 @@ public function __construct(
99104
ITimeFactory $timeFactory,
100105
IConfig $config,
101106
ProviderService $providerService,
107+
VirtualOrganisationService $voService,
102108
ILogger $logger,
103109
?string $userId
104110
) {
@@ -112,6 +118,7 @@ public function __construct(
112118
$this->userManager = $userManager;
113119
$this->timeFactory = $timeFactory;
114120
$this->providerService = $providerService;
121+
$this->voService = $voService;
115122
$this->logger = $logger;
116123
$this->config = $config;
117124
$this->userId = $userId;
@@ -308,6 +315,10 @@ public function code($state = '', $code = '', $scope = '', $error = '', $error_d
308315
$this->config->setUserValue($this->userId, Application::APP_ID, 'displayName', $displayName);
309316
$this->config->setUserValue($this->userId, Application::APP_ID, 'groups', implode($groups, "\n"));
310317

318+
foreach ($groups as $gid) {
319+
$this->voService->addVOUser($gid, $this->userId, $clientId);
320+
}
321+
311322
return new RedirectResponse(
312323
$this->urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'connected-accounts']) .
313324
'?aaiToken=success#vo_federation-personal-settings'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\VO_Federation\Service;
6+
7+
use OCP\IConfig;
8+
use OCP\IGroupManager;
9+
use OCP\IUserManager;
10+
11+
class VirtualOrganisationService {
12+
/** @var IConfig */
13+
private $config;
14+
15+
private $groupManager;
16+
private $userManager;
17+
18+
public function __construct(IConfig $config, IGroupManager $groupManager, IUserManager $userManager) {
19+
$this->config = $config;
20+
$this->groupManager = $groupManager;
21+
$this->userManager = $userManager;
22+
}
23+
24+
public function addVOUser($gid, $userId, $clientId) {
25+
$gid = mb_substr($gid, 0, 64);
26+
$group = $this->groupManager->createGroup($gid);
27+
$group->addUser($this->userManager->get($userId));
28+
}
29+
}

0 commit comments

Comments
 (0)