NutzCN Logo
问答 请教关于shiro的问题
发布于 1947天前 作者 文涛(wentao) 1715 次浏览 复制 上一个帖子 下一个帖子
标签:

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.

访问入口没有拦截 不知道为什么

13 回复

/platform/**=platformAuthc
配了没

不知道是什么配置,我用的nutzboot

logback: 11:36:22.229 [main] INFO  o.n.i.l.a.AnnotationIocLoader -  > scan 'org.nutz.boot.starter'
logback: 11:36:22.254 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'nbServletContextListener                ' - org.nutz.boot.starter.servlet3.NbServletContextListener
logback: 11:36:22.255 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'beetlGroupTemplateStarter               ' - org.nutz.boot.starter.beetl.BeetlGroupTemplateStarter
logback: 11:36:22.258 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add '$views_beetl                            ' - org.nutz.boot.starter.beetl.BeetlViewMakerStarter
logback: 11:36:22.259 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'dataSourceStarter                       ' - org.nutz.boot.starter.jdbc.DataSourceStarter
logback: 11:36:22.260 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'druidWebStatFilterStarter               ' - org.nutz.boot.starter.jdbc.DruidWebStatFilterStarter
logback: 11:36:22.261 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'druidWebStatServletStarter              ' - org.nutz.boot.starter.jdbc.DruidWebStatServletStarter
logback: 11:36:22.262 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'jettyStarter                            ' - org.nutz.boot.starter.jetty.JettyStarter
logback: 11:36:22.271 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'nutDaoStarter                           ' - org.nutz.boot.starter.nutz.dao.NutDaoStarter
logback: 11:36:22.280 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'nutFilterStarter                        ' - org.nutz.boot.starter.nutz.mvc.NutFilterStarter
logback: 11:36:22.280 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'whaleFilterStarter                      ' - org.nutz.boot.starter.nutz.mvc.WhaleFilterStarter
logback: 11:36:22.282 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'quartzStarter                           ' - org.nutz.boot.starter.quartz.QuartzStarter
logback: 11:36:22.283 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'shiroEnvStarter                         ' - org.nutz.boot.starter.shiro.ShiroEnvStarter
logback: 11:36:22.286 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'shiroFilterStarter                      ' - org.nutz.boot.starter.shiro.ShiroFilterStarter
logback: 11:36:22.288 [main] INFO  o.n.i.l.a.AnnotationIocLoader -    > add 'swaggerServletStarter                   ' - org.nutz.boot.starter.swagger.SwaggerServletStarter
logback: 11:36:22.297 [main] INFO  org.nutz.ioc.impl.NutIoc - ... NutIoc init complete
logback: 11:36:22.328 [main] INFO  org.quartz.impl.StdSchedulerFactory - Using default implementation for ThreadExecutor
logback: 11:36:22.338 [main] INFO  o.quartz.core.SchedulerSignalerImpl - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
logback: 11:36:22.338 [main] INFO  org.quartz.core.QuartzScheduler - Quartz Scheduler v.2.3.0 created.
logback: 11:36:22.339 [main] INFO  org.quartz.simpl.RAMJobStore - RAMJobStore initialized.
logback: 11:36:22.340 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v2.3.0) 'NutzbootScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 8 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

logback: 11:36:22.340 [main] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler 'NutzbootScheduler' initialized from an externally provided properties instance.
logback: 11:36:22.340 [main] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler version: 2.3.0
logback: 11:36:22.340 [main] INFO  org.quartz.core.QuartzScheduler - JobFactory set to: org.nutz.integration.quartz.NutQuartzJobFactory@3e6ef8ad
logback: 11:36:22.774 [main] INFO  o.n.b.s.j.DruidWebStatServletStarter - druid stat view random user=druid password=ve9cnvapnoh1jpbqhct0t2p0f0
logback: 11:36:22.776 [main] INFO  o.a.shiro.web.env.EnvironmentLoader - Starting Shiro environment initialization.
logback: 11:36:23.031 [main] INFO  o.a.shiro.web.env.EnvironmentLoader - Shiro environment initialized in 255 ms.
logback: 11:36:23.052 [main] INFO  org.nutz.mvc.NutFilter - NutFilter[nutz] starting ...
logback: 11:36:23.054 [main] INFO  o.n.r.impl.ErrorResourceLocation - [loc=/data/bms/static/WEB-INF/classes]not exist
logback: 11:36:23.057 [main] INFO  org.nutz.mvc.impl.NutLoading - Nutz Version : 1.r.68.v20190516
logback: 11:36:23.057 [main] INFO  org.nutz.mvc.impl.NutLoading - Nutz.Mvc[nutz] is initializing ...
logback: 11:36:23.060 [main] INFO  org.nutz.mvc.impl.NutLoading - Build URL mapping by org.nutz.mvc.impl.UrlMappingImpl ...
logback: 11:36:23.101 [main] INFO  org.nutz.filepool.NutFilePool - Init file-pool by: /data/bms/static/WEB-INF/tmp [2000]
logback: 11:36:23.101 [main] INFO  org.nutz.filepool.NutFilePool - file-pool.cursor: 0
logback: 11:36:23.130 [main] INFO  org.nutz.mvc.impl.NutLoading - Found 66 module methods
logback: 11:36:23.134 [main] INFO  org.nutz.mvc.impl.NutLoading - Nutz.Mvc[nutz] is up in 76ms
logback: 11:36:23.134 [main] INFO  org.nutz.mvc.NutFilter - exclusionsPrefix  = ^(/druid/)
logback: 11:36:23.134 [main] INFO  org.nutz.mvc.NutFilter - exclusionsPath   = [/swagger/swagger.json]
logback: 11:36:23.301 [main] INFO  o.n.b.starter.quartz.QuartzStarter - Starting Quartz Scheduler now
logback: 11:36:23.301 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler NutzbootScheduler_$_NON_CLUSTERED started.
logback: 11:36:23.434 [main] INFO  org.nutz.dao.jdbc.Jdbcs - Get Connection from DataSource for JdbcExpert, if you lock at here, check your database server and configure
Sat Aug 24 11:36:23 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
logback: 11:36:23.728 [main] INFO  c.alibaba.druid.pool.DruidDataSource - {dataSource-1} inited
logback: 11:36:23.898 [main] INFO  org.nutz.boot.NbApp - NB started : 2073ms
logback: 11:36:31.497 [qtp1715248762-58] INFO  o.a.s.s.m.AbstractValidatingSessionManager - Enabling session validation scheduler...

这是启动日志

我搜索shiro关键词,只有那2行,我看demo里是继承的AuthorizingRealm,我改了下,依然不行

demo里还有一个配置

shiro.ini.urls:
/rs = anon
/home.html = authc

担感觉这不是必要配置

那你的shiro.ini.urls:写了啥

不过你用了注解,跟这个也关系不大

是不是自定义@ChainBy了

我主入口有:

@ChainBy(type = LogChainMaker.class, args = {})
public class MainLauncher extends BaseModule {

应该要加

list.add(new NutShiroProcessor());

@qq_b1ca03f7 可以在demo 来个Pull requests

添加回复
请先登陆
回到顶部