AppserverIo\Appserver\ServletEngine\Security\Auth\Spi\AbstractLoginModule::initialize PHP 메소드

initialize() 공개 메소드

The following parameters can by default be passed from the configuration. passwordStacking: If this is set to "useFirstPass", the login identity will be taken from the appserver.security.auth.login.name value of the sharedState map, and the proof of identity from the appserver.security.auth.login.password value of the sharedState map principalClass: A Principal implementation that support a constructor taking a string argument for the princpal name unauthenticatedIdentity: The name of the principal to asssign and authenticate when a null username and password are seen
public initialize ( AppserverIo\Psr\Security\Auth\Subject $subject, AppserverIo\Psr\Security\Auth\Callback\CallbackHandlerInterface $callbackHandler, AppserverIo\Collections\MapInterface $sharedState, AppserverIo\Collections\MapInterface $params ) : void
$subject AppserverIo\Psr\Security\Auth\Subject The Subject to update after a successful login
$callbackHandler AppserverIo\Psr\Security\Auth\Callback\CallbackHandlerInterface The callback handler that will be used to obtain the user identity and credentials
$sharedState AppserverIo\Collections\MapInterface A map shared between all configured login module instances
$params AppserverIo\Collections\MapInterface The parameters passed to the login module
리턴 void
    public function initialize(Subject $subject, CallbackHandlerInterface $callbackHandler, MapInterface $sharedState, MapInterface $params)
    {
        // initialize the passed parameters
        $this->params = $params;
        $this->subject = $subject;
        $this->sharedState = $sharedState;
        $this->callbackHandler = $callbackHandler;
        // query whether or not we have password stacking activated or not
        if ($params->exists(ParamKeys::PASSWORD_STACKING) && $params->get(ParamKeys::PASSWORD_STACKING) === 'useFirstPass') {
            $this->useFirstPass = true;
        }
        // check for a custom principal implementation
        if ($params->exists(ParamKeys::PRINCIPAL_CLASS)) {
            $this->principalClassName = new String($params->get(ParamKeys::PRINCIPAL_CLASS));
        }
        // check for unauthenticatedIdentity option.
        if ($params->exists(ParamKeys::UNAUTHENTICATED_IDENTITY)) {
            $this->unauthenticatedIdentity = $this->createIdentity($params->get(ParamKeys::UNAUTHENTICATED_IDENTITY));
        }
    }

Usage Example

 /**
  * Initialize the login module. This stores the subject, callbackHandler and sharedState and options
  * for the login session. Subclasses should override if they need to process their own options. A call
  * to parent::initialize() must be made in the case of an override.
  *
  * The following parameters can by default be passed from the configuration.
  *
  * lookupName:      The datasource name used to lookup in the naming directory
  * rolesQuery:      The database query used to load the user's roles
  * principalsQuery: The database query used to load the user
  *
  * @param \AppserverIo\Psr\Security\Auth\Subject                           $subject         The Subject to update after a successful login
  * @param \AppserverIo\Psr\Security\Auth\Callback\CallbackHandlerInterface $callbackHandler The callback handler that will be used to obtain the user identity and credentials
  * @param \AppserverIo\Collections\MapInterface                            $sharedState     A map shared between all configured login module instances
  * @param \AppserverIo\Collections\MapInterface                            $params          The parameters passed to the login module
  *
  * @return void
  */
 public function initialize(Subject $subject, CallbackHandlerInterface $callbackHandler, MapInterface $sharedState, MapInterface $params)
 {
     // call the parent method
     parent::initialize($subject, $callbackHandler, $sharedState, $params);
     // check to see if password hashing has been enabled, if an algorithm is set, check for a format and charset
     $this->hashAlgorithm = new String($params->get(ParamKeys::HASH_ALGORITHM));
     // query whether or not a hash algorithm has been specified
     if ($this->hashAlgorithm != null) {
         // initialize the hash encoding to use
         if ($params->exists(ParamKeys::HASH_ENCODING)) {
             $this->hashEncoding = new String($params->get(ParamKeys::HASH_ENCODING));
         } else {
             $this->hashEncoding = new String(Util::BASE64_ENCODING);
         }
         // initialize the hash charset if specified
         if ($params->exists(ParamKeys::HASH_CHARSET)) {
             $this->hashCharset = new String($params->get(ParamKeys::HASH_CHARSET));
         }
     }
     // query whether or not we should ignor case when comparing passwords
     if ($params->exists(ParamKeys::IGNORE_PASSWORD_CASE)) {
         $flag = new String($params->get(ParamKeys::IGNORE_PASSWORD_CASE));
         $this->ignorePasswordCase = Boolean::valueOf($flag)->booleanValue();
     } else {
         $this->ignorePasswordCase = false;
     }
 }