在AuthenticationSuccessHandler实现中访问Spring Security的FormLoginBeanDefinitionParser属性

时间:2017-10-01 17:04:55

标签: authentication spring-security servlet-filters

我想在AuthenticationSuccessHandler实现中访问form-login标签的配置属性。

示例情况如下所示:

@Autowired
private FormLoginBeanDefinitionConfigurationProperties properties;

public class CustomAuthenticationSuccessHandler extends SimpleUrlAuthenticationFailureHandler {
   String usernameParameterName = properties.getUsernameParameter();
   String passwordParameterName = properties.getPasswordParameter();
}

当弹簧安全配置配置如下:

<security:form-login
            login-page="/login.html"
            username-parameter="the_username_parameter"
            password-parameter="the_password-parameter"
            login-processing-url="/dologin"
            authentication-success-handler-ref="customAuthenticationSuccessHandler"
            authentication-failure-handler-ref="customAuthenticationFailureHandler"

    />

我试图在身份验证处理程序中注入UsernamePasswordAuthenticationFilter:

@Autowired
private UsernamePassworAuthenticationFilter formAuthenticationFilter;

public class CustomAuthenticationSuccessHandler extends SimpleUrlAuthenticationFailureHandler {
    String usernameParameterName = formAuthenticationFilter.getUsernameParameter();
    String passwordParameterName = formAuthenticationFilter.getPasswordParameter();     
}

但是这样的东西似乎不可行,因为它通过AuthenticationConfigBuilder和FormLoginConfigurer进行反射配置,并尝试在应用程序上下文中显式定义XML,将生成另一个与servlet-context配置无关的UsernamePasswordAuthenticationFilter已经确定。

欢迎任何建议和想法。

0 个答案:

没有答案