ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
13if ($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
24function 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
31if (array_key_exists('editkey', $_REQUEST)) {
32 $entryc = $store->get('consumers', $_REQUEST['editkey'], '');
33 $entry = $entryc['value'];
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
48if (isset($_POST['submit'])) {
49 $editor->checkForm($_POST);
50
51 $entry = $editor->formToMeta($_POST, array(), array('owner' => $userid));
52
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
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static getById($authId, $type=null)
Retrieve authentication source.
Definition: Source.php:324
static getOptionalConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243
$as
if(empty($userids)) $userid
Attribute-related utility methods.
$useridattr
$oauthconfig
$config
$store
$template
$authsource
$session
$editor
requireOwnership($entry, $userid)
if(isset($_POST['submit'])) $form
$attributes