티스토리 뷰
jsp파일에서 post요청으로 회원가입을 처리할려하는데 요청이 가지 않는다 왜그런걸까?
서버에서 만약회원가입 페이지를보여주세요 하고 휘원가입페이지를 주게될때 태그안에 csrf라는 토큰을 심어준다
예를 들어 어떻게 들어오냐면
<form class="login__input" action="/auth/signup" method="POST">
<input type="text" name="username" placeholder="유저네임" required="required" csrf="BBQ"/>
<input type="password" name="password" placeholder="패스워드" required="required" csrf="BBQ" />
<input type="email" name="email" placeholder="이메일" required="required" csrf="BBQ"/>
<input type="text" name="name" placeholder="이름" required="required" csrf="BBQ"/>
<button>가입</button>
</form>
위와같이 태그 맨뒤에 csrf란 속성에 BBQ란 랜덤 값이 들어오게된다
(우리에겐 보이지 않지만 위처럼 설정이 되있다고 생각하자)
보낼때 csrf토큰을 심어 보내고 다시 클라이언트가 입력하고 post요청을 보내면 csrf토큰이 있는걸 확인하고 받지 않게되어 요청이 가지 않게 된다 그렇다면 csrf토큰 기능을 꺼버리면 되지않는가 바로 끄러가자
SecutifyConfig.java
package com.cos.photogramstart.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity // 해당 파일로 시큐리티를 활성화
@Configuration //loC
public class SecurifyConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
// super 삭제 - 기존 시큐리티가 가지고 있는 기능이 다 비활성화됨.
http.csrf().disable();
// csrf를 사용하지 않겠다 설정
http.authorizeRequests()
.antMatchers("/","/user/**","/image/**","/subscribe/**","/comment/**").authenticated()
.anyRequest().permitAll()
.and()
.formLogin()
.loginPage("/auth/signin")
.defaultSuccessUrl("/");
}
}
위코드처럼 http.csrf().disable(); 해주면 csrf가 비활성화되며 post요청이 잘오는것을 확인할 수 있다.
'Spring Boot' 카테고리의 다른 글
SpringBoot + MariaDB 2 로그인 (세션에 저장된 유저정보찾기) (0) | 2023.06.08 |
---|---|
Spring Boot + MariaDB 1 회원가입구현하기(제약조건, 암호화,제약조건, 전후처리, scrpit) (0) | 2023.06.07 |
Spring Boot Security Config 로그인확인후 페이지이동시키기 (0) | 2023.06.07 |
HTML 응답(txt, mustache, jsp) yml jsp설정(ViewResolver) (0) | 2023.06.07 |
http header, context-type(application/x-www-form-urlencoded, text/plain, application/json) [@RequestBody 추가설명] (0) | 2023.06.07 |