• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

login 구현할때

20.04.15 23:32 작성 조회수 2.02k

2

import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception{
        http.authorizeRequests()
                .mvcMatchers("/", "/login", "/sign-up",  "/check-email-token"
                        , "/email-login", "/check-email-login", "/login-link").permitAll()
                .mvcMatchers(HttpMethod.GET, "/profile/*").permitAll()
                .anyRequest().authenticated();

        http.formLogin()
                .loginPage("/login").permitAll();

        http.logout()
                .logoutSuccessUrl("/");
    }
...

강의 보면서 진행했을 땐 잘 작동했는데

이후 구현하면서 에러가 발생했습니다.

로그인 수행을 하면 로그인은 되지만 /error로 redirect 되어 화면에는 아래와 같은 에러가 뜹니다.

{"timestamp":"2020-04-15T14:28:16.449+0000","status":999,"error":"None","message":"No message available"}


spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration

구글링하면서 위 프로퍼티를 추가하여 해결했지만 /error을 요청하지 않았는데 왜 이런 현상이 발생하는지 이해가 되지 않습니다..

답변 3

·

답변을 작성해보세요.

10

LUA님의 프로필

LUA

2020.08.29

저도 같은문제로 당황하고 있엇는데 정유성님이 이미지 때문이라고 하셔서 관련내용 찾아보다보니

로그인할 때 정적리소스를 찾지못하면 에러로 핸들링하는거 같아요 시큐리티 config 에서 웹 이그노잉에

.antMatchers("/favicon.ico", "/resources/**", "/error")

를 추가하니까 잘 되는거같습니다!

https://stackoverflow.com/questions/61029340/spring-security-redirects-to-page-with-status-code-999/61029341

1

foot님의 프로필

foot

2020.04.27

같은 문제였는데 fragments.html에 <img>에 작성한 이미지파일이 실제로 없어서 에러가 나네요

그런데 그냥 메인페이지 접속할때나 다른경우엔 오류가 안나는데 로그인으로 리다이렉트 하는 경우에만 오류가 나는 이유가 있나요?

1

스프링 부트 기본 설정에 따라 요청 처리시 에러가 발생하면 해당 에러 핸드러로 가게 되어있습니다. 어떤 요청이 제대로 처리가 안되는지 웹 브라우저에서 디버거를 열어서 요청을 확인해 보세요. 첫 페이지로 요청을 보내더라도 실제로는 한개만 보내지느게 아니라 이미지 리소스에 대한 요청도 보내지고 다양한 요청이 보내지는데 그 중에 어떤 요청이 실패하는지 찾아야 합니다.