如何使用Spring Security实现登录页面,以便它与Spring Web流程一起使用?

sim*_*mon 18 java spring-mvc spring-security spring-webflow

我有一个使用Spring 2.5.6和Spring Security 2.0.4的Web应用程序.我已经实现了一个工作登录页面,它根据Web服务对用户进行身份验证.通过定义自定义验证管理器来完成身份验证,如下所示:


<beans:bean id="customizedFormLoginFilter"
    class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter">
    <custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />
    <beans:property name="defaultTargetUrl" value="/index.do" />
    <beans:property name="authenticationFailureUrl" value="/login.do?error=true" />
    <beans:property name="authenticationManager" ref="customAuthenticationManager" />
    <beans:property name="allowSessionCreation" value="true" />
</beans:bean>

<beans:bean id="customAuthenticationManager"
    class="com.sevenp.mobile.samplemgmt.web.security.CustomAuthenticationManager">
    <beans:property name="authenticateUrlWs" value="${WS_ENDPOINT_ADDRESS}" />
</beans:bean>
Run Code Online (Sandbox Code Playgroud)

身份验证管理器类:


public class CustomAuthenticationManager implements AuthenticationManager, ApplicationContextAware {

    @Transactional
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {

                //authentication logic

        return new UsernamePasswordAuthenticationToken(principal, authentication.getCredentials(),
                grantedAuthorityArray);
    }
Run Code Online (Sandbox Code Playgroud)

登录jsp的基本部分如下所示:


<c:url value="/j_spring_security_check" var="formUrlSecurityCheck"/>
<form method="post" action="${formUrlSecurityCheck}">
    <div id="errorArea" class="errorBox"> 
       <c:if test="${not empty param.error}">
          ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
      </c:if>
  </div>
    <label for="loginName">
        Username:           
        <input style="width:125px;" tabindex="1" id="login" name="j_username" />
    </label>

    <label for="password">
        Password:           
        <input style="width:125px;" tabindex="2" id="password" name="j_password" type="password" />
    </label>
    <input type="submit" tabindex="3" name="login" class="formButton" value="Login" />
</form>
Run Code Online (Sandbox Code Playgroud)

现在的问题是应用程序应该使用Spring Web Flow.在将应用程序配置为使用Spring Web Flow之后,登录不再起作用 - 对"/ j_spring_security_check"的表单操作会导致空白页面没有错误消息.调整现有登录过程以使其与Spring Web Flow配合使用的最佳方法是什么?

编辑:没有错误消息,只显示空白页.它现在有效 - 问题是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>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

由于我无法取消赏金,虽然问题已经解决,但赏金奖励最有见地的答案或链接,这将有助于其他人配置Spring Security和Web Flow一起工作.

fol*_*one 0

您是否按照 Spring Web Flow参考指南“保护流程”章节将您的应用程序配置为使用 Spring Web Flow ?