26use InvalidArgumentException;
42 private $isApiRequest;
53 if ( !isset(
$params[
'sessionCookieName'] ) ) {
54 $params[
'sessionCookieName'] =
'_BPsession';
58 if ( !isset(
$params[
'priority'] ) ) {
59 throw new InvalidArgumentException( __METHOD__ .
': priority must be specified' );
64 throw new InvalidArgumentException( __METHOD__ .
': Invalid priority' );
67 $this->priority =
$params[
'priority'];
69 $this->grantsInfo = $grantsInfo;
71 $this->isApiRequest =
$params[
'isApiRequest']
72 ?? ( defined(
'MW_API' ) || defined(
'MW_REST_API' ) );
77 if ( !$this->isApiRequest ) {
117 'persisted' => $id !==
null,
122 'rights' => $this->grantsInfo->getGrantRights( $bp->
getGrants() ),
126 $session = $this->
getManager()->getSessionFromInfo( $info, $request );
136 $missingKeys = array_diff(
137 [
'centralId',
'appId',
'token' ],
138 array_keys( $metadata )
140 if ( $missingKeys ) {
141 $this->logger->info(
'Session "{session}": Missing metadata: {missing}', [
143 'missing' => implode(
', ', $missingKeys ),
148 $bp = BotPassword::newFromCentralId( $metadata[
'centralId'], $metadata[
'appId'] );
151 'Session "{session}": No BotPassword for {centralId} {appId}',
154 'centralId' => $metadata[
'centralId'],
155 'appId' => $metadata[
'appId'],
160 if ( !hash_equals( $metadata[
'token'], $bp->getToken() ) ) {
161 $this->logger->info(
'Session "{session}": BotPassword token check failed', [
163 'centralId' => $metadata[
'centralId'],
164 'appId' => $metadata[
'appId'],
169 $status = $bp->getRestrictions()->check( $request );
170 if ( !$status->isOK() ) {
172 'Session "{session}": Restrictions check failed',
175 'restrictions' => $status->getValue(),
176 'centralId' => $metadata[
'centralId'],
177 'appId' => $metadata[
'appId'],
183 $metadata[
'rights'] = $this->grantsInfo->getGrantRights( $bp->getGrants() );
193 BotPassword::removeAllPasswordsForUser( $username );
198 throw new InvalidArgumentException(
'Backend\'s provider isn\'t $this' );
201 if ( $data && isset( $data[
'rights'] ) && is_array( $data[
'rights'] ) ) {
202 return $data[
'rights'];
206 $this->logger->debug( __METHOD__ .
': No provider metadata, returning no rights allowed' );
211 if ( $data && isset( $data[
'restrictions'] ) && is_string( $data[
'restrictions'] ) ) {
213 return MWRestrictions::newFromJson( $data[
'restrictions'] );
214 }
catch ( InvalidArgumentException $e ) {
215 $this->logger->warning( __METHOD__ .
': Failed to parse restrictions: {restrictions}', [
216 'restrictions' => $data[
'restrictions']
array $params
The job parameters.
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()