2014-05-02 66 views
1
到login.xhtml

我学习Shiro一步一步用@ BalusC的article,是没有问题的,直到我把它变成基于形式的认证fifth part of the article说过。阿帕奇四郎不重定向我在JSF

我的确如文章所述,但是shiro没有将我重定向到登录页面,而是每当我运行我的web应用程序时,它总是显示index.xhtml

这是我的代码,我不知道我错过了什么。

web.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" 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"> 
<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> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> 
<context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Development</param-value> 
</context-param> 
<servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>/faces/*</url-pattern> 
</servlet-mapping> 
<session-config> 
    <session-timeout> 
     30 
    </session-timeout> 
</session-config> 
<welcome-file-list> 
    <welcome-file>faces/index.xhtml</welcome-file> 
</welcome-file-list> 
</web-app> 

shiro.ini

[main] 
authc.loginUrl = /login.xhtml 

[users] 
admin = password 

[urls] 
/login.xhtml = authc 
/app/** = authc 

应该有我重定向到login.xhtml,不应该吗?
任何想法?提前致谢。

回答

1

如果您在浏览器中使用的index.xhtml的确切网址是/index.xhtml或/faces/index.xhtml(而不是/app/index.xhtml/),那么它根本就不安全你需要添加一个额外的行。此外,login.xhtml不应该被保护:

[urls] 
/login.xhtml = anon 
/index.xhtml = authc 
/app/** = authc 

另外,如果您的网址在浏览器中输入的/,它不是固定的。

Shiro查看浏览器的URL,它不知道任何关于jsf的内容。

所以,如果它是你保护的一切目标,配置应该是:

[urls] 
/login.xhtml = anon 
/** = authc 

注意,顺序是有意义的,第一主打是它会作出反应。所以登录应该先来,然后是其他所有内容,否则你的登录页面也会被保护。

+0

我试过这个,但是当我运行web应用程序时它仍然显示'index.xhtml'。 – nosnhoj

+0

浏览器中显示的index.xhtml的实际url是/index.xhtml吗? – Wouter

+0

我发现如果我输入'http:// localhost:8080/shiroPrac1/index.xhtml'而不是'http:// localhost:8080/shiroPrac1 /',它会重定向到'http:// localhost:8080/shiroPrac1/login.xhtml',但是,有什么问题吗?它不应该显示'index.xhtml',因为我没有登录。 – nosnhoj