gpt4 book ai didi

security - Apache Shiro - 基于表单的身份验证似乎对我不起作用

转载 作者:行者123 更新时间:2023-12-02 22:04:14 24 4
gpt4 key购买 nike

我在实现基于表单的身份验证时遇到问题。我创建了一个简单的 Web 应用程序,在打开页面 (/jsp/index.jsp) 之前,我想检查用户的权限并在必要时打开登录页面。

不幸的是,如果我尝试打开index.jsp的链接(http://localhost:8080/mywebapp/jsp/index.jsp),index.jsp会立即出现,但我期望首先是login.jsp!以下是重要文件:

Shiro.ini

[main]
# specify login page
authc.loginUrl = /login.jsp
# name of request parameter with username; if not present filter assumes 'username'
authc.usernameParam = user
# name of request parameter with password; if not present filter assumes 'password'
authc.passwordParam = passw
# does the user wish to be remembered?; if not present filter assumes 'rememberMe'
authc.rememberMeParam = remember
[url]
# enable authc filter for all application pages
/jsp/** = authc
[users]
adminstrator=throttling,Administrator

web.xml

<web-app id="starter" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

这是ma​​ven项目/src/main的目录结构

├───java
├───resources
│ log4j.properties
│ Shiro.ini

└───webapp
│ login.jsp

├───jsp
│ index.jsp

└───WEB-INF
│ web.xml

└───lib

我将这两个依赖项添加到 pom.xml

    <dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.2.1</version>
</dependency>

希望我写下了任何重要信息!谁能帮助我为什么它对我不起作用?谢谢,V。

log4j.properties

log4j.rootLogger=TRACE, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c]: %m%n
log4j.logger.net.sf.ehcache=WARN
log4j.logger.org.apache=WARN
log4j.logger.org.quartz=WARN
log4j.logger.org.apache.shiro=TRACE
log4j.logger.org.apache.shiro.util.ThreadContext=INFO

最佳答案

抱歉,我在 shiro.ini 中犯了一个错误。我写了 [url] 而不是 [urls]...再次抱歉并感谢您的帮助!

关于security - Apache Shiro - 基于表单的身份验证似乎对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14499703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com