2014-05-02 65 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