43 if ( !isset( $params[
'sessionCookieName'] ) ) {
44 $params[
'sessionCookieName'] =
'_BPsession';
46 parent::__construct( $params );
48 if ( !isset( $params[
'priority'] ) ) {
49 throw new \InvalidArgumentException( __METHOD__ .
': priority must be specified' );
54 throw new \InvalidArgumentException( __METHOD__ .
': Invalid priority' );
57 $this->priority = $params[
'priority'];
62 if ( !defined(
'MW_API' ) ) {
67 if ( !$this->config->get(
'EnableBotPasswords' ) ) {
102 'persisted' => $id !==
null,
110 $session = $this->
getManager()->getSessionFromInfo( $info, $request );
116 $missingKeys = array_diff(
117 [
'centralId',
'appId',
'token' ],
118 array_keys( $metadata )
120 if ( $missingKeys ) {
121 $this->logger->info(
'Session "{session}": Missing metadata: {missing}', [
123 'missing' => implode(
', ', $missingKeys ),
131 'Session "{session}": No BotPassword for {centralId} {appId}',
134 'centralId' => $metadata[
'centralId'],
135 'appId' => $metadata[
'appId'],
140 if ( !hash_equals( $metadata[
'token'], $bp->getToken() ) ) {
141 $this->logger->info(
'Session "{session}": BotPassword token check failed', [
143 'centralId' => $metadata[
'centralId'],
144 'appId' => $metadata[
'appId'],
149 $status = $bp->getRestrictions()->check( $request );
150 if ( !$status->isOK() ) {
152 'Session "{session}": Restrictions check failed',
155 'restrictions' => $status->getValue(),
156 'centralId' => $metadata[
'centralId'],
157 'appId' => $metadata[
'appId'],
163 $metadata[
'rights'] = \MWGrants::getGrantRights( $bp->getGrants() );
178 throw new \InvalidArgumentException(
'Backend\'s provider isn\'t $this' );
181 if ( $data && isset( $data[
'rights'] ) && is_array( $data[
'rights'] ) ) {
182 return $data[
'rights'];
186 $this->logger->debug( __METHOD__ .
': No provider metadata, returning no rights allowed' );
Utility class for bot passwords.
getUserCentralId()
Get the central user ID.
getGrants()
Get the grants.
getAppId()
Get the app ID.
static newFromCentralId( $centralId, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
static removeAllPasswordsForUser( $username)
Remove all passwords for a user, by name.
static getGrantRights( $grants)
Fetch the rights allowed by a set of grants.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...