Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- HttpServletResponse
- 서버 배포
- 두수의 합 자바
- Chat GPT
- 값 타입
- github 복제
- JDBC
- Git
- MySQL
- 넘파이
- 비밀번호 재설정 API
- JPA
- swap 메모리
- MVC
- 페이징 정렬
- JPQL
- 저장소 복제
- Json 객체
- jar빌드
- 우분투
- Servlet
- 스프링 이메일 전송
- 파이썬
- 저장소 이전
- git 충돌 해결
- 프로그래머스
- api 개발
- 자바
- springboot
- 스프링부트 OpenAI API
Archives
- Today
- Total
현의 개발 블로그
Spring Security 401 unauthorized error 본문
비밀번호 암호화를 위해 Spring Security를 작성
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder getPasswordEncoder(){
return new BCryptPasswordEncoder();
}
}
문제) postman에서 요청을 할 때 401 unauthorized error 뜸
401 unauthorized error
클라이언트가 인증되지 않았기 때문에 요청을 정상적으로 처리할 수 없다.
해결)
SpringSecurity 설정 시 모든 요청마다 필터가 돌면서 권한을 확인한다.
아래 코드를 작성하여 URI 접근 권한을 모두 허용해줘야 한다.
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@Override
protected void configure(HttpSecurity http) throws Exception{
http.csrf().disable();
http.authorizeRequests()
.anyRequest().permitAll();
}
}
http.csrf().disable();을 해주지 않으면 403 에러가 뜬다.
해당 기능은 CSRF 방지 기능을 비활성화해준다.
CSRF(Cross-Site Request Forgery)란 다른 오리진을 가진 사이트에서 form 요청을 보내는 것이다.
예를 들어, 공격자가 로그인한 사용자의 권한을 사용해 다른 페이지에서도 패스워드를 변경할 수 있다.
http.csrf()를 비활성화한다면, JWT 등의 토큰을 사용하여 보안 취약점을 개선해야 한다.
'대외활동 > 오류' 카테고리의 다른 글
EC2 Remote host identification has changed 에러 (0) | 2023.07.16 |
---|
Comments