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
- 백준9012
- KT포트포워딩
- 코딩테스트실력진단
- 스파르타코딩클럽
- 카카오코테
- 윤곽선검출
- 이것이자바다확인문제
- 운영체제
- java
- 이것이자바다
- 백준온라인저지
- 컴퓨터비전
- 백준10828
- 백준
- 백준스택
- 확인문제
- 이것이자바다9장
- 백준가운데를말해요
- 웹개발기초
- 백준평범한배낭
- 코테
- 2019카카오코테
- 딥러닝
- 냅색알고리즘
- 코드트리
- 백준괄호
- 합성곱연산
- BOJ
- BOJ1655
- 가운데를말해요
Archives
- Today
- Total
코딩하는 락커
[Spring Boot를 이용한 RESTful Web Services 개발] 33~34강 본문
🍃 Spring/🌱 Spring Boot를 이용한 RESTful Web Service
[Spring Boot를 이용한 RESTful Web Services 개발] 33~34강
락꿈사 2022. 3. 5. 13:25Spring Security를 이용한 인증 처리
- 지금까지 작성한 사용자 관리 등의 REST API는 웹 브라우저나 Postman과 같은 클라이언트 테스트 프로그램을 이용하면 바로 결과를 확인할 수 있었음
- 일반적으로 공개되어도 좋은 정보가 아니라 중요한 테스트 혹은 일부 인증을 거친 사용자만 사용해야 하는 리소스의 경우 보안에 문제가 생길 수 있음
- REST API 어플리케이션의 인증을 처리하기 위한 다양한 방법이 있음 (JWT, ID/Password, Spring Security 등)
- Spring Security란 스프링 프레임워크에서도 어렵고 복잡한 구조로 되어 있지만, ID와 Password만을 사용하기 위해 간단한 구조로 만들 수 있음
- Pom.xml 파일에 의존성 추가 (버전 정보 꼭 작성해줘야 함)
- 로그 파일을 확인하여 자동 생성된 현재 프로젝트에서 사용할 수 있는 PW 확인
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.6.3</version>
</dependency>
Configuration 클래스를 이용한 사용자 인증 처리
- 개발자가 직접 지정한 ID, Password를 이용한 인증 처리 구현
- application.yml 파일에 내용 추가
security:
user:
name: username
password: passw0rd
- 고정된 아이디와 패스워드를 사용하는 방식은 정보가 변경될 때마다 수정해줘야하는 번거로움이 있음
- 데이터 베이스에서 사용자 정보를 가져오는 방식 구현
- config 패키지에 SecurityConfig.java 클래스 생성
package com.example.restfulwebservice.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import java.net.Authenticator;
@Configuration
// WebSecurityConfiguration는 security 관련 config를 설정할 수 있게 해줌
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// memory 방식의 Authentication 추가
// auth.jdbcAuthentication()도 가능
auth.inMemoryAuthentication()
.withUser("roxy")
.password("{noop}test1234") // {noop}를 붙이면 패스워드 플레인 텍스트 값을 인코딩 없이 사용할 수 있게 해줌
.roles("USER");
}
}
'🍃 Spring > 🌱 Spring Boot를 이용한 RESTful Web Service' 카테고리의 다른 글
[Spring Boot를 이용한 RESTful Web Services 개발] 32강 (0) | 2022.03.05 |
---|---|
[Spring Boot를 이용한 RESTful Web Services 개발] 31강 (0) | 2022.03.03 |
[Spring Boot를 이용한 RESTful Web Services 개발] 29~30강 (0) | 2022.03.03 |
[Spring Boot를 이용한 RESTful Web Services 개발] 27~28강 (0) | 2022.02.11 |
[Spring Boot를 이용한 RESTful Web Services 개발] 25~26강 (0) | 2022.02.09 |
Comments