-
[RESTFUL 학습] spring-security 기본SPRING/WEBSERVICE 2020. 8. 31. 23:29
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
스프링에 기본적인 시큐리티를 적용하기 위해서는 위와 같이 dependency를 추가해야 한다.
스프링 톰캣 서버를 시작할 때 발급되는 위 password를 Authorization에 할당해야 한다.
(참고 : https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Authorization)
위 POSTMAN와 같이 user/ 비밀번호를 Authorization Header에 추가해야 정상적인 Response를 받을 수 있다.
- Spring Security 계정 및 비밀번호 설정방법
1. application.yml 에 적용
2. Configuration Class (환결설정 클래스로 설정)
@Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { // {noop} no operation = noencoding auth.inMemoryAuthentication() .withUser("bins") .password("{noop}test1234") .roles("USER"); } }
위와 같이 Security 관련 Configuration Class를 생성하여 User / password를 설정 할 수 있다.
'SPRING > WEBSERVICE' 카테고리의 다른 글
[RESTFUL 학습] JPA를 이용한 CRUD 기본 예제 (RESTCONTROLLER) (0) 2020.09.06 [RESTFUL 학습] JPA를 사용하기 위한 기본 세팅(H2 DB 사용) (0) 2020.09.05 [RESTFUL] HAL BROWSER (0) 2020.08.31 [RESTFUL 학습] SWAGGER 심화-1 (0) 2020.08.31 [RESTFUL 학습] SWAGGER (0) 2020.08.23