Security ApacheShiro-基于表单的身份验证不';似乎不适合我

Security ApacheShiro-基于表单的身份验证不';似乎不适合我,security,shiro,Security,Shiro,我在实现基于表单的身份验证时遇到问题。我创建了一个简单的web应用程序,在打开一个页面(/jsp/index.jsp)之前,我想检查用户的权限,并在必要时打开一个登录页面 不幸的是,如果我试图打开index.jsp的链接(http://localhost:8080/mywebapp/jsp/index.jsp)index.jsp马上就出现了,但我希望先出现login.jsp!以下是重要文件: 西罗·伊尼 [main] # specify login page authc.loginUrl = /

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

不幸的是,如果我试图打开index.jsp的链接(http://localhost:8080/mywebapp/jsp/index.jsp)index.jsp马上就出现了,但我希望先出现login.jsp!以下是重要文件:

西罗·伊尼

[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>
我将这两个依赖项添加到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>

如果您在这里显示的是准确的,那么您的问题可能是Shiro在默认情况下查找'Shiro.ini',而您创建了'Shiro.ini'。日志中可能还有一条消息,大意是“ShiroFilter无法找到ini文件”


另外请注意,您需要确保将authc应用于login.jsp,以便登录正常。

对不起,我在shiro.ini中犯了一个错误。我写了[url]而不是[url]。。。
再次抱歉,谢谢你的帮助

谢谢你的回复!我检查了是否使用“Shiro.ini”或“Shiro.ini”名称并不重要,这两个名称都可以使用。您能告诉我如何将authc应用于login.jsp吗?谢谢我将authc应用于login.jsp,但没有成功。。。我如何调试shiro?我添加了log4j.properties,但我看不到更多的日志。你说的“两者都在工作”是什么意思?。如果它位于resources目录中,则表示它是从类路径加载的。Java的类路径资源访问区分大小写。您可以尝试的另一件事是在web.xml中显式指定“shiroConfigLocations”。shiroConfigLocation类路径:Shiro.ini
    <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>
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