【问题标题】:Spring Security custom filter chain proxy using java config for mvc applicationSpring Security 自定义过滤器链代理使用 java config 用于 mvc 应用程序
【发布时间】:2015-08-10 11:41:20
【问题描述】:

我们正在尝试在 Spring Boot 应用程序中使用 Spring Security,并希望使用 java config 来配置 Spring Security。 最重要的是,我们想使用我们自己的过滤器来修改登录前后的一些行为。 类似于http://sleeplessinslc.blogspot.in/2012/02/spring-security-stateless-cookie-based.html 的东西

有谁知道如何创建 SecurityConfig.java,我们可以在其中自定义过滤器序列并添加我们自己的过滤器。

试过http://shazsterblog.blogspot.com/2014/07/spring-security-custom-filterchainproxy.html,但没有让它指向我的登录页面。

【问题讨论】:

  • 您是否使用 spring boot 来进行休息服务?

标签: spring security spring-boot


【解决方案1】:

您可以将 CustomUsernamePasswordAuthenticationFilter 添加到 securityCONfig.java

public class SecurityConfig extends WebSecurityConfigurerAdapter {
 @Bean
public CustomUsernamePasswordAuthenticationFilter customUsernamePasswordAuthenticationFilter()
        throws Exception {


@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();
    http.authorizeRequests().antMatchers("/*").permitAll()
            .anyRequest().hasRole("USER").and()
            .formLogin()
            .permitAll();
    http.addFilterBefore(new CustomFilter(), LogoutFilter.class);
    //.and().anonymous().disable();
}

这是一个类似的帖子 - Spring security custom authentication filter without web.xml

这里有两个教程 - http://www.journaldev.com/2715/spring-security-in-servlet-web-application-using-dao-jdbc-in-memory-authentication

【讨论】:

  • 嗨,保罗,感谢您的回复。我想要做的基本上是创建一个无状态应用程序,根本不使用默认(持久)JSESSIONID。我想将加密令牌用作 cookie,并将其用作已登录用户的身份验证策略。我能够创建自己的 AuthSucessHandler 并在 UsernamePasswordAuthenticationFilter 之前添加了一个过滤器。我现在需要的是一种在我的自定义过滤器找到有效 cookie 时绕过身份验证的机制。真的很感激更多的见解..
猜你喜欢
  • 2016-04-21
  • 2015-02-14
  • 2015-06-17
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 2016-03-17
  • 2017-01-09
  • 2016-03-08
相关资源
最近更新 更多