2013-01-10 74 views
0

可能重複:
Spring Security Authentication is not working as expected in my configurationJSF和Spring securtiy集成

我試圖整合JSF和春季安全我花了差不多一天,但沒有結果

開發的應用程序使用JSF,Spring MVC和Primfaces。我幾乎完成了我的要求,最後我計劃整合春季安全,但是我不能,而且我在網上做了足夠的搜索。我覺得這可能是相關框架中的錯誤。

如果有人遇到同樣的問題,請發佈解決方案。我發表我的做法在這裏

第1步: 創建的Login.jsp(已定製的登錄頁面) 第2步: 添加下面的代碼在我的web.xml

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
<dispatcher>REQUEST</dispatcher> 
</filter-mapping> 

第3步:

創建Springsecurity.xml

<sec:global-method-security 
    secured-annotations="enabled" /> 
<sec:http auto-config="true" use-expressions="true" 
    once-per-request="false"> 
    <sec:intercept-url pattern="pages/secured/**" 
     access="ROLE_USER" /> 
    <sec:form-login login-page="/login.jsp" 
     default-target-url="/pages/secured/products.xhtml" 
     authentication-failure-url="/login.html?login_error=1" /> 
    <sec:logout logout-url="/logout" logout-success-url="/login.jsp" /> 
</sec:http> 

<sec:authentication-manager alias="authenticationManager"> 
    <sec:authentication-provider> 
     <sec:user-service> 
      <sec:user name="vijay" authorities="ROLE_USER" password="vijay"/> 
     </sec:user-service> 
    </sec:authentication-provider> 
</sec:authentication-manager> 

執行應用程序並獲得login.jsp作爲第一頁,因爲我定義在web.xml中。在登錄身份驗證轉發到Products.xhtml,但我甚至可以訪問其餘的頁面,這些都是在安全的文件夾下出來登錄。

請建議一個更好的方法或其他選擇。

+0

對於您的訪問屬性有你的嘗試。

回答

0

對於您的訪問屬性有你的嘗試。你的第一個斜線在模式中缺失。

+0

非常感謝!現在,如果我訪問受保護的頁面(在修改 VijayM

+0

不確定爲什麼它會進入該頁面,但是您可以在form-login上將屬性always-use-default-target =「true」設置爲默認值。 –

+0

是的,我嘗試過,但仍然發生如此。一路上你的答案真的很有幫助 – VijayM