Reactjsシングルページアプリケーション内のどのルートにも認証されていないユーザーがアクセスするのを制限しようとしています。我々は、UI側のルーティングを処理するためにHashRouterを使用しているので、我々のURLはhttp://localhost/app/#/Home、http://localhost/app/#/Loginのようになります。JWTでSpring Security OAuth2を使用しています。Spring Securityを使用して特定のReact Hashルートにアクセスするにはどうすればよいですか?
/app /#/ Login、/ app /#/ Homeなどとは異なり、すべてのリクエストは/ app /として入力されます。クライアントは正しいルートをレンダリングしますが、アプリケーションを保護しようとすると問題が発生します。ログインルートへのアクセスを許可するには、すべてを開く、Spring Securityの/ app /へのアクセスを許可する必要があります。
Spring SecurityでReact Hash Routeを保護することは可能ですか、それともルータのUI側でこれを処理する必要がありますか?他のすべての要求のためのすべての
@EnableWebSecurity(debug = true)
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
public class LoginConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/app/**")
.httpBasic().disable()
.formLogin().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers(HttpMethod.GET, "/favicon.ico").permitAll()
.antMatchers("/app/**").permitAll()
.anyRequest().authenticated()
;
}
}
デフォルト設定へ
ログインConfigが
@EnableWebSecurity(debug = true)
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
public class LoginConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/app/#/login")
.httpBasic().disable()
.formLogin().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers(HttpMethod.GET, "/favicon.ico").permitAll()
.antMatchers("/app/#/login").permitAll()
.anyRequest().authenticated()
;
}
}
ログインコンフィグ補助金のアクセス
@EnableWebSecurity(debug = true)
@Configuration
@Order(2)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http
.httpBasic().disable()
.formLogin().disable()
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers(HttpMethod.GET, "/**/favicon.ico").permitAll()
.antMatchers(HttpMethod.POST, "/oa/oauth/token").permitAll()
.anyRequest().authenticated()
;
}
}
ありがとうございます!
ありがとう、それは私が周りに来ていた、ちょうど私が何かを逃していないことを確認したいと思った。 – Steve