vendor/bundles/JMS/SecurityExtraBundle/Security/Authentication/Token/RunAsUserToken.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * Copyright 2010 Johannes M. Schmitt <schmittjoh@gmail.com>
       
     5  *
       
     6  * Licensed under the Apache License, Version 2.0 (the "License");
       
     7  * you may not use this file except in compliance with the License.
       
     8  * You may obtain a copy of the License at
       
     9  *
       
    10  * http://www.apache.org/licenses/LICENSE-2.0
       
    11  *
       
    12  * Unless required by applicable law or agreed to in writing, software
       
    13  * distributed under the License is distributed on an "AS IS" BASIS,
       
    14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    15  * See the License for the specific language governing permissions and
       
    16  * limitations under the License.
       
    17  */
       
    18 
       
    19 namespace JMS\SecurityExtraBundle\Security\Authentication\Token;
       
    20 
       
    21 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
       
    22 use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
       
    23 
       
    24 /**
       
    25  * This token is automatically generated by the RunAsManager when an invocation
       
    26  * is supposed to be run with a different Token.
       
    27  *
       
    28  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
       
    29  */
       
    30 class RunAsUserToken extends AbstractToken
       
    31 {
       
    32     private $originalToken;
       
    33     private $key;
       
    34     private $credentials;
       
    35 
       
    36     public function __construct($key, $user, $credentials, array $roles, TokenInterface $originalToken)
       
    37     {
       
    38         parent::__construct($roles);
       
    39 
       
    40         $this->originalToken = $originalToken;
       
    41         $this->credentials = $credentials;
       
    42         $this->key = $key;
       
    43 
       
    44         $this->setUser($user);
       
    45         $this->setAuthenticated(true);
       
    46     }
       
    47 
       
    48     public function getKey()
       
    49     {
       
    50         return $this->key;
       
    51     }
       
    52 
       
    53     public function getOriginalToken()
       
    54     {
       
    55         return $this->originalToken;
       
    56     }
       
    57 
       
    58     public function getCredentials()
       
    59     {
       
    60         return $this->credentials;
       
    61     }
       
    62 
       
    63     public function eraseCredentials()
       
    64     {
       
    65         parent::eraseCredentials();
       
    66 
       
    67         $this->credentials = null;
       
    68     }
       
    69 
       
    70     public function serialize()
       
    71     {
       
    72         return serialize(array(
       
    73             $this->originalToken,
       
    74             $this->key,
       
    75             $this->credentials,
       
    76             parent::serialize(),
       
    77         ));
       
    78     }
       
    79 
       
    80     public function unserialize($str)
       
    81     {
       
    82         list($this->originalToken, $this->key, $this->credentials, $parentStr) = unserialize($str);
       
    83         parent::unserialize($parentStr);
       
    84     }
       
    85 }