set all user properties from a database record
495267
protected function setUserFromDb()
	{
		$this->intId = $this->id;

		foreach ($this->arrData as $key => $value) {
			if (! is_numeric($value)) {
				$this->$key = \StringUtil::deserialize($value);
			}
		}

		$always = array('alexf');
		$depends = array();

		if (is_array($GLOBALS['TL_PERMISSIONS']) && ! empty($GLOBALS['TL_PERMISSIONS'])) {
			$depends = array_merge($depends, $GLOBALS['TL_PERMISSIONS']);
		}

		if ($this->inherit == 'group') {
			foreach ($depends as $field) {
				$this->$field = array();
			}
		}

		$inherit = in_array($this->inherit, array('group', 'extend')) ? array_merge($always, $depends) : $always;
		$time = time();

		foreach ((array) $this->groups as $id) {

			$objGroup = $this->Database
				->prepare("SELECT * FROM tl_user_group WHERE id=? AND disable!=1 AND (start='' OR start<$time) AND (stop='' OR stop>$time)")
				->limit(1)
				->execute($id);

			if ($objGroup->numRows > 0) {
				foreach ($inherit as $field) {
					$value = \StringUtil::deserialize($objGroup->$field, true);
					if (!empty($value)) {
						$this->$field = array_merge((is_array($this->$field) ? $this->$field : (($this->$field != '') ? array($this->$field) : array())), $value);
						$this->$field = array_unique($this->$field);
					}
				}
			}

		}
	}
765984
public static void serializeUserProperties( BackendlessUser user )
  {
    Map<String, Object> serializedProperties = user.getProperties();

    Set<Map.Entry<String, Object>> properties = serializedProperties.entrySet();
    for( Map.Entry<String, Object> property : properties )
    {
      Object propertyValue = property.getValue();
      if( propertyValue != null && !propertyValue.getClass().isArray() && !propertyValue.getClass().isEnum() && !isBelongsJdk( propertyValue.getClass() ) )
      {
        property.setValue( serializeToMap( propertyValue ) );
      }
    }

    user.setProperties( serializedProperties );
  }
317502
def process_user_record(cls, info):
        """"""
        keys = list(info.keys())
        # Value conversion
        for k in keys:
            v = info[k]
            if v in ('N/A', 'no_information'):
                info[k] = None
            elif v == 'false':
                info[k] = False
            elif v == 'true':
                info[k] = True
        # Object conversion
        for p, t in cls.list_sub_objects:
            obj = dict([(k[len(p):], info.pop(k))
                        for k in keys if k.startswith(p)])
            if obj.get('active', False):
                info.setdefault(t, []).append(obj)
        return info
801223
void setUserInfo() {
        String smcDBID = _smc.getSessionDBID();
        if (smcDBID != null && smcDBID.indexOf("::") != -1) {
            try {
                dbid = smcDBID.substring(0, smcDBID.indexOf("::"));
                collectionName = smcDBID.substring(smcDBID.indexOf("::") + 2);
                if (collectionName.indexOf("$V") > 0) {
                    collectionName = collectionName.substring(0, collectionName.indexOf("$V") - 1);
                    String dbConnectVersionName = smcDBID.substring(smcDBID.indexOf("$V") + 2);
                    dbConnectVersion = (int) (new Double(dbConnectVersionName)).doubleValue();
                }
            } catch (Exception e) {
                com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ws.session.store.db.DatabaseHashMap.setUserInfo", "241", this);
                LoggingUtil.SESSION_LOGGER_WAS.logp(Level.SEVERE, methodClassName, methodNames[SET_USER_INFO], "CommonMessage.exception", e);
            }
        } else
            dbid = smcDBID;

        dbpwd = _smc.getSessionDBPWD();
    }
288029
private String fixDatabaseName(String databaseName, Record record, Map<String,String> oldProperties)
    {
        if (databaseName.endsWith(BaseDatabase.SHARED_SUFFIX))
            databaseName = databaseName.substring(0, databaseName.length() - BaseDatabase.SHARED_SUFFIX.length());
        else if (databaseName.endsWith(BaseDatabase.USER_SUFFIX))
            databaseName = databaseName.substring(0, databaseName.length() - BaseDatabase.USER_SUFFIX.length());
        String recordDBName = record.getDatabaseName();
        if (record instanceof DatabaseInfo)
            recordDBName = DatabaseInfo.DATABASE_INFO_FILE;
        if (!databaseName.startsWith(recordDBName))
        { // Typically user name
            this.getTask().setProperty(DBConstants.DB_USER_PREFIX, databaseName.substring(0, databaseName.indexOf('_')));
            databaseName = databaseName.substring(databaseName.indexOf('_') + 1);
        }
        if (!databaseName.endsWith(recordDBName))
        {
            String suffix = databaseName.substring(databaseName.lastIndexOf('_') + 1);
            if (suffix.length() == 2)
            { // Typically language
                this.getTask().setProperty(DBParams.LANGUAGE, suffix);
                databaseName = databaseName.substring(0, databaseName.lastIndexOf('_'));
                suffix = databaseName.substring(databaseName.lastIndexOf('_') + 1);             
            }
            if (!databaseName.endsWith(recordDBName))
            {
                databaseName = databaseName.substring(0, databaseName.lastIndexOf('_'));
                if ((record.getDatabaseType() & DBConstants.USER_DATA) != 0)
                    this.getTask().setProperty(record.getDatabaseName() + BaseDatabase.DBUSER_PARAM_SUFFIX, suffix);
                else
                    this.getTask().setProperty(record.getDatabaseName() + BaseDatabase.DBSHARED_PARAM_SUFFIX, suffix);
                suffix = databaseName.substring(databaseName.lastIndexOf('_') + 1); //?         
            }
            if (!databaseName.endsWith(recordDBName))
            {
                this.getTask().setProperty(DBConstants.SYSTEM_NAME, suffix);
                databaseName = databaseName.substring(0, databaseName.lastIndexOf('_'));
            }
        }
        return databaseName;
    }
835144
public Map<String, Object> addDatabaseProperties(Map<String,Object> properties, DatabaseOwner databaseOwner)
    {
        Map<String,Object> oldProperties = databaseOwner.getProperties();
        if (properties != null)
        {   // Also move any application params up.
            for (String key : properties.keySet())
            {   // Move these params to the application
                if ((key.endsWith(BaseDatabase.DBSHARED_PARAM_SUFFIX))
            		|| (key.endsWith(BaseDatabase.DBUSER_PARAM_SUFFIX))
                    || (DBConstants.DB_USER_PREFIX.equals(key))
                        || (DBConstants.SYSTEM_NAME.equals(key)))
                {
                    if (oldProperties == databaseOwner.getProperties())
                    {   // Return the old properties
                        oldProperties = new HashMap<String,Object>();
                        oldProperties.putAll(databaseOwner.getProperties());
                    }
                    databaseOwner.setProperty(key, (String)properties.get(key));
                }
            }
        }
        return oldProperties;
    }
468466
def setTableProperty(self, login, tableName, property, value):
    
    self.send_setTableProperty(login, tableName, property, value)
    self.recv_setTableProperty()
1042162
public void addDatabaseProperties(Map<String,Object> properties)
    {
        Map<String,Object> propRequest = this.getRequestProperties(this.getServletRequest(), false);
        if (propRequest != null)
        {   // Also move any application params up.
            for (String key : propRequest.keySet())
            {   // Move these params to the application
                if ((key.endsWith(BaseDatabase.DBSHARED_PARAM_SUFFIX))
            		|| (key.endsWith(BaseDatabase.DBUSER_PARAM_SUFFIX))
                    || (key.equals(DBConstants.MODE))
                    || (key.equals(DBConstants.SYSTEM_NAME)))
                		properties.put(key, propRequest.get(key));
            }
        }        
    }
737728
def setPermissions(self, dbName, access) :
        """"""
        import json

        if not self.URL :
            raise CreationError("Please save user first", None, None)

        rights = []
        if access :
            rights.append("rw")

        rights = ''.join(rights)

        if not self.connection.hasDatabase(dbName) :
            raise KeyError("Unknown database: %s" % dbName)

        url = "%s/database/%s" % (self.URL, dbName)
        r = self.connection.session.put(url, data = json.dumps({"grant": rights}, default=str))
        if r.status_code < 200 or r.status_code > 202 :
            raise CreationError("Unable to grant rights", r.content)
709536
def initialize_db_args(self, settings, db_key):
        
        self.print_message("Initializing database settings for %s" % db_key, verbosity_needed=2)

        db_member = self.databases[db_key]

        db_name = settings.get('NAME')
        if db_name and not db_member['name']:
            db_member['name'] = db_name

        db_member['password'] = settings.get('PASSWORD')

        args = []
        for key in ['USER', 'HOST', 'PORT']:
            value = settings.get(key)
            if value:
                self.print_message("Adding parameter %s" % key.lower, verbosity_needed=2)
                args.append('--%s=%s' % (key.lower(), value))

        db_member['args'] = args
52213
private void loadUser(String username)
    {
        try
        {
            if (null==_con)
                connectDatabase();
            
            if (null==_con)
                throw new SQLException("Can't connect to database");
            
            PreparedStatement stat = _con.prepareStatement(_userSql);
            stat.setObject(1, username);
            ResultSet rs = stat.executeQuery();
    
            if (rs.next())
            {
                Object key = rs.getObject(_userTableKey);
                put(username, rs.getString(_userTablePasswordField));
                stat.close();
                
                stat = _con.prepareStatement(_roleSql);
                stat.setObject(1, key);
                rs = stat.executeQuery();

                while (rs.next())
                    addUserToRole(username, rs.getString(_roleTableRoleField));
                
                stat.close();
            }
        }
        catch (SQLException e)
        {
            log.warn("UserRealm " + getName()
                      + " could not load user information from database", e);
            connectDatabase();
        }
    }
647264
@Override
    public void initialize() {
        String adminUsername = "admin";
        String adminPassword = "123456";

        User param = new User();
        param.setUserName(adminUsername);
        User admin = baseDao.getUnique(User.class, param);
        if (admin != null) {
            LoggerHelper.info("database has been initialized.");
            return;
        }
        LoggerHelper.info("begin init database.");
        admin = new User();
        admin.setUserName(adminUsername);
        admin.setUserPassword(HashHelper.getHashedPassword(adminPassword, adminUsername));
        admin.setPasswordSalt(adminUsername);

        Role role = new Role();
        role.setRoleName("ROLE_ADMIN");
        role.setRoleDescription("Administrator");
        baseDao.save(role);

        admin.setRoleList(Arrays.asList(role));
        baseDao.save(admin);

        LoggerHelper.info("init database successfully.");
    }
695153
def set_uservar(self, user, name, value):
        
        self._session.set(user, {name: value})
91825
def _populate_input_for_name_id(self, config, record, context, data):
        
        user_id = ""
        user_id_from_attrs = config['user_id_from_attrs']
        for attr in user_id_from_attrs:
            if attr in record["attributes"]:
                value = record["attributes"][attr]
                if isinstance(value, list):
                    # Use a default sort to ensure some predictability since the
                    # LDAP directory server may return multi-valued attributes
                    # in any order.
                    value.sort()
                    user_id += "".join(value)
                    satosa_logging(
                        logger,
                        logging.DEBUG,
                        "Added attribute {} with values {} to input for NameID".format(attr, value),
                        context.state
                        )
                else:
                    user_id += value
                    satosa_logging(
                        logger,
                        logging.DEBUG,
                        "Added attribute {} with value {} to input for NameID".format(attr, value),
                        context.state
                        )
        if not user_id:
            satosa_logging(
                logger,
                logging.WARNING,
                "Input for NameID is empty so not overriding default",
                context.state
                )
        else:
            data.subject_id = user_id
            satosa_logging(
                logger,
                logging.DEBUG,
                "Input for NameID is {}".format(data.subject_id),
                context.state
                )
69748
void getProperties(Connection connection, long id, LoggingEvent event)
      throws SQLException {

    PreparedStatement statement = connection.prepareStatement(sqlProperties);
    try {
      statement.setLong(1, id);
      ResultSet rs = statement.executeQuery();

      while (rs.next()) {
        String key = rs.getString(1);
        String value = rs.getString(2);
        event.setProperty(key, value);
      }
    } finally {
      statement.close();
    }
  }
835661
def get_user_properties(user_or_username):
    
    user = get_user(user_or_username)
    if user is None:
        return {}
    if not callable(user.getUser):
        return {}
    out = {}
    plone_user = user.getUser()
    for sheet in plone_user.listPropertysheets():
        ps = plone_user.getPropertysheet(sheet)
        out.update(dict(ps.propertyItems()))
    return out
370353
def basic_set_of_users_exists_in_the_database(context):
    
    user_model = get_user_model()
    user_model.objects.create(
        username='administrator',
        is_staff=True
    )
    user_model.objects.create(
        username='allowed_user'
    )
    user_model.objects.create(
        username='unallowed_user'
    )