48 if ( !isset( $params[
'sessionCookieName'] ) ) {
49 $params[
'sessionCookieName'] =
'_BPsession';
51 parent::__construct( $params );
53 if ( !isset( $params[
'priority'] ) ) {
54 throw new \InvalidArgumentException( __METHOD__ .
': priority must be specified' );
59 throw new \InvalidArgumentException( __METHOD__ .
': Invalid priority' );
62 $this->priority = $params[
'priority'];
64 $this->grantsInfo = $grantsInfo;
69 if ( !defined(
'MW_API' ) && !defined(
'MW_REST_API' ) ) {
109 'persisted' => $id !==
null,
114 'rights' => $this->grantsInfo->getGrantRights( $bp->
getGrants() ),
117 $session = $this->
getManager()->getSessionFromInfo( $info, $request );
127 $missingKeys = array_diff(
128 [
'centralId',
'appId',
'token' ],
129 array_keys( $metadata )
131 if ( $missingKeys ) {
132 $this->logger->info(
'Session "{session}": Missing metadata: {missing}', [
134 'missing' => implode(
', ', $missingKeys ),
139 $bp = BotPassword::newFromCentralId( $metadata[
'centralId'], $metadata[
'appId'] );
142 'Session "{session}": No BotPassword for {centralId} {appId}',
145 'centralId' => $metadata[
'centralId'],
146 'appId' => $metadata[
'appId'],
151 if ( !hash_equals( $metadata[
'token'], $bp->getToken() ) ) {
152 $this->logger->info(
'Session "{session}": BotPassword token check failed', [
154 'centralId' => $metadata[
'centralId'],
155 'appId' => $metadata[
'appId'],
160 $status = $bp->getRestrictions()->check( $request );
161 if ( !$status->isOK() ) {
163 'Session "{session}": Restrictions check failed',
166 'restrictions' => $status->getValue(),
167 'centralId' => $metadata[
'centralId'],
168 'appId' => $metadata[
'appId'],
174 $metadata[
'rights'] = $this->grantsInfo->getGrantRights( $bp->getGrants() );
184 BotPassword::removeAllPasswordsForUser( $username );
189 throw new \InvalidArgumentException(
'Backend\'s provider isn\'t $this' );
192 if ( $data && isset( $data[
'rights'] ) && is_array( $data[
'rights'] ) ) {
193 return $data[
'rights'];
197 $this->logger->debug( __METHOD__ .
': No provider metadata, returning no rights allowed' );
Utility class for bot passwords.
getUserCentralId()
Get the central user ID.
A class containing constants representing the names of configuration variables.
const EnableBotPasswords
Name constant for the EnableBotPasswords setting, for use with Config::get()
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...