/** * Handles UsernameCallback and PasswordCallback types. A UsernameCallback name property is set to the * Prinicpal->getName() value. A PasswordCallback password property is set to the credential value. * * @param \AppserverIo\Collections\CollectionInterface $callbacks The collection with the callbacks * * @return void * @throws AppserverIo\Psr\Security\Auth\Callback\UnsupporedCallbackException Is thrown if any callback of type other than NameCallback or PasswordCallback has been passed */ public function handle(CollectionInterface $callbacks) { // handle the registered callbacks foreach ($callbacks as $callback) { if ($callback instanceof NameCallback) { $callback->setName($this->principal->getName()); } elseif ($callback instanceof PasswordCallback) { $callback->setPassword($this->credential); } else { throw new UnsupportedCallbackException('Unrecognized Callback'); } } }
/** * Compare this SimplePrincipal's name against another Principal. * * @param \AppserverIo\Psr\Security\PrincipalInterface $another The other principal to compare to * * @return boolean TRUE if name equals $another->getName(); */ public function equals(PrincipalInterface $another) { // query whether or not another principal has been passed if ($another instanceof PrincipalInterface) { $anotherName = $another->getName(); $equals = false; if ($this->name == null) { $equals = $anotherName == null; } else { $equals = $this->name->equals($anotherName); } // return the flag if the both are equal return $equals; } // return FALSE if they are not equal return false; }
/** * Login the passed principal and return a DTO representation. * * @param \AppserverIo\Psr\Security\PrincipalInterface $principal The principal to login * * @return \AppserverIo\Apps\Api\TransferObject\UserPrincipal The user logged into the system * @see \AppserverIo\Apps\Example\Service\UserProcessorInterface::login() */ public function login(PrincipalInterface $principal) { return $principal->getUserPrincipal(); }
/** * Returns TRUE if the passed principal is a member of the group. * This method does a recursive search, so if a principal belongs * to a group which is a member of this group, true is returned. * * A special check is made to see if the member is an instance of * AnybodyPrincipal or NobodyPrincipal since these classes do not * hash to meaningful values. * * @param \AppserverIo\Psr\Security\PrincipalInterface $principal The principal to query membership for * * @return boolean TRUE if the principal is a member of this group, FALSE otherwise */ public function isMember(PrincipalInterface $principal) { // first see if there is a key with the member name $isMember = $this->members->exists($principal->getName()); if ($isMember === false) { // check the AnybodyPrincipal & NobodyPrincipal special cases $isMember = $principal instanceof AnybodyPrincipal; if ($isMember === false) { if ($principal instanceof NobodyPrincipal) { return false; } } } if ($isMember === false) { // check any groups for membership foreach ($this->members as $group) { if ($group instanceof GroupInterface) { $isMember = $group->isMember($principal); } } } return $isMember; }