• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

스프링부트3.1 / 시큐리티6.1 관련하여 문의드립니다.

23.09.22 08:12 작성 23.09.22 18:29 수정 조회수 331

0

http.authorizeRequests()
.requestMatchers(new AntPathRequestMatcher("/")).permitAll() // 기본 경로는 로그인을 안하고도 볼 수 있어야함
.requestMatchers(new AntPathRequestMatcher("/mypage")).hasRole("USER") //유저 권한이 있는 사람만 접근 가능
.requestMatchers(new AntPathRequestMatcher("/messages")).hasRole("MANAGER")
.requestMatchers(new AntPathRequestMatcher("/config")).hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin();

return http.build();

@Bean

static final public InMemoryUserDetailsManager kk() { //DB연동을 안할 경우, 테스트 용으로 하는 것이다.

UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("1111")
.roles("USER")
.build();
UserDetails admin = User.withDefaultPasswordEncoder()
.username("admin")
.password("1111")
//.roles("ADMIN","USER")
.roles("ADMIN")
.build();
UserDetails manager = User.withDefaultPasswordEncoder()
.username("manager")
.password("1111")
.roles("MANAGER")
.build();

return new InMemoryUserDetailsManager(user, admin, manager);

// 아래는 컨트롤러 입니다.
@GetMapping("/")
public String getInts() {
System.out.println("path: / /n");
return "index";
}
	
@GetMapping("/mypage")
public String getInt23() {
System.out.println("path: /mypage /n");
return "index";
}
	
@GetMapping("/config")
public String getInt45() {
System.out.println("path: /config /n");
return "index";
}

 

안녕하세요 해당 config파일 설정에 의하여 프로젝트는 문제 없이 잘 돌아가고는 있습니다.

하지만, 초기 경로 "/" 으로 갈때에는 모두 허용이라는 permitAll()이 작동하기 전에 무조건 시큐리티 내장 "/login" 페이지로 이동 후, 아이디/비밀번호 입력시 "/" 경로를 타게 됩니다.

 

/login을 거치지 않도록 하기 위한 방법이 있을까요?

 

https://drive.google.com/file/d/1DljHlHOwmlCuiFrCh5NMB5TfYhMh23Bj/view?usp=sharing

해당 링크는 크롬 브라우저에서 페이지 테스트한 영상입니다!!

 

답변 3

·

답변을 작성해보세요.

0

literate_t님의 프로필

literate_t

2024.02.24

http.authorizeHttpRequests(registry -> registry
.requestMatchers("/").permitAll()
.anyRequest().authenticated());

return http.build();

0

버전이 최신버전이군요

테스트를 위해 전체 소스 공유 부탁드립니다

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.09.24

안녕하세요, 인프런 AI 인턴이에요.
질문 내용을 확인해보니, 스프링 부트와 시큐리티 관련한 내용인 것 같아요. 어떤 도움이 필요하신가요?

김상욱님의 프로필

김상욱

질문자

2023.09.25

permitAll()에 대한 경로가 허용되지 않고 있습니다