You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by giandv <di...@gmail.com> on 2013/10/24 10:52:10 UTC

Realm Shiro

Hi all I would like to make the realm of shiro.
Suppose that I put in the user login session, then in my application there
is a form bean that allows me to change the user's credentials and up to
here everything ok.
So I can successfully modify the user but after changing the user you need
to bring it back into session in the realm of practice I do because
otherwise Shiro tags like
<shiro:principal property="surname"/>
will continue to give me the old value before the change.
Mica someone has already had to deal with this problem and knows how to make
realm with Shiro?

I'll post my class realm: MyAuthorizingRealm.

public class MyAuthorizingRealm extends AuthorizingRealm {

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken
token)
            throws AuthenticationException {
        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
        SecurityService service = SondaggioBusinessFactory.
                getInstance().getSecurityService();
        User user = null;
        try {
            user = service.authenticate(upToken.getUsername());
        } catch (BusinessException idEx) {
            throw new AuthenticationException(idEx);
        }
        if (user == null) {
            throw new AuthenticationException(
                    "Login [" + upToken.getUsername() + "] not found!");
        }
        return new SimpleAuthenticationInfo(user, user.getPassword(),
getName());
    }


    @Override
    public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection
principals) {
        Set<String> roles = new HashSet<String>();
        Set<Permission> permissions = new HashSet<Permission>();
        Collection<User> principalsList = principals.byType(User.class);
        if (principalsList.isEmpty()) {
            throw new AuthorizationException("Empty principals list!");
        }
        SecurityService service =
SondaggioBusinessFactory.getInstance().getSecurityService();
        for (User userPrincipal : principalsList) {
            try {
                User user =
service.authenticate(userPrincipal.getUsername());
                Set<Role> userRoles = user.getRoles();
                for (Role r : userRoles) {
                    roles.add(r.getName());
                }
            } catch (BusinessException idEx) { //userManger exceptions
                throw new AuthorizationException(idEx);
            }
        }
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roles);

        info.setRoles(roles);

        info.setObjectPermissions(permissions);
        return info;
    }

}

I give you also the images to better understand the problem.

<http://shiro-user.582556.n2.nabble.com/file/n7579312/before.jpg> Before
Modify
<http://shiro-user.582556.n2.nabble.com/file/n7579312/after.jpg> After
Modify

If you think that you could do with the cache, and you know something please
help me.

Thank you all for your time.



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Realm-Shiro-tp7579312.html
Sent from the Shiro User mailing list archive at Nabble.com.