コード例 #1
0
ファイル: hooks.php プロジェクト: fproject/apps
function update_user_data($uid, $attributes = array(), $just_created = false)
{
    OC_Util::setupFS($uid);
    OCP\Util::writeLog('saml', 'Updating data of the user: '******'email'])) {
        update_mail($uid, $attributes['email']);
    }
    if (isset($attributes['groups'])) {
        update_groups($uid, $attributes['groups'], $attributes['protected_groups'], $just_created);
    }
    if (isset($attributes['display_name'])) {
        update_display_name($uid, $attributes['display_name']);
    }
    if (isset($attributes['quota'])) {
        update_quota($uid, $attributes['quota']);
    }
}
コード例 #2
0
ファイル: hooks.php プロジェクト: anolisti/apps
 public static function post_login($parameters)
 {
     $userid = $parameters['uid'];
     $samlBackend = new OC_USER_SAML();
     if ($samlBackend->auth->isAuthenticated()) {
         $attributes = $samlBackend->auth->getAttributes();
         $usernameFound = false;
         foreach ($samlBackend->usernameMapping as $usernameMapping) {
             if (array_key_exists($usernameMapping, $attributes) && !empty($attributes[$usernameMapping][0])) {
                 $usernameFound = true;
                 $uid = $attributes[$usernameMapping][0];
                 OC_Log::write('saml', 'Authenticated user ' . $uid, OC_Log::DEBUG);
                 break;
             }
         }
         if ($usernameFound && $uid == $userid) {
             $attributes = $samlBackend->auth->getAttributes();
             $saml_email = '';
             foreach ($samlBackend->mailMapping as $mailMapping) {
                 if (array_key_exists($mailMapping, $attributes) && !empty($attributes[$mailMapping][0])) {
                     $saml_email = $attributes[$mailMapping][0];
                     break;
                 }
             }
             $saml_display_name = '';
             foreach ($samlBackend->displayNameMapping as $displayNameMapping) {
                 if (array_key_exists($displayNameMapping, $attributes) && !empty($attributes[$displayNameMapping][0])) {
                     $saml_display_name = $attributes[$displayNameMapping][0];
                     break;
                 }
             }
             $saml_groups = array();
             foreach ($samlBackend->groupMapping as $groupMapping) {
                 if (array_key_exists($groupMapping, $attributes) && !empty($attributes[$groupMapping])) {
                     $saml_groups = array_merge($saml_groups, $attributes[$groupMapping]);
                 }
             }
             if (empty($saml_groups) && !empty($samlBackend->defaultGroup)) {
                 $saml_groups = array($samlBackend->defaultGroup);
                 OC_Log::write('saml', 'Using default group "' . $samlBackend->defaultGroup . '" for the user: '******'/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
                     OC_Log::write('saml', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', OC_Log::DEBUG);
                     return false;
                 } else {
                     $random_password = OC_Util::generate_random_bytes(20);
                     OC_Log::write('saml', 'Creating new user: '******'saml', 'Updating data of the user: ' . $uid, OC_Log::DEBUG);
                     if (isset($saml_email)) {
                         update_mail($uid, $saml_email);
                     }
                     if (isset($saml_groups)) {
                         update_groups($uid, $saml_groups, $samlBackend->protectedGroups, false);
                     }
                     if (isset($saml_display_name)) {
                         update_display_name($uid, $saml_display_name);
                     }
                 }
             }
             return true;
         }
     }
     return false;
 }