Spring/Spring Security (10) 썸네일형 리스트형 [Spring Security] JWT Token 🔐 JWT : Json Web Token JWT는 세 부분으로 구성된다 : 헤더(Header), 페이로드(Payload), 서명(Signature). 헤더 (Header): 토큰의 유형 (즉, JWT)과 해싱 알고리즘 (예: HMAC SHA256 또는 RSA)을 정의하는 데 사용된다. 페이로드 (Payload): 페이로드는 클레임을 포함하고 있으며, 이는 엔티티 (일반적으로 사용자)와 추가 데이터에 대한 선언으로 클레임에는 등록된 (즉, 표준에 정의된), 공개, 비공개 클레임이 있다. 서명 (Signature): 헤더와 페이로드를 합친 후, 비밀키를 사용하여 이를 암호화한다. 이 서명은 토큰이 변조되지 않았음을 확인하는 데 사용되며, 비밀 키를 알고 있는 경우에만 토큰을 확인하거나 생성할 수 있다. 이 .. [Spring Security] ajax login - Spring Security 를 이용하여 (ajax)비동기 로그인 구현하기 SecurityConfig.java @Configuration @EnableWebSecurity @Order(0) @Slf4j public class AjaxSecurityConfig extends WebSecurityConfigurerAdapter { private String[] permitAllResources = {"/api/public/**","/sample","/aws/**","/sample/**", "/login/**", "/outer/**", "/fonts/**", "/landing/**", "/error/**", "/aws/health/check"}; @Override public void configure(W.. [Spring Security] GET 로그아웃 처리 스프링 시큐리티의 로그아웃 기능은 별도의 설정을 하지 않으면 POST 방식을 지원한다. 이를 GET 방식으로 변경해주었다. tymeleaf를 사용한 get 로그아웃 처리 1. build.gradle dependency 추가 implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' 2. logout 기능을 구현할 .html 헤더 부분에 springsecurity name space 추가 3. 로그인 여부에 따라 보여진 태그 sec:authorize의 isAnonymous() / isAuthenticated() 로 구분 및 로그아웃 경로 설정 로그인 | 회원가입 회원명 | 로그아웃 isAnonymous() : 로그인하지 않은 사용자에게만 .. [Spring Security] 스프링 시큐리티를 이용하여 로그인, 회원가입 구현하기 Config @Configuration @RequiredArgsConstructor public class SecurityConfig { private final AuthenticationSuccess authenticationSuccess; private final AuthenticationFailure authenticationFailure; private final LogoutExecute logoutExecute; private final LogoutSuccess logoutSuccess; private final UserDetailsService userDetailsService; private final AuthenticationEntryException authenticationEntryEx.. [Spring Secururity ERROR] 스프링 빈 순환 참조 에러 The dependencies of some of the beans i 스프링 시큐리티 설정 파일 세팅 중 비밀번호 암호화 설정을 위해 PasswordEncoder 반환 타입의 메소드를 선언 하는 중 순환 참조 오류가 발생하였다. Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true. 순환 참조에 의존하는 것은 권장되지 않으며 기본적.. [Spring Security] Spring Security 설정하기 Config 설정 클래스 import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.s.. [Spring Security] 유저별 권한 설정 1. 표현식 메소드 동작 authenticated() 인증된 사용자의 접근을 허용 fullyAuthenticated() 인증된 사용자의 접근을 혀용, rememberMe(로그인 상태유지) 인증 제외 permitAll() 무조건 접근 허용 denyAll() 무조건 접근 허용하지 않음 anonymous() 익명 사용자만 접근 허용 (인증된 사용자는 접근 불가) rememberMe() 기억하기를 통해 인증된 사용자의 접근 허용 access(String) 주어진 SpEL 표현식의 평가 결과가 true이면 접근을 허용 hasRole(String) 사용자가 주어진 역할이 있다면 접근을 허용 -> ex) USER hasAuthority(String) 사용자가 주어진 권한이 있다면 접근을 허용 -> ex) ROLE_U.. [Spring Security] 동시 로그인 제한하기(동시 세션 제어) ❄️ 설정한 최대 허용 가능 세션을 초과했을 경우 1️⃣ 이전 사용자 세션 만료 처리 (첫 번째 사용자) : maxSessionsPreventsLogin(false) 2️⃣ 현재 사용자 인증 실패 처리 : maxSessionsPreventsLogin(true) 해당 기능을 구현하기 위해서는 스프링 시큐리티가 적용되어 있어야 한다. [Spring Security] Spring Security 설정하기 import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springfram.. 이전 1 2 다음