예제 #1
0
 public static function post_login($parameters)
 {
     $uid = $parameters['uid'];
     $casBackend = OC_USER_CAS::getInstance();
     $userDatabase = new \OC\User\Database();
     if (phpCAS::isAuthenticated()) {
         // $cas_attributes may vary in name, therefore attributes are fetched to $attributes
         $cas_attributes = phpCAS::getAttributes();
         $cas_uid = phpCAS::getUser();
         // parameters
         $attributes = array();
         if ($cas_uid == $uid) {
             \OCP\Util::writeLog('cas', 'attr  \\"' . implode(',', $cas_attributes) . '\\" for the user: '******'cas_name'] = $cas_attributes[$casBackend->displayNameMapping];
             } else {
                 $attributes['cas_name'] = $cas_attributes['cn'];
             }
             if (array_key_exists($casBackend->mailMapping, $cas_attributes)) {
                 $attributes['cas_email'] = $cas_attributes[$casBackend->mailMapping];
             } else {
                 $attributes['cas_email'] = $cas_attributes['mail'];
             }
             if (array_key_exists($casBackend->groupMapping, $cas_attributes)) {
                 $attributes['cas_groups'] = $cas_attributes[$casBackend->groupMapping];
             } else {
                 if (!empty($casBackend->defaultGroup)) {
                     $attributes['cas_groups'] = array($casBackend->defaultGroup);
                     \OCP\Util::writeLog('cas', 'Using default group "' . $casBackend->defaultGroup . '" for the user: '******'/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
                     \OCP\Util::writeLog('cas', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', \OCP\Util::DEBUG);
                     return false;
                 } else {
                     $random_password = \OCP\Util::generateRandomBytes(20);
                     \OCP\Util::writeLog('cas', 'Creating new user: ' . $uid, \OCP\Util::DEBUG);
                     $userDatabase->createUser($uid, $random_password);
                     // after creating the user, fill the attributes
                     if ($userDatabase->userExists($uid)) {
                         OC_USER_CAS_Hooks::update_user($uid, $attributes);
                     }
                 }
             }
             // try to update user attributes
             if ($casBackend->updateUserData) {
                 OC_USER_CAS_Hooks::update_user($cas_uid, $attributes);
             }
             return true;
         }
     }
     return false;
 }
예제 #2
0
 public function testCountWithSearchString()
 {
     $access = $this->getAccessMock();
     $this->enableGroups($access);
     $access->expects($this->any())->method('groupname2dn')->will($this->returnValue('cn=group,dc=foo,dc=bar'));
     $access->expects($this->any())->method('fetchListOfUsers')->will($this->returnValue(array()));
     $access->expects($this->any())->method('readAttribute')->will($this->returnCallback(function ($name) {
         //the search operation will call readAttribute, thus we need
         //to anaylze the "dn". All other times we just need to return
         //something that is neither null or false, but once an array
         //with the users in the group – so we do so all other times for
         //simplicicity.
         if (strpos($name, 'u') === 0) {
             return strpos($name, '3');
         }
         return array('u11', 'u22', 'u33', 'u34');
     }));
     $access->expects($this->any())->method('dn2username')->will($this->returnCallback(function () {
         return 'foobar' . \OCP\Util::generateRandomBytes(7);
     }));
     $groupBackend = new GroupLDAP($access);
     $users = $groupBackend->countUsersInGroup('group', '3');
     $this->assertSame(2, $users);
 }
예제 #3
0
 /**
  * Encrypt a single password
  *
  * @param string $password plain text password
  * @return string encrypted password
  */
 private static function encryptPassword($password)
 {
     $cipher = self::getCipher();
     $iv = \OCP\Util::generateRandomBytes(16);
     $cipher->setIV($iv);
     return base64_encode($iv . $cipher->encrypt($password));
 }
예제 #4
0
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled('activity');
\OCP\JSON::callCheck();
$l = \OCP\Util::getL10N('activity');
$token = $tokenUrl = '';
if ($_POST['enable'] === 'true') {
    // Check for collisions
    $token = \OCP\Util::generateRandomBytes();
    $preferences = new \OC\Preferences(\OC_DB::getConnection());
    $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token);
    while (!empty($conflicts)) {
        $token = \OCP\Util::generateRandomBytes();
        $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token);
    }
    $tokenUrl = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('activity.rss', array('token' => $token)));
}
\OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'rsstoken', $token);
\OCP\JSON::success(array('data' => array('message' => $l->t('Your settings have been updated.'), 'rsslink' => $tokenUrl)));
예제 #5
0
 /**
  * @param \Doctrine\DBAL\Schema\Table $table
  * @param string $newName
  * @return \Doctrine\DBAL\Schema\Table
  */
 protected function renameTableSchema(Table $table, $newName)
 {
     /**
      * @var \Doctrine\DBAL\Schema\Index[] $indexes
      */
     $indexes = $table->getIndexes();
     $newIndexes = array();
     foreach ($indexes as $index) {
         if ($index->isPrimary()) {
             // do not rename primary key
             $indexName = $index->getName();
         } else {
             // avoid conflicts in index names
             $indexName = 'oc_' . \OCP\Util::generateRandomBytes(13);
         }
         $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
     }
     // foreign keys are not supported so we just set it to an empty array
     return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions());
 }