2013-01-10 77 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