私はgraphqlで春のブートプロジェクトに取り組んでいます。私はgraphql-java-toolsとgraphql-spring-boot-starterを使っています。私は、以下のjava設定ファイルで確認できるように、セキュリティとセッション管理を春のセキュリティで設定することができました。私はgraphqlを使用している春のブートで認証
"/ graphql"パスが保護されています(要求のhttpヘッダーに「基本HTTP認証」またはセッショントークン(x-auth-token)のみを送信することでアクセスできます)。任意のgraphql操作で「基本的なHTTP認証」を使用して認証すると、新しいセッションが開始され、新しいセッショントークンがヘッダーに返され、そのトークンを使用してそのセッションを続行できます。
上記の動作を維持しているグラフクエリー/突然変異に対して匿名ユーザーにアクセスする方法はありますか?
匿名アクセスを許可するためにantMatchers( "/ graphql")、authenticated()をantMatchers( "/ graphql")、permitAll()に変更した場合、私のカスタム認証プロバイダはもはや呼び出されません「基本的なhttp認証」で認証します。
ありがとうございます!ここで
は私のconfigsは以下の通りです。
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationProvider authenticationProvider;
@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) {
authenticationManagerBuilder.authenticationProvider(authenticationProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/graphql").authenticated()
.and()
.requestCache()
.requestCache(new NullRequestCache())
.and()
.httpBasic()
.and()
.headers()
.frameOptions().sameOrigin() // needed for H2 web console
.and()
.sessionManagement()
.maximumSessions(1)
.maxSessionsPreventsLogin(true)
.sessionRegistry(sessionRegistry());
}
@Bean
public SessionRegistry sessionRegistry() {
return new SessionRegistryImpl();
}
@Bean
public HttpSessionEventPublisher httpSessionEventPublisher() {
return new HttpSessionEventPublisher();
}
}
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 180)
public class HttpSessionConfig {
@Bean
public HttpSessionStrategy httpSessionStrategy() {
return new HeaderHttpSessionStrategy();
}
}