1. Controller 생성 - AuthController @CrossOrigin(origins = "*", maxAge = 3600) @RestController @RequestMapping("/api/auth") public class AuthController { ..... @PostMapping("/signin") public ResponseEntity authenticateUser(@Valid @RequestBody LoginRequest loginRequest) { Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken (loginRequest.getUse..
1. unauthorizedHandler 비인증 처리 - AuthEntryPointJwt @Component // 인증,인가 예외발생시 처리 public class AuthEntryPointJwt implements AuthenticationEntryPoint { private static final Logger logger = LoggerFactory.getLogger(AuthEntryPointJwt.class); @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletExceptio..
1. model 생성 - User @Data @Entity @Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = "username"), @UniqueConstraint(columnNames = "email") }) public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotBlank @Size(max = 20) private String username; @NotBlank @Size(max = 50) @Email private String email; @NotBlank @Size(max = 120) priva..
Spring Security를 이용하여 JWT 인증하기 전 기본적인 세팅을 해야한다. 1. dependency - Spring Data JPA - Spring Security - Spring Web - Lombok - PostgreSQL Driver (DB) - jwt 2. DB 연동 설정 spring.datasource.url=jdbc:postgresql://localhost:5432/TestDB spring.datasource.username=test spring.datasource.password=1234 spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.dial..