【问题标题】:JSF and Spring securtiy Integration [duplicate]JSF 和 Spring 安全集成 [重复]
【发布时间】:2013-01-10 20:00:08
【问题描述】:

可能重复:
Spring Security Authentication is not working as expected in my configuration

我尝试集成 JSF 和 Spring Security 我花了将近一天但没有结果

使用 JSF、Spring MVC 和 Primfaces 开发了一个应用程序。我几乎完成了我的要求,最后我计划集成弹簧安全,但我不能,我在网上做了足够的搜索。感觉可能是相关框架的bug。

如果你们中的任何人遇到相同的问题,请发布解决方案。我在这里发布我的方法

第 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>

自从我在 web.xml 中定义以来,执行了应用程序并将 login.jsp 作为第一页。在登录身份验证时,它会转发到 Products.xhtml,但我什至可以访问所有位于安全文件夹下的其余页面,而无需登录。

请提出更好的方法或其他替代方案。

【问题讨论】:

  • 对于你的访问属性有你的尝试。

标签: spring jsf spring-mvc spring-security


【解决方案1】:

对于你的访问属性有你的尝试。模式中缺少您的第一个斜线。

<sec:intercept-url pattern="/pages/secured/**"
    access="hasRole('ROLE_USER')" />

【讨论】:

  • 非常感谢!!现在,如果我访问安全页面(在修改
  • 不确定为什么会进入该页面,但您可以将表单登录上的属性 always-use-default-target="true" 设置为默认值。
  • 是的,我试过了,但仍然如此。无论如何,你的回答真的很有帮助
猜你喜欢
  • 2012-02-28
  • 2012-07-21
  • 2021-04-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-13
  • 2018-11-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多