LoginSignup
1
0

Spring Security 6のPathRequestにおけるConsider switching to 'HttpSecurity' Lambda DSL syntaxvscode-spring-boot(JAVA_LAMBDA_DSL)について

Last updated at Posted at 2024-03-04

Spring Security 6を使っている場合、静的リソースへのアクセス許可を設定する際にPathRequest.toStaticResources().atCommonLocations()を使用すると以下のPathRequestにおいて、Consider switching to 'HttpSecurity' Lambda DSL syntaxvscode-spring-boot(JAVA_LAMBDA_DSL)というエラーが出ました。

@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

    private final WebOidcUserService userService;

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.
            authorizeHttpRequests(authorize -> authorize
                .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
                .anyRequest().authenticated()
            ).oauth2Login().userInfoEndpoint().oidcUserService(userService);
        return http.build();
    }

}

解決策

PathRequestクラスを適切にインポートする必要があります。以下のインポート文を追加することでエラーを解消できます。

```java
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;

このインポートを追加することで、Spring Securityの設定内でPathRequest.toStaticResources().atCommonLocations()メソッドが正しく認識され、静的リソースへのアクセス許可が適切に設定されます。

参考にした記事

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0