inflearn logo
강의

講義

知識共有

Spring Boot JWT Tutorial

セキュリティ設定、データ設定

2:00 에서 저처럼 버전 안 맞춰서 해서 헤매는 분들 이걸로 해보세요.

解決済みの質問

1275

terrinens

投稿した質問数 2

0

저처럼 버전 안 맞춰서 안되는 분들 이걸로 해결해보세요. 문서 참조해서 지원 중단된 방식은 제외하고 설정했습니다. 

 

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
        return httpSecurity
                .csrf(AbstractHttpConfigurer::disable)
                .authorizeHttpRequests((registry) ->
                        registry.requestMatchers("/api/hello").permitAll()
                                .anyRequest().authenticated()
                )
                .build();
    }
}

 

어노테이션에 꼭 @Configuration 이 들어가야 설정 파일로 인식해 제대로 작동합니다. 빼먹으시면 안됩니다.

spring-boot jwt

回答 3

0

silvernine

안녕하세요 🙂

Spring Boot 3.4.0 (SNAPSHOT) 버전에 맞춰 샘플 코드를 업데이트했습니다.

아래 링크에서 Java와 Kotlin 버전의 최신 샘플 코드를 확인하실 수 있으니 참고 부탁드립니다.

Javahttps://github.com/SilverNine/spring-boot-jwt-tutorial

Kotlinhttps://github.com/SilverNine/spring-boot-jwt-tutorial-kotlin

0

junseong Kim

terrinens 님 덕분에 해결했습니다. 감사합니다.

추가로 저는 spring 3.1.5 사용중인데 알려주신 코드대로 했을 때 requestMatchers()에서 Ant 패턴으로 작성하라는 컴파일 에러가 발생해서 아래와 같이 수정했습니다.

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
        return httpSecurity
                .csrf(AbstractHttpConfigurer::disable)
                .authorizeHttpRequests((registry) ->
                        registry.requestMatchers(new AntPathRequestMatcher("/api/hello")).permitAll()
                                .anyRequest().authenticated()
                )
                .build();
    }
}

 

0

kim9xd5500

@Bean

public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

여기서 public에 밑줄이 그어져있는데 이유가 뭘까요?

spring boot 3.x 버전 강의도 만들어주시면 안될까요?

0

67

1

3강 secret key 관련해서 질문있습니다

0

65

1

JwtFilter 에 TokenProvider 선언 시 final 키워드 빠진 이유

0

76

1

/api/authenticate 포스트맨 401 에러

0

223

1

Spring boot 3.x버전에서 data.sql 오류 발생할 경우

4

398

1

/api/hello 접근 시 401 나올 때 해결법

2

301

2

소스코드 전체 볼수 있을까요?

0

397

2

머이렇게 안되는게많노 ㅠ

1

757

2

스프링부트 3.x 버전 data.sql 삽입 오류 발생할 경우 해결 방법

6

1350

2

postman 결과가 다릅니다

0

354

2

body값이 비었습니다.

0

399

2

jjwt 버전을 올렸더니 jwt가 유효하지 않다고 합니다

0

3590

1

Refresh Token

0

505

1

유저 권한 설정

0

368

2

setAuthentication

0

496

1

postman에서 오류가 납니다..

0

1766

3

Spring boot 3.1.5 기준 학습 정리 파일 공유

1

1082

4

/api/hello에 접근이 안됩니다 ㅠㅠ

0

1082

2

mysql 설정로 실습시

0

873

2

유효한 JWT 토큰이 없습니다

0

667

2

8:45 spring security 3.1.5 설정 방법 (버전 안 맞춰서 안될때)

1

2278

2

JWT String argument cannot be null or empty.

0

2156

2

new User 생성자 오류 발생하는 분들...

6

501

2

requestMatchers 관련 에러 뜨시는 분들 참고하세요

6

2598

3