关键词:
【中文标题】Spring 安全性和自定义 AuthenticationFilter 与 Spring boot【英文标题】:Spring security and custom AuthenticationFilter with Spring boot 【发布时间】:2014-10-23 11:08:59 【问题描述】:我有自定义身份验证过滤器,它创建 PreAuthenticatedAuthenticationToken
并将其存储在安全上下文中。这一切都很好。这是配置:
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
@Autowired
private SsoAuthenticationProvider authenticationProvider;
@Autowired
private SsoAuthenticationFilter ssoAuthenticationFilter;
@Override
protected void configure(HttpSecurity http) throws Exception
http.addFilterAfter(ssoAuthenticationFilter, SecurityContextPersistenceFilter.class);
现在我的ssoAuthenticationFilter
是FilterChainProxy
的一部分,在正确的位置。平滑。
但由于 ssoAuthenticationFilter
是 Filter
,它会被 Boot 拾取并作为过滤器包含在内。所以我的过滤器链看起来像:
Filter
)
filterChainProxy(弹簧自动配置)
...
SecurityContextPersistenceFilter
ssoAuthenticationFilter(包含在http.addFilterAfter(...)
中)
...
其他一些过滤器
显然,我想在此处摆脱ssoAuthenticationFilter
的自动注册(列出的第一个)。
非常感谢任何提示。
【问题讨论】:
【参考方案1】:2 个选择:
添加一个 FilterRegistrationBean
@Bean
并将您的过滤器 bean 作为其目标过滤器并将其标记为 enabled=false
不要为您的过滤器创建 @Bean
定义(通常我会这样做,但 YMMV 因为您可能依赖自动装配或其他东西来使其工作)
【讨论】:
是否有计划将 Spring Security 过滤器配置与 Spring Boot 方式融合?我希望能够设置我的 servlet 过滤器的顺序,包括能够在安全过滤器之前放置一个,而不必弄乱HttpSecurity
不要以为我理解那个(而且它似乎没有为答案添加任何内容)。无论如何,您不能将安全过滤器作为有序 bean,因为在一个上下文中可以有多个过滤器链。具有 3 个字段身份验证和自定义登录表单的 Spring Boot 安全性
】具有3个字段身份验证和自定义登录表单的SpringBoot安全性【英文标题】:Springbootsecuritywith3fieldsauthenticationandcustomloginform【发布时间】:2015-08-2005:26:36【问题描述】:我正在使用SpringBoot,我需要使用3个字段身份验证过程用户名... 查看详情
Spring、Jackson 和自定义(例如 CustomDeserializer)
】Spring、Jackson和自定义(例如CustomDeserializer)【英文标题】:Spring,JacksonandCustomization(e.g.CustomDeserializer)【发布时间】:2011-04-0505:06:32【问题描述】:由于对Spring还有些陌生,我遇到了一个problem,这使得我有必要为Jackson实现一个... 查看详情
Spring Security 和自定义 ws 身份验证
】SpringSecurity和自定义ws身份验证【英文标题】:SpringSecurityandcustomwsauthentication【发布时间】:2016-09-0500:10:27【问题描述】:我们刚刚在一个新项目中使用了SpringBoot和SpringSecurity。问题是,我们公司使用CXF和自定义实施的SAML身份... 查看详情
spring boot spring security 基于自定义令牌的身份验证和自定义授权
】springbootspringsecurity基于自定义令牌的身份验证和自定义授权【英文标题】:springbootspringsecuritycustomtokenbasedauthenticationandcustomauthorization【发布时间】:2016-06-0915:38:11【问题描述】:大家好,我正在开发应用程序,在我的应用程... 查看详情
spring:向spring安全用户添加自定义用户详细信息
我目前正在开发一个SpringMVC应用程序,我需要在登录时向我的SpringSecurity登录用户添加一个自定义字段(我插入用户名,密码,自定义值)。当用户登录时(例如,通过pricipal.getValue),该值必须在任何地方都可用。我阅读了很... 查看详情
Spring Boot:HATEOAS 和自定义 JacksonObjectMapper
】SpringBoot:HATEOAS和自定义JacksonObjectMapper【英文标题】:SpringBoot:HATEOASandcustomJacksonObjectMapper【发布时间】:2020-06-2119:16:07【问题描述】:将HATEOAS的依赖项添加到Maven后,SpringBoot无法启动:添加依赖:<dependency><groupId>org.... 查看详情
Spring Security 和自定义外部身份验证
】SpringSecurity和自定义外部身份验证【英文标题】:SpringSecurityandCustomExternalAuthentication【发布时间】:2013-02-1815:00:11【问题描述】:我有这样的任务-将我的Web应用程序与外部单点登录服务集成。它是基于设置特定cookie并重定向回... 查看详情
springsecurity实现登录和自定义权限认证(代码片段)
...制编写大量重复代码的工作。 SpringSecurity对Web安全性的支持大量地依赖于Servlet过滤器。这些过滤器拦截进入请求,并且在应用程序处理该请求之前进行某些安全处理。SpringSecurity提供有若干个过滤器,它们能... 查看详情
带有 LDAP 和自定义 UserDetailsContextMapper 的 Spring Security
】带有LDAP和自定义UserDetailsContextMapper的SpringSecurity【英文标题】:SpringSecuritywithLDAPandcustomUserDetailsContextMapper【发布时间】:2011-07-0821:18:38【问题描述】:我正在尝试使SpringSecurity3.05与修改后的UserDetailsContextMapper一起使用,以便... 查看详情
带有 BasicAuth 和自定义 WebSecurityConfigurerAdapter 的 Spring 测试控制器
】带有BasicAuth和自定义WebSecurityConfigurerAdapter的Spring测试控制器【英文标题】:SpringtestingcontrollerswithBasicAuthonandcustomWebSecurityConfigurerAdapter【发布时间】:2017-05-2605:41:24【问题描述】:我正在制作一个休息api。最近,我在项目中添... 查看详情
Spring Security 自定义 UserDetailsService 和自定义 User 类
】SpringSecurity自定义UserDetailsService和自定义User类【英文标题】:SpringSecuritycustomUserDetailsServiceandcustomUserclass【发布时间】:2014-10-1213:06:06【问题描述】:我正在尝试在用户主体对象中保存其他数据。我所做的是:为我的现有... 查看详情
如何使用和自定义 MessageConversion(Spring websocket 客户端)
】如何使用和自定义MessageConversion(Springwebsocket客户端)【英文标题】:howtouseandcustomizeMessageConversion(Springwebsocketclient)【发布时间】:2017-01-1203:52:23【问题描述】:我用spring写了一个websocket服务器和一个客户端。代码如下。向服务... 查看详情
具有 CAS 身份验证和自定义授权的 Spring Security
】具有CAS身份验证和自定义授权的SpringSecurity【英文标题】:SpringSecuritywithCASauthenticationandcustomauthorization【发布时间】:2012-10-2519:04:56【问题描述】:我是SpringSecurity和CAS的新手。我让SSO部分正常工作,但正在努力让授权部分正... 查看详情
为 Spring 会话和自定义数据使用不同的 Redis 数据库
】为Spring会话和自定义数据使用不同的Redis数据库【英文标题】:UsingdifferentRedisdatabasesforSpringsessionsandcustomdata【发布时间】:2018-08-2119:23:27【问题描述】:在我的REST控制器Spring项目中,我想将Session信息存储在Redis中,并将我的... 查看详情
spring安全登录成功期间强制Https连接
...问题描述】:我有一个springboot应用程序,其中包含spring安全性,其中添加了formLogin和自定义loginPage。每当我通过身份验证时,它就会将我发送到/app/dashboard的defau 查看详情
Google Cloud Endpoints Security (OAuth2) 和自定义用户架构
...时间】:2013-02-1603:34:21【问题描述】:我正在阅读与OAuth2安全性相关的GoogleCloudEndpoints文档。我认为这种安全措施是针对Google帐户的。是否支持使用自定义用户架构进行身份验 查看详情
spring标准事件和自定义事件-观察者模式(代码片段)
Spring标准事件和自定义事件-观察者模式spring事件系统事件自定义事件声明事件发布事件监听事件实现`ApplicationListener`接口`@EventListener`注解。异步消息监听:顺序监听:通用消息声明通用消息事件监听通用消息事件spr... 查看详情
spring标准事件和自定义事件-观察者模式(代码片段)
Spring标准事件和自定义事件-观察者模式spring事件系统事件自定义事件声明事件发布事件监听事件实现`ApplicationListener`接口`@EventListener`注解。异步消息监听:顺序监听:通用消息声明通用消息事件监听通用消息事件spr... 查看详情