Shiro provides the realization of your own kingdom as per your requirement.
Create a simple area where you can manage parts, inputs, permissions, and roles. You can use jdbc, Hibernate, or any other authentication method to manage them.
Set this area to your ini or any other method that you use in your project.
Now Shiro will automatically call the methods of your realm class to look up credentials, permissions, and roles.
For me, I have a sleep mode. I used my sleeping code to manage users in my db.
import java.util.Collection; import java.util.Date; import java.util.HashSet; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.authc.SimpleAuthenticationInfo; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.authc.credential.CredentialsMatcher; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.SimpleAuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; public class PortalHibernateRealm extends AuthorizingRealm { private static final Logger LOGGER = new Logger( PortalHibernateRealm.class.toString()); public PortalHibernateRealm() { super(); setCredentialsMatcher(new CredentialsMatcher() { @Override public boolean doCredentialsMatch(AuthenticationToken arg0, AuthenticationInfo arg1) { UsernamePasswordToken token = (UsernamePasswordToken) arg0; String username = token.getUsername(); String password = new String(token.getPassword()); return false; } }); } @Override protected AuthorizationInfo doGetAuthorizationInfo( PrincipalCollection principalCollection) { Collection<String> permissionSet; SimpleAuthorizationInfo info = null; Long userId = (Long) principalCollection.getPrimaryPrincipal();
source share