shiro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SimeĆ³ Reig <simeo.r...@grupoincofisa.com>
Subject rememberMe not working after creating own realm
Date Wed, 22 Feb 2017 19:16:44 GMT
Hello All 

  We had a shiro web JSF app working smoothless, but we need to have an
own Realm, therefore we extended AuthorizingRealm. The system works but
now rememberMe function does not work, shiro does not create the cookie.


Must we implement rememberMe function too if we implemented our Realm??
how? 

Many thanks in advance 

---------------- 

Our custom realm 

----------------- 

public class myRealm extends AuthorizingRealm {

    @Override
    protected AuthorizationInfo
doGetAuthorizationInfo(PrincipalCollection principals) {
        Set<String> roles = new HashSet<>();
        Collection<User> principalsList = principals.byType(User.class);

        if (principalsList.isEmpty())  throw new
AuthorizationException("Empty principals list!");

        for (User userPrincipal : principalsList) {
            try {
                User user = new
User(userPrincipal.getId(),userPrincipal.getName(),userPrincipal.getPassword());
                List<Role> userRoles = user.getRoles();
                for (Role r : userRoles) {roles.add(r.getName());
                }
            } catch (Exception rEx) {
                throw new AuthorizationException(rEx);
            }
        }

        SimpleAuthorizationInfo info = new
SimpleAuthorizationInfo(roles);
        info.setRoles(roles); //fill in roles 
        return info;
    }

    @Override
    protected AuthenticationInfo
doGetAuthenticationInfo(AuthenticationToken token) throws
AuthenticationException {

        UsernamePasswordToken upToken = (UsernamePasswordToken) token;

        System.out.println("isRememberMe Activated ===> " +
upToken.isRememberMe());

        User user = new User(1,upToken.getUsername(),"password");

        if (user == null) {throw new AuthenticationException("Login name
[" + upToken.getUsername() + "] not found!");}

        return new SimpleAuthenticationInfo(user, user.getPassword(),
ByteSource.Util.bytes(user.getSalt()), getName());
    }

} 

--------- 

shiro.ini 

--------- 

[main] 
authc.loginUrl = /faces/login.xhtml
user.loginUrl = /faces/login.xhtml

adronicaRealm = com.adronica.shirofaces.myRealm

authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
securityManager.rememberMeManager.cookie.name = shiroTest
securityManager.realms = $adronicaRealm

[urls]
/faces/admin/index.xhtml=user
/faces/admin/protected.xhtml = user,roles[admin]

------ 

pom.xml 

--------- 

    <dependencies>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.4.0-RC2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-web</artifactId>
            <version>1.4.0-RC2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-faces</artifactId>
            <version>2.0</version>
        </dependency>        

        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>2.6</version> 
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>  
            <groupId>org.primefaces</groupId>  
            <artifactId>primefaces</artifactId>  
            <version>6.0</version>  
        </dependency>  

    </dependencies>
Mime
View raw message