SPRING
-
JWT 실습 프로젝트 - 4 (회원가입, 권한검증)SPRING/스프링 시큐리티 -JWT 2021. 9. 18. 00:19
SecurityUtil public class SecurityUtil { private static final Logger logger = LoggerFactory.getLogger(SecurityUtil.class); private SecurityUtil() { } public static Optional getCurrentUsername() { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { logger.debug("Security Context에 인증 정보가 없습니다."); return Optional.empty(); } Str..
-
JWT 실습 프로젝트 - 3 (로그인)SPRING/스프링 시큐리티 -JWT 2021. 9. 17. 20:01
@RestController @RequestMapping("/api") public class AuthController { private final TokenProvider tokenProvider; private final AuthenticationManagerBuilder authenticationManagerBuilder; public AuthController(TokenProvider tokenProvider, AuthenticationManagerBuilder authenticationManagerBuilder) { this.tokenProvider = tokenProvider; this.authenticationManagerBuilder = authenticationManagerBuilder..
-
JWT 실습 프로젝트 - 2 (Security 기본 설정, JWT 및 Security 설정)SPRING/스프링 시큐리티 -JWT 2021. 9. 17. 00:46
SilverNine님의 JWT 강의를 듣고 정리하였습니다. Security 기본 설정 @EnableWebSecurity // 기본적인 Web 보안 활성화 @EnableGlobalMethodSecurity(prePostEnabled = true) // @EnableGlobalMethodSecurity(prePostEnabled = true) 어노테이션은 메소드 단위로 // @PreAuthorize 검증 어노테이션을 사용하기 위해 추가합니다. public class SecurityConfig extends WebSecurityConfigurerAdapter { private final TokenProvider tokenProvider; private final JwtAuthenticationEntryPoin..
-
JWT 실습 프로젝트 - 1 (프로젝트 생성 및 설정)SPRING/스프링 시큐리티 -JWT 2021. 9. 11. 22:24
프로젝트 생성시 아래와 같은 dependency들을 추가합니다. - JPA - 스프링 시큐리티 - Validation - Web - lombok - H2 DB - jwt 관련 설정 implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org..
-
JWT란?SPRING/스프링 시큐리티 -JWT 2021. 9. 11. 18:38
JWT의 정의 JWT (JSON Web Token)는 개방형 표준 (RFC 7519)으로 당사자간에 정보를 JSON 객체로 안전하게 전송하기 위한 간결하고 독립적인 방법을 말합니다. 이 정보는 디지털 서명되어 있으므로 확인하고 신뢰할 수 있습니다. JWT는 비밀 (HMAC 알고리즘 사용) 또는 RSA 또는 ECDSA를 사용하는 공개 / 개인 키 쌍을 사용하여 서명 할 수 있습니다. JWT를 암호화하여 당사자 간의 보안을 제공 할 수도 있지만 서명 된 토큰에 중점을 둡니다. 서명 된 토큰은 그 안에 포함 된 클레임의 무결성을 확인할 수있는 반면 암호화 된 토큰은 해당 클레임을 다른 당사자로부터 숨깁니다. 공개 / 개인 키 쌍을 사용하여 토큰에 서명하면 서명은 개인 키를 보유한 당사자만 서명한 당사자임을 인..
-
세션 정책 및 고정세션 공격방지SPRING/스프링 시큐리티 2021. 8. 3. 10:51
스프링 시큐리티에서는 세션 관련 정책을 설정할 수 있다. 하나의 계정에 최대 몇개의 세션을 유지할 것인지, 새로운 사용자가 접근하면 로그인을 금지할 것인지 아니면 기존 사용자를 로그아웃 시킬 것인 지 등 정책 설정이 필요하다. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired UserDetailsService userDetailsService; @Override protected void configure(HttpSecurity http) throws Exception { // 모든 리소스에 대한 인증완료시 접근 허용 http .authorizeReques..
-
remember-meSPRING/스프링 시큐리티 2021. 8. 1. 17:24
1. 세션이 만료되고 브라우저가 종료된 후에도 어플리케이션이 사용자를 기억하는 기능 2. Remember-Me 쿠키에 대한 Http 요청을 확인한 후 토큰 기반 인증을 사용해 유효성을 검사하고 토큰이 검증되면 사용자는 로그인이 됨. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired UserDetailsService userDetailsService; @Override protected void configure(HttpSecurity http) throws Exception { // 모든 리소스에 대한 인증완료시 접근 허용 http .authorizeReq..
-
로그아웃SPRING/스프링 시큐리티 2021. 8. 1. 16:04
아래와 같이 로그아웃 관련 설정을 할 수 있다. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { // 모든 리소스에 대한 인증완료시 접근 허용 http .authorizeRequests() .anyRequest().authenticated(); // form Login 사용 http .formLogin(); // LogOut http .logout() // 로그아웃 처리 .logoutUrl("/logout") // 로그아웃 처리 URL .logo..