ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
registry.edit.php
Go to the documentation of this file.
1 <?php
2 
3 // Load SimpleSAMLphp, configuration and metadata
7 
9 
10 $authsource = "admin"; // force admin to authenticate as registry maintainer
11 $useridattr = $oauthconfig->getValue('useridattr', 'user');
12 
13 if ($session->isValid($authsource)) {
14  $attributes = $session->getAuthData($authsource, 'Attributes');
15  // Check if userid exists
16  if (!isset($attributes[$useridattr]))
17  throw new Exception('User ID is missing');
19 } else {
21  $as->initLogin(\SimpleSAML\Utils\HTTP::getSelfURL());
22 }
23 
24 function requireOwnership($entry, $userid) {
25  if (!isset($entry['owner']))
26  throw new Exception('OAuth Consumer has no owner. Which means no one is granted access, not even you.');
27  if ($entry['owner'] !== $userid)
28  throw new Exception('OAuth Consumer has an owner that is not equal to your userid, hence you are not granted access.');
29 }
30 
31 if (array_key_exists('editkey', $_REQUEST)) {
32  $entryc = $store->get('consumers', $_REQUEST['editkey'], '');
33  $entry = $entryc['value'];
34  requireOwnership($entry, $userid);
35 
36 } else {
37  $entry = array(
38  'owner' => $userid,
39  'key' => SimpleSAML\Utils\Random::generateID(),
40  'secret' => SimpleSAML\Utils\Random::generateID(),
41  );
42 }
43 
44 
46 
47 
48 if (isset($_POST['submit'])) {
49  $editor->checkForm($_POST);
50 
51  $entry = $editor->formToMeta($_POST, array(), array('owner' => $userid));
52 
53  requireOwnership($entry, $userid);
54 
55  $store->set('consumers', $entry['key'], '', $entry);
56 
57  $template = new SimpleSAML_XHTML_Template($config, 'oauth:registry.saved.php');
58  $template->data['entry'] = $entry;
59  $template->show();
60  exit;
61 }
62 
63 $form = $editor->metaToForm($entry);
64 
65 $template = new SimpleSAML_XHTML_Template($config, 'oauth:registry.edit.tpl.php');
66 $template->data['form'] = $form;
67 $template->show();
68 
$session
if(empty($userids)) $userid
$config
$useridattr
$template
Attribute-related utility methods.
if(isset($_POST['submit'])) $form
$oauthconfig
$as
$editor
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$authsource
exit
Definition: backend.php:16
requireOwnership($entry, $userid)
$store
static getOptionalConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
static getById($authId, $type=null)
Retrieve authentication source.
Definition: Source.php:340
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:241
$_POST["username"]
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.