forked from COmanage/match
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
API authz and other fixes
Benn Oshrin
committed
Oct 3, 2018
1 parent
ecee7a1
commit c61e66b
Showing
22 changed files
with
833 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* COmanage Match API Users Controller | ||
* | ||
* Portions licensed to the University Corporation for Advanced Internet | ||
* Development, Inc. ("UCAID") under one or more contributor license agreements. | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. | ||
* | ||
* UCAID licenses this file to you 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: | ||
* | ||
* http://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. | ||
* | ||
* @link http://www.internet2.edu/comanage COmanage Project | ||
* @package match | ||
* @since COmanage Match v1.0.0 | ||
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace App\Controller; | ||
|
||
class ApiUsersController extends StandardController { | ||
/** | ||
* Authorization for this Controller, called by Auth component | ||
* - postcondition: $vv_permissions set with calculated permissions for this Controller | ||
* | ||
* @since COmanage Match v1.0.0 | ||
* @param Array $user Array of user data | ||
* @return Boolean True if authorized for the current action, false otherwise | ||
*/ | ||
|
||
public function isAuthorized(Array $user) { | ||
$mgid = isset($this->cur_mg->id) ? $this->cur_mg->id : null; | ||
|
||
$platformAdmin = $this->Authorization->isPlatformAdmin($user['username']); | ||
|
||
$mgAdmin = $this->Authorization->isMatchAdmin($user['username'], $mgid); | ||
|
||
if(!$platformAdmin && !$mgid) { | ||
// Normally this is done in AppController::setMatchgrid, but since we | ||
// allow empty Matchgrid ID we have to manually check here. | ||
throw new \RuntimeException(__('match.er.mgid')); | ||
} | ||
|
||
$p = [ | ||
'add' => $platformAdmin || $mgAdmin, | ||
'delete' => $platformAdmin || $mgAdmin, | ||
'edit' => $platformAdmin || $mgAdmin, | ||
'index' => $platformAdmin || $mgAdmin, | ||
'view' => false | ||
]; | ||
|
||
$this->set('vv_permissions', $p); | ||
return $p[$this->request->getParam('action')]; | ||
} | ||
} |
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
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
Oops, something went wrong.