Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/apps.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge López Pérez <jorge@adobo.org>2014-07-30 15:22:07 +0400
committerJorge López Pérez <jorge@adobo.org>2014-07-30 15:22:07 +0400
commitfd5e96f3b59f340df916d03ff19787c4e25a6db7 (patch)
tree1a4987aff7d8758ce1c8a0d6d198d0dfc23bf286 /user_saml
parent32877d3b5909261bc82b72ebd11490ed0c3cf154 (diff)
Get quota from SAML attributes
Sets user quotas from SAML attributes. Adds two new settings: * Quota mapping: an attribute that will be read to set the current quota * Default quota: used to set a quota value when the quota attribute is missing. An empty default quota can be set to keep quotas untouched
Diffstat (limited to 'user_saml')
-rw-r--r--user_saml/lib/hooks.php28
-rw-r--r--user_saml/settings.php4
-rw-r--r--user_saml/templates/settings.php2
-rw-r--r--user_saml/user_saml.php4
4 files changed, 37 insertions, 1 deletions
diff --git a/user_saml/lib/hooks.php b/user_saml/lib/hooks.php
index 20e0461e9..3839e9ca2 100644
--- a/user_saml/lib/hooks.php
+++ b/user_saml/lib/hooks.php
@@ -62,6 +62,22 @@ class OC_USER_SAML_Hooks {
}
}
+ $saml_quota = '';
+ if (!empty($samlBackend->quotaMapping)) {
+ foreach ($samlBackend->quotaMapping as $quotaMapping) {
+ if (array_key_exists($quotaMapping, $attributes) && !empty($attributes[$quotaMapping][0])) {
+ $saml_quota = $attributes[$quotaMapping][0];
+ break;
+ }
+ }
+ OC_Log::write('saml','Current quota: "'.$saml_quota.'" for user: '.$uid, OC_Log::DEBUG);
+ }
+
+ if (empty($saml_quota) && !empty($samlBackend->defaultQuota)) {
+ $saml_quota = $samlBackend->defaultQuota;
+ OC_Log::write('saml','Using default quota ('.$saml_quota.') for user: '.$uid, OC_Log::DEBUG);
+ }
+
$saml_groups = array();
foreach ($samlBackend->groupMapping as $groupMapping) {
if (array_key_exists($groupMapping, $attributes) && !empty($attributes[$groupMapping])) {
@@ -93,6 +109,9 @@ class OC_USER_SAML_Hooks {
if (isset($saml_display_name)) {
update_display_name($uid, $saml_display_name);
}
+ if (isset($saml_quota)) {
+ update_quota($uid, $saml_quota);
+ }
}
}
}
@@ -109,6 +128,9 @@ class OC_USER_SAML_Hooks {
if (isset($saml_display_name)) {
update_display_name($uid, $saml_display_name);
}
+ if (isset($saml_quota)) {
+ update_quota($uid, $saml_quota);
+ }
}
}
return true;
@@ -170,3 +192,9 @@ function update_groups($uid, $groups, $protectedGroups=array(), $just_created=fa
function update_display_name($uid, $displayName) {
OC_User::setDisplayName($uid, $displayName);
}
+
+function update_quota($uid, $quota) {
+ if (!empty($quota)) {
+ \OCP\Config::setUserValue($uid, 'files', 'quota', \OCP\Util::computerFileSize($quota));
+ }
+}
diff --git a/user_saml/settings.php b/user_saml/settings.php
index d0b393f75..827d23ab4 100644
--- a/user_saml/settings.php
+++ b/user_saml/settings.php
@@ -23,7 +23,7 @@
OC_Util::checkAdminUser();
-$params = array('saml_ssp_path', 'saml_sp_source', 'saml_force_saml_login', 'saml_autocreate', 'saml_update_user_data', 'saml_protected_groups', 'saml_default_group', 'saml_username_mapping', 'saml_email_mapping', 'saml_displayname_mapping', 'saml_group_mapping');
+$params = array('saml_ssp_path', 'saml_sp_source', 'saml_force_saml_login', 'saml_autocreate', 'saml_update_user_data', 'saml_protected_groups', 'saml_default_group', 'saml_username_mapping', 'saml_email_mapping', 'saml_quota_mapping', 'saml_default_quota', 'saml_displayname_mapping', 'saml_group_mapping');
OCP\Util::addscript('user_saml', 'settings');
@@ -63,6 +63,8 @@ $tmpl->assign( 'saml_default_group', OCP\Config::getAppValue('user_saml', 'saml_
$tmpl->assign( 'saml_username_mapping', OCP\Config::getAppValue('user_saml', 'saml_username_mapping', 'uid'));
$tmpl->assign( 'saml_email_mapping', OCP\Config::getAppValue('user_saml', 'saml_email_mapping', 'mail'));
$tmpl->assign( 'saml_displayname_mapping', OCP\Config::getAppValue('user_saml', 'saml_displayname_mapping', 'displayName'));
+$tmpl->assign( 'saml_quota_mapping', OCP\Config::getAppValue('user_saml', 'saml_quota_mapping', ''));
+$tmpl->assign( 'saml_default_quota', OCP\Config::getAppValue('user_saml', 'saml_default_quota', ''));
$tmpl->assign( 'saml_group_mapping', OCP\Config::getAppValue('user_saml', 'saml_group_mapping', ''));
return $tmpl->fetchPage();
diff --git a/user_saml/templates/settings.php b/user_saml/templates/settings.php
index 5aad114e5..eb09e468b 100644
--- a/user_saml/templates/settings.php
+++ b/user_saml/templates/settings.php
@@ -21,6 +21,8 @@
<p><label for="saml_username_mapping"><?php p($l->t('Username'));?></label><input type="text" id="saml_username_mapping" name="saml_username_mapping" value="<?php p($_['saml_username_mapping']); ?>" /></p>
<p><label for="saml_email_mapping"><?php p($l->t('Email'));?></label><input type="text" id="saml_email_mapping" name="saml_email_mapping" value="<?php p($_['saml_email_mapping']); ?>" /></p>
<p><label for="saml_displayname_mapping"><?php p($l->t('DisplayName'));?></label><input type="text" id="saml_displayname_mapping" name="saml_displayname_mapping" value="<?php p($_['saml_displayname_mapping']); ?>" /></p>
+ <p><label for="saml_quota_mapping"><?php p($l->t('Quota'));?></label><input type="text" id="saml_quota_mapping" name="saml_quota_mapping" value="<?php p($_['saml_quota_mapping']); ?>" /></p>
+ <p><label for="saml_default_quota"><?php p($l->t('Quota Default'));?></label><input type="text" id="saml_default_quota" name="saml_default_quota" value="<?php p($_['saml_default_quota']); ?>" title="<?php echo $l->t('in bytes');?>" /></p>
<p><label for="saml_group_mapping"><?php p($l->t('Group'));?></label><input type="text" id="saml_group_mapping" name="saml_group_mapping" value="<?php p($_['saml_group_mapping']); ?>" /></p>
</fieldset>
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
diff --git a/user_saml/user_saml.php b/user_saml/user_saml.php
index af5b5d68d..eb6335688 100644
--- a/user_saml/user_saml.php
+++ b/user_saml/user_saml.php
@@ -34,6 +34,8 @@ class OC_USER_SAML extends OC_User_Backend {
public $usernameMapping;
public $mailMapping;
public $displayNameMapping;
+ public $quotaMapping;
+ public $defaultQuota;
public $groupMapping;
public $auth;
@@ -49,6 +51,8 @@ class OC_USER_SAML extends OC_User_Backend {
$this->usernameMapping = explode (',', preg_replace('/\s+/', '', OCP\Config::getAppValue('user_saml', 'saml_username_mapping', '')));
$this->mailMapping = explode (',', preg_replace('/\s+/', '', OCP\Config::getAppValue('user_saml', 'saml_email_mapping', '')));
$this->displayNameMapping = explode (',', preg_replace('/\s+/', '', OCP\Config::getAppValue('user_saml', 'saml_displayname_mapping', '')));
+ $this->quotaMapping = explode (',', preg_replace('/\s+/', '', OCP\Config::getAppValue('user_saml', 'saml_quota_mapping', '')));
+ $this->defaultQuota = OCP\Config::getAppValue('user_saml', 'saml_default_quota', '');
$this->groupMapping = explode (',', preg_replace('/\s+/', '', OCP\Config::getAppValue('user_saml', 'saml_group_mapping', '')));
if (!empty($this->sspPath) && !empty($this->spSource)) {