본문 바로가기

개발64

[Spring Security] @Secured(ROLE_?) 본래 필터 단에서 requestMatcher(" ? ").hasRole(" ? ")로 작업을 진행했다. URL 하나하나 작업하는 부분이 생각보다 많은 시간을 요구하여 Spring Security에서 지원하는 @Secured로 작업 방향을 변경하기로 했다. 기존 SecurityConfig에서 조금 더 간소하게 바꾸고 @EnableMethodSecurity(securedEnabled = true, prePostEnabled = true) 어노테이션을 추가했다. https://docs.spring.io/spring-security/reference/servlet/authorization/method-security.html Method Security :: Spring Security Sometimes, yo.. 2023. 1. 13.
Security + JWT를 사용해보자 JWTGenerator, JWTValidator, SecurityConfig JWT생성 JWT 검증 검증 단계에서 주의할 부분은 Claims claims = Jwts.parser() .setSigningKey(key) .parseClaimsJws(jwt.replace("Bearer ", "").trim())//pass the jwt that we received .getBody(); // want to read body part of jwt token parseClaimsJws 자동완성으로 작성하면서 Jwt가 작성 되는 경우가 있는데 에러가 발생하기에 주의해주자. 또한 위의 jwt.replace("Bearer " , "").trim()을 작성했다. JWT 생성하면서 우리는 분명 생성한 JWT를 'Auth.. 2023. 1. 10.
[Security] JWT와 JWS는 뭘까...? 둘이 신경쓰이게 된 부분은 JWT Token을 검증하는 단계에서 Claims claims = Jwts.parser() .setSigningKey(key) .parseClaimsJws(jwt.replace("Bearer ", "").trim())//pass the jwt that we received .getBody(); // want to read body part of jwt token parseCaimsJwt를 사용하면 io.jsonwebtoken.UnsupportedJwtException: Signed Claims JWSs are not supported. 에러를 확인할 수 있기 때문이다. 그럼 무엇인 문제인걸까? 아래 링크를 확인하면 https://developer.okta.com/blog/202.. 2023. 1. 6.
[Security] 시큐리티 세션정책 http .sessionManagement() .sessionCreationPolicy( SessionCreationPolicy.정책상수) SessionCreationPolicy.ALWAYS - 스프링시큐리티가 항상 세션을 생성 SessionCreationPolicy.IF_REQUIRED - 스프링시큐리티가 필요시 생성(기본) SessionCreationPolicy.NEVER - 스프링시큐리티가 생성하지않지만, 기존에 존재하면 사용 SessionCreationPolicy.STATELESS - 스프링시큐리티가 생성하지도않고 기존것을 사용하지도 않음 - JWT 같은토큰방식을 쓸때 사용하는 설정 2023. 1. 5.
SecurityFilterChain을 작성해보자 사용자 요청에 따라서 특정 URL에 대한 접근을 제한하고 풀어줄 수 있으며 SecurityFilterChain로 정의 한다. 하지만 해당 설정을 진행하지 않더라도 Spring에는 Default로 진행하는 SecurityFilterChain이 존재한다. SpringBootWebSecurityConfiguration //IDE에서 검색해보자 중요한 부분은 해당 메도스가 default configuration for web security인 점과 사용자가 개인의 SpringFilterChain @Bean을 선언한다면 해당 Configuration은 back-off completely 한다는 점이다. config 작성에 어려움이 있다면 defaultSecurityFilterChain을 활용해서 개인 config.. 2023. 1. 2.
Spring Security 구성과 흐름 해당 게시글은 Spring Security의 이해를 위해서 작성했다. Spring Security INTERNAL FLOW Spring Security Filter : 사용자 측에서 보내는 request들을 확인하여 인증이 필요 여부를 확인한다. 필요하다면 login page로 보내거나 저장 되어있는 정보를 확인한다. Authentication : UsernamePasswordAuthenticationFilter가 http로 부터 username, password를 추출하며 Authentication 타입의 객체를 준비한다. AuthenticationManger : 사용가능한 AuthenticationProviders를 관리하며 책임진다. AuthenticationProvider : 인증 비즈니스 로직들.. 2023. 1. 2.