IocBean 注入了一个 继承的 AbstractSimpleAuthorizingRealm
@IocBean(name="shiroRealm")
public class SimpleAuthorizingRealm extends AbstractSimpleAuthorizingRealm {
private static final Log log = Logs.get();
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
log.infof("doGetAuthorizationInfo.......1");
if (principals == null) {
throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
}
BmsUser user = (BmsUser) principals.getPrimaryPrincipal();
if (user == null)
return null;
SimpleAuthorizationInfo auth = new SimpleAuthorizationInfo();
auth.addRole(user.getRealName());
for (String authPermission : user.getAuthPermissions()) {
log.debugf("User [%s] addStringPermission - [%s]", user.getUserName(), authPermission);
auth.addStringPermission(authPermission);
}
return auth;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
log.infof("doGetAuthorizationInfo.......2");
SimpleShiroToken upToken = (SimpleShiroToken) token;
BmsUser user = (BmsUser) upToken.getPrincipal();
if (user == null)
return null;
return new SimpleAccount(user, user.getPassword(), user.getRealName());
}
页面入口注解了
@RequiresPermissions("account:visit")
@At("/")
@Ok("beetl:/tml/account.btl")
@RequiresPermissions("account:visit")
public void main() {
}
应用启动打印:
logback: 11:11:50.722 [main] INFO o.a.shiro.web.env.EnvironmentLoader - Starting Shiro environment initialization.
logback: 11:11:50.976 [main] INFO o.a.shiro.web.env.EnvironmentLoader - Shiro environment initialized in 254 ms.
访问入口没有拦截 不知道为什么