/*
UserInfo
UserPermissions
AccountData
 ======================================================================================= 使用者資料
14469
function UserInfo() {
	//使用者帳號(索引用)
	this.strAccount = "";
	//電子信箱
	this.strEmail = "";
	//信箱通知勾選
	this.bEmailNotify = false;
	//電話資料
	this.strPhone = "";
	//簡訊通知勾選
	this.bSMSNotify = false;
	//使用者名稱(暱稱?)
	this.strUserName = "";
	//語系控制
	this.strLanguages = "";
	//系統保護
	this.bSystemAegis = false;
	//登入次數
	this.iLoginCount = 0;
	//登入時間
	this.iLogin = 0;
	//最後登出時間
	this.iLastLogout = 0;
}
776972
function getUserdataForAmi_(username, upNamespace, envVars_, origUsername) {
  var envVars = cleanEnvVars(upNamespace, envVars_);

  var script  = [
                "#!/bin/bash -ex",
                ""
  ];
  _.each(envVars, function(value, key) {
    script.push("/usr/local/bin/yoshi-set-env "+key+" "+value);
  });
  script.push(  "");

  console.error(script);
  return script;
}
213416
function role_permissions(roles, callback) {
  var permissions = [],
      fetch = [];

  if (roles) {
    // TODO: Here we could do with some caching like Drupal does.
    roles.forEach(function (name, rid) {
      fetch.push(rid);
    });

    // Get permissions for the rids.
    if (fetch) {
      db.query("SELECT rid, permission FROM role_permission WHERE rid IN ($1);", [fetch], function (err, rows) {
        if (err) {
          callback(err, null);
        }

        if (rows.length > 0) {
          rows.forEach(function (row) {
            permissions.push(row.permission);
          });
        }

        callback(null, permissions);
      });
    }
  }
}
952687
protected function InitUserData()
    {
        $userData = $this->getInputFilterUtil()->getFilteredPostInput('aUser');
        if (null === $userData) {
            $oUser = self::getExtranetUserProvider()->getActiveUser();
            $this->SetUserData($oUser->sqlData);
        } else {
            $this->SetUserData($userData);
            $this->bUserDataSubmission = true;
        }
    }
208249
public function updatePostPermissions() {
		$set = $this->owner->PostPermission;
		$source = $this->postPermissionSource();
		
		switch ($set) {
			case 'Hidden': {
				$this->permissionService->removePermissions($source, 'View', $this->getGroupFor(self::FOLLOWERS));
				$this->permissionService->removePermissions($source, 'View', $this->getGroupFor(self::FRIENDS));

				$source->InheritPerms = false;
				$source->PublicAccess = false;
				break;
			}
			case 'Friends only': {
				$source->InheritPerms = false;
				$source->PublicAccess = false;
				
				$this->permissionService->removePermissions($source, 'View', $this->getGroupFor(self::FOLLOWERS));
				$this->permissionService->grant($source, 'View', $this->getGroupFor(self::FRIENDS));
				break;
			}
			
			case 'Friends and followers': {
				$source->InheritPerms = false;
				$source->PublicAccess = false;

				$this->permissionService->grant($source, 'View', $this->getGroupFor(self::FOLLOWERS));
				$this->permissionService->grant($source, 'View', $this->getGroupFor(self::FRIENDS));
				break;
			}
			
			case 'Logged In': {
				$source->InheritPerms = false;
				$source->PublicAccess = false;

				$this->permissionService->grant($source, 'View', $this->getGroupFor(self::FOLLOWERS));
				$this->permissionService->grant($source, 'View', $this->getGroupFor(self::FRIENDS));
				break;
			}

			case 'Public': {
				$source->PublicAccess = true;
				break;
			}
		}
		
		$source->write();
	}
808897
private static void checkPermission(final Subject user, 
                                      final Permission... permissions) 
  throws AuthorizationException {
    try{
      Subject.doAs(user, 
                   new PrivilegedExceptionAction<Void>() {
                     @Override
                     public Void run() throws Exception {
                       try {
                         for(Permission permission : permissions) {
                           AccessController.checkPermission(permission);
                         }
                       } catch (AccessControlException ace) {
                         LOG.info("Authorization failed for " + 
                                  UserGroupInformation.getCurrentUGI(), ace);
                         throw new AuthorizationException(ace);
                       }
                      return null;
                     }
                   }
                  );
    } catch (PrivilegedActionException e) {
      throw new AuthorizationException(e.getException());
    }
  }
765918
private void updatePermissions(
            IPortletDefinition def,
            Set<IGroupMember> newPrincipals,
            String owner,
            String activity) {
        final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);

        final IUpdatingPermissionManager pm =
                authorizationService.newUpdatingPermissionManager(owner);

        /* Create the new permissions array */
        final List<IPermission> newPermissions = new ArrayList<>();
        for (final IGroupMember newPrincipal : newPrincipals) {
            final IAuthorizationPrincipal authorizationPrincipal =
                    authorizationService.newPrincipal(newPrincipal);
            final IPermission permission = pm.newPermission(authorizationPrincipal);
            permission.setType(IPermission.PERMISSION_TYPE_GRANT);
            permission.setActivity(activity);
            permission.setTarget(portletTargetId);
            newPermissions.add(permission);
            logger.trace("In updatePermissions() - adding a new permission of: {}", permission);
        }

        /* Remove former permissions for this portlet / activity */
        final IPermission[] oldPermissions = pm.getPermissions(activity, portletTargetId);
        pm.removePermissions(oldPermissions);

        /* Add the new permissions */
        pm.addPermissions(newPermissions.toArray(new IPermission[newPermissions.size()]));
    }
257773
def get_permissions(self, user_id):
        """"""
        response = self.request(
            "{0}/{1}/permissions".format(self.version, user_id), {}
        )["data"]
        return {x["permission"] for x in response if x["status"] == "granted"}
1182468
function(data) {
			data = utils.parseJSON(data);

			var userData = resources.getVocabulary('user') || {};
			resources.setVocabulary(utils.deepMerge(userData, data), 'user');
		}
675435
function(objects, user, action, model, body) {
    if (!_.isArray(objects)) {
      return PermissionService.isAllowedToPerformSingle(user.id, action, model, body)(objects);
    }
    return Promise.all(objects.map(PermissionService.isAllowedToPerformSingle(user.id, action, model, body)))
      .then(function (allowedArray) {
        return allowedArray.every(function (allowed) {
          return allowed === true;
        });
      });
  }
593437
public function oAuth2UserInfo()
    {
        $wechat_Oauth2_user_info_url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=".$this->getAccessToken()."&code=".$this->code;
        $client = new Client();
        $json = $client->get($wechat_Oauth2_user_info_url)->getBody();
        $arr = json_decode($json, true);

        if(array_has($arr, 'errcode') && (array_get($arr, 'errcode') == 4001 || array_get($arr, 'errcode') == 4002)){
            $this->getAccessTokenFromWechat();
            $this->oAuth2UserInfo();
        }else{
            $this->oAuth2UserInfoArray = $arr;
        }
    }
15389
public function getPermissions($user_id = null)
    {
        static $permissions = array();

        if (!isset($user_id)) {
            $user_id = $this->uid;
        }

        if (isset($permissions[$user_id])) {
            return $permissions[$user_id];
        }

        $user = $this->get($user_id);

        if (empty($user['role_id'])) {
            return $permissions[$user_id] = array();
        }

        $role = array();
        if (isset($user['role_permissions'])) {
            $role['permissions'] = $user['role_permissions'];
        } else {
            $role = $this->role->get($user['role_id']);
        }

        if (empty($role['permissions'])) {
            return $permissions[$user_id] = array();
        }

        return $permissions[$user_id] = (array) $role['permissions'];
    }
326772
function $permission() {
    'ngInject';

    var defaultOnAuthorizedMethod = 'showElement';
    var defaultOnUnauthorizedMethod = 'hideElement';
    var suppressUndefinedPermissionWarning = false;

    /**
     * Methods allowing to alter default directive onAuthorized behaviour in permission directive
     * @methodOf permission.permissionProvider
     *
     * @param onAuthorizedMethod {String} One of permission.PermPermissionStrategies method names
     */
    this.setDefaultOnAuthorizedMethod = function (onAuthorizedMethod) { // jshint ignore:line
      defaultOnAuthorizedMethod = onAuthorizedMethod;
    };

    /**
     * Methods allowing to alter default directive onUnauthorized behaviour in permission directive
     * @methodOf permission.permissionProvider
     *
     * @param onUnauthorizedMethod {String} One of permission.PermPermissionStrategies method names
     */
    this.setDefaultOnUnauthorizedMethod = function (onUnauthorizedMethod) { // jshint ignore:line
      defaultOnUnauthorizedMethod = onUnauthorizedMethod;
    };


    /**
     * When set to true hides permission warning for undefined roles and permissions
     * @methodOf permission.permissionProvider
     *
     * @param value {Boolean}
     */
    this.suppressUndefinedPermissionWarning = function (value) { // jshint ignore:line
      suppressUndefinedPermissionWarning = value;
    };


    this.$get = function () { // jshint ignore:line
      return {
        defaultOnAuthorizedMethod: defaultOnAuthorizedMethod,
        defaultOnUnauthorizedMethod: defaultOnUnauthorizedMethod,
        suppressUndefinedPermissionWarning: suppressUndefinedPermissionWarning
      };
    };
  }
1310203
@Override
    public boolean checkUserPermission(String pattern, RequestMethod method) {
        // 获取用户角色
        Visitor visitor = ThreadContext.getSessionVisitor();
        if (visitor == null) {
            return false;
        }

        String urlPattarn = pattern;
        if (!urlPattarn.endsWith(RoleResourceConstant.URL_SPLITOR)) {
            urlPattarn += RoleResourceConstant.URL_SPLITOR;
        }

        Integer roleId = visitor.getRoleId();

        Map<String, Map<RequestMethod, List<Integer>>> roleResMap = getAllAsMap();
        Map<RequestMethod, List<Integer>> methodMap = roleResMap.get(urlPattarn);
        if (methodMap == null) {
            return false;
        }

        List<Integer> roleIdList = methodMap.get(method);
        if (roleIdList == null) {
            return false;
        }

        if (!roleIdList.contains(roleId)) {
            return false;
        }
        return true;
    }
366137
public function getUserInformation()
    {
        $deferred = new Deferred();

        $this->http->get(Options::replace(Endpoints::USER_INFO, ['id' => $this->userInfo['userId']]))->then(function ($json) use ($deferred) {
            $deferred->resolve($json);
        }, function ($e) use ($deferred) {
            $deferred->reject($e);
        });

        return $deferred->promise();
    }
351721
function MatrixUser(userId, data, escape=true) {
    if (!userId) {
        throw new Error("Missing user_id");
    }
    if (data && Object.prototype.toString.call(data) !== "[object Object]") {
        throw new Error("data arg must be an Object");
    }
    this.userId = userId;
    const split = this.userId.split(":");
    this.localpart = split[0].substring(1);
    this.host = split[1];
    if (escape) {
        this.escapeUserId();
    }
    this._data = data || {};
}
506860
function(user) {
      if (Parse.User._currentUser !== user) {
        Parse.User.logOut();
      }
      user._isCurrentUser = true;
      Parse.User._currentUser = user;
      Parse.User._currentUserMatchesDisk = true;

      var json = user.toJSON();
      json._id = user.id;
      json._sessionToken = user._sessionToken;
      Parse.localStorage.setItem(
          Parse._getParsePath(Parse.User._CURRENT_USER_KEY),
          JSON.stringify(json));
    }