9use InvalidArgumentException;
27 private $isApiRequest;
38 if ( !isset( $params[
'sessionCookieName'] ) ) {
39 $params[
'sessionCookieName'] =
'_BPsession';
41 parent::__construct( $params );
43 if ( !isset( $params[
'priority'] ) ) {
44 throw new InvalidArgumentException( __METHOD__ .
': priority must be specified' );
49 throw new InvalidArgumentException( __METHOD__ .
': Invalid priority' );
52 $this->priority = $params[
'priority'];
54 $this->grantsInfo = $grantsInfo;
56 $this->isApiRequest = $params[
'isApiRequest']
57 ?? ( defined(
'MW_API' ) || defined(
'MW_REST_API' ) );
63 if ( !$this->isApiRequest ) {
104 'persisted' => $id !==
null,
109 'rights' => $this->grantsInfo->getGrantRights( $bp->
getGrants() ),
113 $session = $this->
getManager()->getSessionFromInfo( $info, $request );
123 $missingKeys = array_diff(
124 [
'centralId',
'appId',
'token' ],
125 array_keys( $metadata )
127 if ( $missingKeys ) {
128 $this->logger->info(
'Session "{session}": Missing metadata: {missing}', [
130 'missing' => implode(
', ', $missingKeys ),
135 $bp = BotPassword::newFromCentralId( $metadata[
'centralId'], $metadata[
'appId'] );
138 'Session "{session}": No BotPassword for {centralId} {appId}',
141 'centralId' => $metadata[
'centralId'],
142 'appId' => $metadata[
'appId'],
147 if ( !hash_equals( $metadata[
'token'], $bp->getToken() ) ) {
148 $this->logger->info(
'Session "{session}": BotPassword token check failed', [
150 'centralId' => $metadata[
'centralId'],
151 'appId' => $metadata[
'appId'],
156 $status = $bp->getRestrictions()->check( $request );
157 if ( !$status->isOK() ) {
159 'Session "{session}": Restrictions check failed',
162 'restrictions' => $status->getValue(),
163 'centralId' => $metadata[
'centralId'],
164 'appId' => $metadata[
'appId'],
170 $metadata[
'rights'] = $this->grantsInfo->getGrantRights( $bp->getGrants() );
180 BotPassword::removeAllPasswordsForUser( $username );
186 throw new InvalidArgumentException(
'Backend\'s provider isn\'t $this' );
189 if ( $data && isset( $data[
'rights'] ) && is_array( $data[
'rights'] ) ) {
190 return $data[
'rights'];
194 $this->logger->debug( __METHOD__ .
': No provider metadata, returning no rights allowed' );
199 if ( $data && isset( $data[
'restrictions'] ) && is_string( $data[
'restrictions'] ) ) {
201 return MWRestrictions::newFromJson( $data[
'restrictions'] );
202 }
catch ( InvalidArgumentException ) {
203 $this->logger->warning( __METHOD__ .
': Failed to parse restrictions: {restrictions}', [
204 'restrictions' => $data[
'restrictions']
if(!defined('MW_SETUP_CALLBACK'))
A class to check request restrictions expressed as a JSON object.
A class containing constants representing the names of configuration variables.
const EnableBotPasswords
Name constant for the EnableBotPasswords setting, for use with Config::get()