日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

details在Java中_Spring安全性在Java配置中使用两个自定义UserDetailsS​​ervices

發布時間:2025/3/15 java 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 details在Java中_Spring安全性在Java配置中使用两个自定义UserDetailsS​​ervices 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖將XML中的實際安全配置傳遞給Java,但我不知道為什么在兩個過濾器中有兩個UserdetailsService,過濾器總是使用相同的UserdetailsService。

XML配置:

auto-config="false">

auto-config="false">

auto-config="false">

Java配置:

@EnableWebSecurity

public class SecurityConfig {

@Autowired

private CustomUserAppDetailsService customUserAppDetailsService;

@Autowired

private CustomRefreshTokenAppDetailsService customRefreshTokenAppDetailsService;

@Autowired

private CustomAccessTokenAppDetailsService customAccessTokenAppDetailsService;

@Bean

public TokenAuthenticationEntryPoint tokenAuthenticationEntryPoint(){

return new TokenAuthenticationEntryPoint();

}

@Configuration

@Order(1)

public class RefreshTokenSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Bean

public AuthenticationManager refresTokenAuthenticationManager() throws Exception {

return super.authenticationManagerBean();

}

@Bean

public RefreshTokenAuthenticationFilter refreshTokenAuthenticationFilter(){

return new RefreshTokenAuthenticationFilter();

}

@Override

protected void configure(HttpSecurity http) throws Exception {

DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider ();

authenticationProvider.setUserDetailsService(customRefreshTokenAppDetailsService);

http

.csrf().disable()

.antMatcher("/v1/Login/refresh/**")

.userDetailsService(customRefreshTokenAppDetailsService)

.sessionManagement()

.sessionCreationPolicy(SessionCreationPolicy.STATELESS)

.and()

.exceptionHandling()

.authenticationEntryPoint(tokenAuthenticationEntryPoint())

.and()

.authorizeRequests()

.antMatchers("/v1/Login/refresh/**").access("hasRole('ROLE_USER')")

.and()

.requiresChannel()

.antMatchers("/v1/Login/refresh/**").requiresSecure()

.and()

.addFilterBefore(refreshTokenAuthenticationFilter(), BasicAuthenticationFilter.class);

}

}

@Configuration

@Order(2)

public class LoginSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override

protected void configure(HttpSecurity http) throws Exception {

DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider ();

authenticationProvider.setUserDetailsService(customUserAppDetailsService);

authenticationProvider.setPasswordEncoder(new Md5PasswordEncoder());

http

.csrf().disable()

.antMatcher("/v1/Login/**")

.authenticationProvider(authenticationProvider)

.sessionManagement()

.sessionCreationPolicy(SessionCreationPolicy.STATELESS)

.and()

.authorizeRequests().antMatchers("/v1/Login/**").access("hasRole('ROLE_USER')")

.and()

.requiresChannel().antMatchers("/v1/Login/**").requiresSecure()

.and()

.httpBasic();

}

}

@Configuration

@Order(3)

public class UsuarioSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Bean

public TokenAuthenticationFilter tokenAuthenticationEmpresaFilter() throws Exception {

TokenAuthenticationFilter tokenAuthenticationFilter = new TokenAuthenticationFilter();

tokenAuthenticationFilter.setAuthenticationManager(super.authenticationManager());

return tokenAuthenticationFilter;

}

@Override

protected void configure(HttpSecurity http) throws Exception {

DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider ();

authenticationProvider.setUserDetailsService(customAccessTokenAppDetailsService);

http

.csrf().disable()

.antMatcher("/v1/UsuarioEmpresa/**")

.authenticationProvider(authenticationProvider)

.userDetailsService(customAccessTokenAppDetailsService)

.sessionManagement()

.sessionCreationPolicy(SessionCreationPolicy.STATELESS)

.and()

.exceptionHandling()

.authenticationEntryPoint(tokenAuthenticationEntryPoint())

.and()

.authorizeRequests()

.antMatchers("/v1/UsuarioEmpresa/**").access("hasRole('ROLE_USER')")

.and()

.requiresChannel()

.antMatchers("/v1/UsuarioEmpresa/").requiresSecure()

.antMatchers("/v1/UsuarioEmpresa/**").requiresSecure()

.and()

.addFilterBefore(tokenAuthenticationEmpresaFilter(), BasicAuthenticationFilter.class);

}

}

}出于某種原因,http配置(順序1和3)均使用customRefreshTokenAppDetailsService??偸鞘褂玫谝粋€http的UserDetailsService。

總結

以上是生活随笔為你收集整理的details在Java中_Spring安全性在Java配置中使用两个自定义UserDetailsS​​ervices的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。