2

我想在我的登录页面中传递额外的参数。我的应用程序上下文如下所示。例如我想location在登录表单中添加参数。

<context:annotation-config />
<context:component-scan base-package="com.myetest.app" />

<sec:http entry-point-ref="apiAuthenticationEntryPoint" create-session="always">
    <sec:form-login login-processing-url="/login" 
        username-parameter="username" 
        password-parameter="password" 
        authentication-failure-handler-ref="apiAuthenticationFailureHandler"
        authentication-success-handler-ref="apiLoginSuccessHandler" />
    <sec:logout logout-url="/logout" success-handler-ref="apiLogoutSuccessHandler"/>

    <sec:intercept-url pattern="/receipt/**" access="ROLE_ANONYMOUS"/>
    <sec:intercept-url pattern="/internal/**" access="ROLE_ANONYMOUS"/>
    <sec:intercept-url pattern="/system/**" access="ROLE_ANONYMOUS"/>
    <sec:intercept-url pattern="/**" access="ROLE_SELLER"/>

    <sec:custom-filter ref="apiPreAuthFilter" before="PRE_AUTH_FILTER"/>
    <sec:custom-filter ref="apiFirstFilter" before="LAST"/>
</sec:http>

<sec:authentication-manager alias="authenticationManager">
    <sec:authentication-provider ref="apiAuthenticationProvider"/>
</sec:authentication-manager>

<bean id="apiAuthenticationProvider" class="com.myetest.app.security.ApiAuthenticationProvider" />
<bean id="apiAuthenticationEntryPoint" class="com.myetest.app.security.ApiAuthenticationEntryPoint"/>
<bean id="apiLoginSuccessHandler" class="com.myetest.app.security.ApiLoginSuccessHandler"/>
<bean id="apiLogoutSuccessHandler" class="com.myetest.app.security.ApiLogoutSuccessHandler"/>
<bean id="apiAuthenticationFailureHandler" class="com.myetest.app.security.ApiAuthenticationFailureHandler"/>
<bean id="apiPreAuthFilter" class="com.myetest.app.security.ApiPreAuthenticationFilter" />

<bean id="apiFirstFilter" class="com.myetest.app.security.ApiFirstFilter"/> 

AuthenticationProvider的是这样的。

public class ApiAuthenticationProvider implements AuthenticationProvider {

}
4

1 回答 1

2

您是否查看过可能的解决方案(第 1 节)并在此处进行了一些解释。解决方案基于UsernamePasswordAuthenticationFilter使用情况。简而言之,您可以覆盖可以从正文中UsernamePasswordAuthenticationFilter提取的位置并执行一些自定义内容。或者您可以添加自定义 MVC 控制器,该控制器将接受您的表单数据并使用您的 custome手动调用。希望这可以帮助。locationHttpServletRequestUsernamePasswordAuthenticationFilter.attemptAuthenticationAuthenticationManagerAuthenticationProvider

于 2013-11-14T14:16:19.670 回答