为了账号安全,请及时绑定邮箱和手机立即绑定

JSF/Spring Security - 添加额外的登录字段不会调用自定义过滤器

JSF/Spring Security - 添加额外的登录字段不会调用自定义过滤器

qq_花开花谢_0 2021-10-06 13:00:41
我有一个 Web 应用程序,我需要使用三个字段登录:用户、密码和部门。当我尝试运行它时,登录有效,但未调用自定义过滤器,因此没有部门。我一直在尝试添加自定义用户名和密码过滤器,传递一个我可以稍后解析的字符串。我没有取得任何成功,这让我发疯。SecurityConfig 扩展了 WebSecurityConfigurerAdapter@Overrideprotected void configure(HttpSecurity http) throws Exception {    http        .addFilterBefore(authenticationFilter(),                 UsernamePasswordAuthenticationFilter.class);    // Authentication control    http        .authorizeRequests()        .antMatchers("/login.xhtml").permitAll() // All everyone to see login page        .antMatchers("/javax.faces.resource/**").permitAll() // All everyone to see resources        .antMatchers("/resources/**").permitAll() // All everyone to see resources        .anyRequest().authenticated(); // Ensure any request to application is authenticated    // Login control    http        .formLogin()            .loginPage("/login.xhtml")            .usernameParameter("userInput")            .passwordParameter("passwordInput")            .defaultSuccessUrl("/home.xhtml", true)            .failureUrl("/login.xhtml?error=true");    // logout    http        .logout()            .logoutUrl("/logout")            .invalidateHttpSession(true)            .logoutSuccessUrl("/login.xhtml");    // not needed as JSF 2.2 is implicitly protected against CSRF    http        .csrf().disable();} public CustomAuthenticationFilter authenticationFilter() throws Exception {    CustomAuthenticationFilter filter = new CustomAuthenticationFilter();    filter.setAuthenticationManager(authenticationManagerBean());    filter.setAuthenticationFailureHandler(failureHandler());    return filter;}public SimpleUrlAuthenticationFailureHandler failureHandler() {    return new SimpleUrlAuthenticationFailureHandler("/login?error=true");}@Autowiredpublic void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {    auth.authenticationProvider(authProvider());}   
查看完整描述

2 回答

?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

对于您,CustomAuthenticationFilter您没有设置与 Spring 的默认值usernamepassword.


查看完整回答
反对 回复 2021-10-06
  • 2 回答
  • 0 关注
  • 228 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信