NutzCN Logo
问答 nutz shiro集成
发布于 2698天前 作者 qq_32ee9e89 2747 次浏览 复制 上一个帖子 下一个帖子
标签:

NutzdaoRealm的doGetAuthorizationInfo和doGetAuthenticationInfo方法都未用到,shiro.ini里是还得配置什么内容吗?

[main]
nutzdao_realm = util.NutzdaoRealm
authc = org.nutz.integration.shiro.SimpleAuthenticationFilter
authc.loginUrl = /user/login
perms.loginUrl = /user/login
roles.loginUrl = /user/login
user.loginUrl = /user/login
rest.loginUrl = /user/login
logout.redirectUrl = /user/login

[urls]
/ = anon
/user/logout = logout
/user/login = anon
/hello/* = anon
/say = anon
/index = anon
/** = user

26 回复

把文档看完

就是把文档看到“添加入口方法完成登陆”这一步,并且也是按照文档来操作的

啥文档?链接贴一下

那你加入口方法没?能进入口方法没?

加了 但是代码执行没有这一行的输出System.out.println("subject"+subject);

 NutMap re = new NutMap().setv("ok", false);

        System.out.println("login success"+username+"password"+password);
        // 如果已经登陆过,直接返回真
        Subject subject = SecurityUtils.getSubject();
        System.out.println("subject"+subject);
        subject.login(new SimpleShiroToken());
        if (subject.isAuthenticated())
            return re.setv("ok", true);

System.out.println("login success"+username+"password"+password); 这一行的输出是有的。

报错抛异常了?

没有异常 ,但是Subject subject = SecurityUtils.getSubject();断点的时候,指向了 ModuleProcessor的

if (reqContext != null)
                try {
                    reqContext.depose();
                }
                catch (Throwable e) {
                    if (log.isDebugEnabled())
                        log.debug("ReqContext depose fail?!", e);
                }

Debug 的reqContext内容为null

web.xml没改好

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <filter>
        <filter-name>nutz</filter-name>
        <filter-class>org.nutz.mvc.NutFilter</filter-class>
        <init-param>
            <param-name>modules</param-name>
            <param-value>demo.MainMoudle</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>nutz</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>ShiroFilter</filter-name>
        <!-- filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class -->
        <!-- 原生ShiroFilter,每次请求都会touch一次session,导致session持久化的时候压力非常大.ShiroFilter2能解决这个问题 -->
        <filter-class>org.nutz.integration.shiro.ShiroFilter2</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ShiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

调整完顺序以后,执行到这一行subject.login(new SimpleShiroToken());Debug还是这个

if (reqContext != null)
                try {
                    reqContext.depose();
                }
                catch (Throwable e) {
                    if (log.isDebugEnabled())
                        log.debug("ReqContext depose fail?!", e);
                }

贴后台日志,看看报啥错误

后台没有异常输出,断点只有这个提示reqContext :null

tomcat启动以后,清除控制台,再进行访问的时候没有任何日志输出。

日志要配为debug

D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21\bin\catalina.bat run
[2017-08-03 06:37:57,083] Artifact Gradle : cloud : cloud-1.0-SNAPSHOT.war (exploded): Server is not connected. Deploy is not available.
Using CATALINA_BASE:   "C:\Users\liubo\.IntelliJIdea2017.1\system\tomcat\Unnamed_cloud"
Using CATALINA_HOME:   "D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21"
Using CATALINA_TMPDIR: "D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21\temp"
Using JRE_HOME:        "D:\tools\jdk8"
Using CLASSPATH:       "D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21\bin\bootstrap.jar;D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21\bin\tomcat-juli.jar"
Connected to the target VM, address: '127.0.0.1:50022', transport: 'socket'
03-Aug-2017 18:37:58.791 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.0.M21
03-Aug-2017 18:37:58.797 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          May 4 2017 22:42:36 UTC
03-Aug-2017 18:37:58.797 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         9.0.0.0
03-Aug-2017 18:37:58.797 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
03-Aug-2017 18:37:58.797 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
03-Aug-2017 18:37:58.797 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
03-Aug-2017 18:37:58.798 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             D:\tools\jdk8\jre
03-Aug-2017 18:37:58.798 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_131-b11
03-Aug-2017 18:37:58.798 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
03-Aug-2017 18:37:58.798 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\liubo\.IntelliJIdea2017.1\system\tomcat\Unnamed_cloud
03-Aug-2017 18:37:58.799 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21
03-Aug-2017 18:37:58.799 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\liubo\.IntelliJIdea2017.1\system\tomcat\Unnamed_cloud\conf\logging.properties
03-Aug-2017 18:37:58.799 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
03-Aug-2017 18:37:58.800 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50022,suspend=y,server=n
03-Aug-2017 18:37:58.800 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -javaagent:C:\Users\liubo\.IntelliJIdea2017.1\system\groovyHotSwap\gragent.jar
03-Aug-2017 18:37:58.800 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
03-Aug-2017 18:37:58.800 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
03-Aug-2017 18:37:58.800 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
03-Aug-2017 18:37:58.801 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
03-Aug-2017 18:37:58.801 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
03-Aug-2017 18:37:58.801 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
03-Aug-2017 18:37:58.801 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
03-Aug-2017 18:37:58.802 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\liubo\.IntelliJIdea2017.1\system\tomcat\Unnamed_cloud
03-Aug-2017 18:37:58.802 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21
03-Aug-2017 18:37:58.803 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21\temp
03-Aug-2017 18:37:58.803 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.12] using APR version [1.5.2].
03-Aug-2017 18:37:58.803 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
03-Aug-2017 18:37:58.804 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
03-Aug-2017 18:37:59.877 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2k  26 Jan 2017]
03-Aug-2017 18:38:00.185 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
03-Aug-2017 18:38:00.283 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
03-Aug-2017 18:38:00.287 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
03-Aug-2017 18:38:00.290 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
03-Aug-2017 18:38:00.291 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2228 ms
03-Aug-2017 18:38:00.451 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
03-Aug-2017 18:38:00.451 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.0.M21
03-Aug-2017 18:38:00.484 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Aug-2017 18:38:00.508 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
03-Aug-2017 18:38:00.514 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 221 ms
Connected to server
[2017-08-03 06:38:00,936] Artifact Gradle : cloud : cloud-1.0-SNAPSHOT.war (exploded): Artifact is being deployed, please wait...
03-Aug-2017 18:38:03.863 信息 [RMI TCP Connection(5)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
log4j:WARN No appenders could be found for logger (org.apache.shiro.web.env.EnvironmentLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[2017-08-03 06:38:06,218] Artifact Gradle : cloud : cloud-1.0-SNAPSHOT.war (exploded): Artifact is deployed successfully
[2017-08-03 06:38:06,218] Artifact Gradle : cloud : cloud-1.0-SNAPSHOT.war (exploded): Deploy took 5,282 milliseconds
03-Aug-2017 18:38:07.786 信息 [http-nio-8080-exec-3] org.apache.tomcat.util.http.parser.Cookie.logInvalidHeader A cookie header was received [1496109312; Hm_lvt_199b8a0055e193852ba6822737b053b6=1495790638,1496109312; _ga=GA1.1.153016834.1496065850; JSESSIONID=13191C6847B8C6164E08B8AE62463356] that contained an invalid cookie. That cookie will be ignored.Note: further occurrences of this error will be logged at DEBUG level.
03-Aug-2017 18:38:10.500 信息 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21\webapps\manager]
03-Aug-2017 18:38:10.577 信息 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
03-Aug-2017 18:38:10.592 信息 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\tools\apache-tomcat-9.0.0.M21-windows-x64\apache-tomcat-9.0.0.M21\webapps\manager] has finished in [92] ms

log4j就没配好

Log4j不会影响到shiro吧

没日志根本不知道报啥错误

是死是活也回复一下啊

抱歉,因为临时有急事,没有及时看到您的消息,配上日志以后。这个问题已经解决了,今天遇到个新的问题,建了一个新帖子。

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