Karlie_dev
{SourceCode}
Karlie_dev
전체 방문자
오늘
어제
  • 분류 전체보기
    • 컴퓨터공학
    • JAVA
    • CSS
    • 자바스크립트
    • 파이썬
    • 스프링
    • DB
      • SQL
      • MySQL
      • Oracle
      • MongoDB
      • MariaDB
    • 형상관리
    • IDE
      • VS Code
      • Eclipse
    • 알고리즘
    • Server
    • AWS
    • 개발소리
    • Docker&Kubernetes
    • Cloud (클라우드)

블로그 메뉴

  • 홈

공지사항

인기 글

태그

  • AWS
  • mariadb
  • 자바스크립트
  • 도커
  • 파이썬
  • Spring
  • 쿠버네티스
  • nodejs
  • 오라클
  • MongoDB
  • k8s
  • kubernetes
  • MySQL
  • JavaScript
  • oracle
  • 스프링
  • Minikube
  • 마리아디비
  • docker
  • 스프링부트

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Karlie_dev

{SourceCode}

Spring Security 사용 중, POST 요청 시 403 뜨는 경우
스프링

Spring Security 사용 중, POST 요청 시 403 뜨는 경우

2020. 8. 2. 02:48

처음으로 스프링 시큐리티를 적용하고, 빠르게 개발 중에 이상하게 로그인 요청만 하면 에러가 떴다. 콘솔은 감감무소식이고, 에러 페이지를 커스텀하여 해당 페이지에는 '에러페이지' 단 다섯 글자만 띄워서 에러를 찾을 수 없었다. 잠시 커스텀 에러 페이지 컨트롤러를 없애고 다시 에러를 확인했다.

Forbidden, 403 에러. 권한 문제로 발생하는 오류로, 스프링 시큐리티는 csrf 토큰이 필요한데 이가 없어서 발생한다.

설정 클래스 내에 httpSecurity.csrf().disable();를 입력해준다. 전체적인 코드는 아래와 같고, 중요한 것은 HttpSecurity 를 인자로 받는 configure 메소드를 확인하면 된다.

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(HttpSecurity httpSecurity)throws Exception{
        httpSecurity.csrf().disable();
    }

    @Override
    public void configure(WebSecurity webSecurity)throws Exception{
        webSecurity.ignoring().antMatchers("/css/**", "/fonts/**", "/images/**", "/js/**", "/plugins/**");
    }
}

 

저작자표시
    '스프링' 카테고리의 다른 글
    • 스프링과 스프링 부트의 차이
    • [logback] 특정 로그 출력 비활성화 하기 (logback.xml)
    • 스프링 MariaDB log4jdbc 연결 오류 해결
    • ajax 406 에러 대응
    Karlie_dev
    Karlie_dev

    티스토리툴바