protected function createPrincipal(String $username, Subject $subject, LoginContextInterface $loginContext)
    {

        // initialize the roles and the user principal
        $roles = new ArrayList();
        $userPrincipal = null;

        // scan the Principals for this Subject
        foreach ($subject->getPrincipals() as $principal) {
            // query whether or not the principal found is a group principal
            if ($principal instanceof GroupInterface && $principal->getName()->equals(new String(Util::DEFAULT_GROUP_NAME))) {
                // if yes, add the role name
                foreach ($principal->getMembers() as $role) {
                    $roles->add($role->getName());
                }

            // query whether or not the principal found is a user principal
            } elseif ($userPrincipal == null && $principal instanceof PrincipalInterface) {
                $userPrincipal = $principal;
            } else {
                // do nothing, because we've no principal or group to deal with
            }
        }

        // return the resulting Principal for our authenticated user
        return new GenericPrincipal($username, null, $roles, $userPrincipal);
    }
protected function createPrincipal(String $username, Subject $subject, LoginContextInterface $loginContext)
    {

        // initialize the roles and the user principal
        $roles = new ArrayList();
        $userPrincipal = null;

        // scan the Principals for this Subject
        foreach ($subject->getPrincipals() as $principal) {
            // query whether or not the principal found is a group principal
            if ($principal instanceof GroupInterface && $principal->getName()->equals(new String(Util::DEFAULT_GROUP_NAME))) {
                // if yes, add the role name
                foreach ($principal->getMembers() as $role) {
                    $roles->add($role->getName());
                }

            // query whether or not the principal found is a user principal
            } elseif ($userPrincipal == null && $principal instanceof PrincipalInterface) {
                $userPrincipal = $principal;
            } else {
                // do nothing, because we've no principal or group to deal with
            }
        }

        // return the resulting Principal for our authenticated user
        return new GenericPrincipal($username, null, $roles, $userPrincipal);
    }
protected function createPrincipal ( String $ username , Subject $ subject , LoginContextInterface $ loginContext ) { // initialize the roles and the user principal $ roles = new ArrayList ( ) ; $ userPrincipal = null ; // scan the Principals for this Subject foreach ( $ subject -> getPrincipals ( ) as $ principal ) { // query whether or not the principal found is a group principal if ( $ principal instanceof GroupInterface && $ principal -> getName ( ) -> equals ( new String ( Util :: DEFAULT_GROUP_NAME ) ) ) { // if yes, add the role name foreach ( $ principal -> getMembers ( ) as $ role ) { $ roles -> add ( $ role -> getName ( ) ) ; } // query whether or not the principal found is a user principal } elseif ( $ userPrincipal == null && $ principal instanceof PrincipalInterface ) { $ userPrincipal = $ principal ; } else { // do nothing, because we've no principal or group to deal with } } // return the resulting Principal for our authenticated user return new GenericPrincipal ( $ username , null , $ roles , $ userPrincipal ) ; }
Identify and return an instance implementing the PrincipalInterface that represens the
authenticated user for the specified Subject. The Principal is constructed by scanning
the list of Principals returned by the LoginModule. The first Principal object that
matches one of the class names supplied as a "user class" is the user Principal. This
object is returned to the caller. Any remaining principal objects returned by the
LoginModules are mapped to roles, but only if their respective classes match one of the
"role class" classes. If a user Principal cannot be constructed, return NULL.

@param \AppserverIo\Lang\String                                   $username     The associated user name
@param \AppserverIo\Psr\Security\Auth\Subject                     $subject      The Subject representing the logged-in user
@param \AppserverIo\Psr\Security\Auth\Login\LoginContextInterface $loginContext Associated with the Principal so {@link LoginContext#logout()} can be called later

@return \AppserverIo\Psr\Security\PrincipalInterface the principal object
Identify and return an instance implementing the PrincipalInterface that represens the authenticated user for the specified Subject . The Principal is constructed by scanning the list of Principals returned by the LoginModule . The first Principal object that matches one of the class names supplied as a user class is the user Principal . This object is returned to the caller . Any remaining principal objects returned by the LoginModules are mapped to roles but only if their respective classes match one of the role class classes . If a user Principal cannot be constructed return NULL .