Spring/JWT

    회원가입, 권한검증

    회원가입, 권한검증

    회원가입 API 생성 권한검증 확인 간단한 유틸리티 메소드를 만들기 위해 SecurityUtil 클래스 생성 package com.example.jwttutorial.util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import java.util.Optional; public class Securit..

    DTO, Repository, 로그인

    DTO, Repository, 로그인

    외부와의 통신에 사용할 DTO 클래스 생성 Repository 관련 코드 생성 로그인 API, 관련 로직 생성 로그인 시 사용할 LoginDto 클래스 생성 package com.example.jwttutorial.dto; import lombok.*; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @Getter @Setter @Builder @AllArgsConstructor @NoArgsConstructor public class LoginDto { @NotNull @Size(min = 3, max = 50) private String username; @NotNull @Size(min = 3..

    JWT 코드, Security 설정 추가

    JWT 설정 추가 spring: h2: console: enabled: true datasource: url: jdbc:h2:tcp://localhost/~/documents/project/jwt driver-class-name: org.h2.Driver username: sa password: jpa: database-platform: org.hibernate.dialect.H2Dialect hibernate: ddl-auto: update properties: hibernate: format_sql: true show_sql: true logging: level: com.example: DEBUG jwt: header: Authorization secret: QAFF-_jk3R4iSedvs_JM4Z9..

    Security 설정, Data 설정

    401 unauthorized 해결을 위한 Security 설정 package com.example.jwttutorial.config; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @EnableWebSecurity // 기본적인 Web 보안을 활성화 public cl..

    JWT 소개

    JWT 소개

    JWT(JSON Web Token)는 RFC 7519 웹 표준으로 지정이 되어있고 JSON 객체를 사용해서 토큰 자체에 정보들을 저장하고 있는 Web Token이라고 정의 할 수 있습니다. Header, Payload, Signature로 구성되어있다. aaaaaa.bbbbbbb.ccccccc -> (header.payload.signature) Header : Signature를 해싱하기 위한 알고리즘 정보들이 담겨 있다. Payload : 서버와 클라이언트가 주고받는, 시스템에서 실제로 사용될 정보에 대한 내용들을 담고 있습니다. Signature : 토큰의 유효성 검증을 위한 문자열입니다. 이 문자열을 통해 서버에서는 이 토큰이 유효한 토큰인지를 검증할 수 있습니다. 장점 중앙의 인증 서버, 데이터..