Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for review #47

Open
wants to merge 97 commits into
base: first
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
c7349f5
[ADD] actuator
ritty27 Jul 25, 2021
e5dca1c
[ADD] Actuator
oh980225 Jul 25, 2021
ecaad60
[Merge] Actuator
oh980225 Jul 25, 2021
fe80f29
[ADD] Member DB 수정 & 가입 기능 구현(비회원)
oh980225 Jul 26, 2021
a46081f
[ADD] 플레이 리스트 생성, 삭제, 수정 구현 & Member의 playList 조회 & 추가적 요구사항
oh980225 Jul 27, 2021
8c8c6aa
[ADD] 플레이 생성, 조회 구현
oh980225 Jul 28, 2021
006cd78
[ADD] 플레이 재생 시간 수정 & 플레이 재생 순서 수정
oh980225 Jul 29, 2021
73aaeb0
[ADD] 스웨거3 추가
oh980225 Jul 30, 2021
3505c2f
[FIX] 삭제시 순서 재정렬
oh980225 Jul 31, 2021
1bd5399
[ADD] RDS MySQL DB 연결
oh980225 Aug 2, 2021
3a42787
Merge branch 'dev' into seungjae
oh980225 Aug 2, 2021
133faee
Merge pull request #6 from YoutubePlaylist/seungjae
oh980225 Aug 2, 2021
70e0bd7
Merge pull request #7 from YoutubePlaylist/dev
oh980225 Aug 2, 2021
f70ffcf
[FIX] 시간 수정 FIX
oh980225 Aug 2, 2021
5a10228
Merge branch 'seungjae' of https://github.com/YoutubePlaylist/Youtube…
oh980225 Aug 2, 2021
a6f83f4
Merge pull request #8 from YoutubePlaylist/seungjae
oh980225 Aug 2, 2021
c7ba2d5
Merge pull request #9 from YoutubePlaylist/seungjae
oh980225 Aug 2, 2021
cbc4893
Merge pull request #10 from YoutubePlaylist/dev
oh980225 Aug 2, 2021
6ed1152
[ADD] 플레이리스트의 썸네일 이미지 추가
oh980225 Aug 2, 2021
4fe5889
Merge pull request #11 from YoutubePlaylist/seungjae
oh980225 Aug 2, 2021
68967cc
Merge pull request #12 from YoutubePlaylist/dev
oh980225 Aug 2, 2021
245a59e
[ADD] CORS 설정
oh980225 Aug 3, 2021
18c3174
Merge pull request #13 from YoutubePlaylist/seungjae
oh980225 Aug 3, 2021
df4c733
Merge pull request #14 from YoutubePlaylist/seungjae
oh980225 Aug 3, 2021
23a7758
Merge pull request #15 from YoutubePlaylist/dev
oh980225 Aug 3, 2021
c630e93
[ADD]jwt
ritty27 Aug 7, 2021
ac3a6e3
[ADD] 3차 스프린트 Spring Security - JWT 적용
oh980225 Aug 8, 2021
3c0b975
[FIX]SpringSecurity-jwt
ritty27 Aug 8, 2021
93e1471
[FIX]EXPIREDATE
ritty27 Aug 8, 2021
c03df42
[FIX]redis
ritty27 Aug 8, 2021
2759c8e
[DELETE]memberService
ritty27 Aug 8, 2021
3c78811
MERGE
oh980225 Aug 9, 2021
e7ee42f
[MERGE] 1차 작업 완료
oh980225 Aug 9, 2021
bc27d73
1차 MERGE
oh980225 Aug 10, 2021
1a15910
[MERGE] Spring Security 코드 정리, Redis적용, RefreshToken적용
oh980225 Aug 11, 2021
c305a87
[MERGE] Spring Security 코드 정리, Redis적용, RefreshToken적용
oh980225 Aug 11, 2021
d1b5d4c
0811
ritty27 Aug 11, 2021
63a80c3
[MERGE] 2차 작업 완료
ritty27 Aug 11, 2021
699ae38
Merge pull request #17 from YoutubePlaylist/jisoo
ritty27 Aug 11, 2021
c365edd
[ADD] 비회원 플레이리스트 개수 제한
ritty27 Aug 12, 2021
08a1cb4
[FIX] Security config
ritty27 Aug 12, 2021
cbe7f61
[FIX]Swagger 임시로 열러두기
ritty27 Aug 12, 2021
da6ed33
Merge pull request #18 from YoutubePlaylist/jisoo
ritty27 Aug 12, 2021
cb72c37
[ADD] 회원 삭제, 비밀번호 생성 규칙
oh980225 Aug 12, 2021
4c07455
Merge branch 'dev' into seungjae
oh980225 Aug 12, 2021
b766d1a
[ADD] 회원 삭제, 비밀번호 생성 규칙
oh980225 Aug 12, 2021
da732d0
Merge pull request #20 from YoutubePlaylist/dev
oh980225 Aug 12, 2021
1963784
[FIX] RefreshTokenExpire 로직 변경
ritty27 Aug 12, 2021
9d7691a
Merge pull request #21 from YoutubePlaylist/jisoo
ritty27 Aug 12, 2021
6e005ec
Merge pull request #22 from YoutubePlaylist/dev
ritty27 Aug 12, 2021
157874e
[ADD] 스웨거 적용
oh980225 Aug 12, 2021
d59c27c
Merge branch 'seungjae' of https://github.com/YoutubePlaylist/Youtube…
oh980225 Aug 12, 2021
4cb4891
Merge branch 'dev' into seungjae
oh980225 Aug 12, 2021
ff83568
Merge pull request #23 from YoutubePlaylist/seungjae
oh980225 Aug 12, 2021
541297e
Merge pull request #24 from YoutubePlaylist/dev
oh980225 Aug 12, 2021
bb11e01
[FIX] PlayService
ritty27 Aug 12, 2021
741149c
Merge pull request #25 from YoutubePlaylist/jisoo
ritty27 Aug 12, 2021
9621888
Merge pull request #26 from YoutubePlaylist/dev
ritty27 Aug 12, 2021
1f1ca33
[FIX] cors
ritty27 Aug 13, 2021
25a59b1
Merge pull request #27 from YoutubePlaylist/jisoo
ritty27 Aug 13, 2021
41d7909
Merge pull request #28 from YoutubePlaylist/jisoo
ritty27 Aug 13, 2021
53099d0
Merge pull request #29 from YoutubePlaylist/dev
ritty27 Aug 13, 2021
62da719
Cors
oh980225 Aug 13, 2021
7d64574
Merge branch 'dev' of https://github.com/YoutubePlaylist/YoutubePlayl…
oh980225 Aug 13, 2021
03f389d
[FIX] 만료 시간 로직 오류 수정
ritty27 Aug 13, 2021
4271084
Merge pull request #30 from YoutubePlaylist/jisoo
ritty27 Aug 13, 2021
4f38534
[FIX] Refresh token redis structure
ritty27 Aug 14, 2021
b02c101
[FIX] Refresh token redis structure
ritty27 Aug 14, 2021
39929e7
[FIX] Refresh token redis structure
ritty27 Aug 14, 2021
35f9b02
Merge branch 'dev' into jisoo
ritty27 Aug 14, 2021
d28b624
Merge pull request #32 from YoutubePlaylist/jisoo
ritty27 Aug 14, 2021
8673c0c
[FIX] Refresh token redis expireTime
ritty27 Aug 14, 2021
967f9d4
Merge branch 'jisoo' of https://github.com/YoutubePlaylist/YoutubePla…
ritty27 Aug 14, 2021
f4efe1d
Merge pull request #33 from YoutubePlaylist/jisoo
ritty27 Aug 14, 2021
bd14560
Merge pull request #34 from YoutubePlaylist/dev
ritty27 Aug 14, 2021
0d62224
Merge branch 'main' of https://github.com/YoutubePlaylist/YoutubePlay…
oh980225 Aug 15, 2021
b7ad771
[ADD] S3 1차 작업
oh980225 Aug 17, 2021
663dcc6
[ADD] S3 프로필 이미지 업로드
oh980225 Aug 17, 2021
fdb10e7
[merge] s3
ritty27 Aug 18, 2021
e7781e0
[TEST] TEST용 RefreshToekn 만료시간 설정
ritty27 Aug 18, 2021
acda9a5
[ADD] 비밀번호 변경, PLAY-Channel title 추가
ritty27 Aug 19, 2021
90ab091
[ADD] 회원정보조회 + 이미지 업로드 수정
oh980225 Aug 20, 2021
78abfe0
Merge pull request #35 from YoutubePlaylist/jisoo
ritty27 Aug 20, 2021
740a212
[ADD] 비회원->회원 변경 & 이미지 업로드 파일명 랜덤 & 회원 정보 조회
oh980225 Aug 20, 2021
be6cfea
Merge pull request #36 from YoutubePlaylist/seungjae
oh980225 Aug 20, 2021
e9eca9b
Merge branch 'dev' into jisoo
ritty27 Aug 20, 2021
5702104
[ADD] 비밀번호 변경, PLAY-Channel title 추가
ritty27 Aug 20, 2021
d56bae1
8월 3주차 merge
ritty27 Aug 20, 2021
1705ad2
[FIX] 중복 검사
oh980225 Aug 20, 2021
2fb9315
Merge pull request #40 from YoutubePlaylist/seungjae
oh980225 Aug 20, 2021
9fb0485
Merge pull request #41 from YoutubePlaylist/dev
oh980225 Aug 20, 2021
5b8377b
[FIX] 비회원 리스트 제한, 토큰 만료 시간
ritty27 Aug 22, 2021
491cf35
[FIX] 비회원 리스트 제한, 토큰 만료 시간
ritty27 Aug 22, 2021
46a3c48
[ADD] Actuator 설정 변경
oh980225 Aug 23, 2021
fa9d677
[MERGE] Actuator 설정
oh980225 Aug 23, 2021
055fad4
Merge pull request #43 from YoutubePlaylist/seungjae
oh980225 Aug 23, 2021
600d7de
Merge pull request #44 from YoutubePlaylist/dev
oh980225 Aug 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
application-prod.yaml
aws.yaml

**/src/main/resources/application*
**/src/main/resources/application-local.yaml

### STS ###
.apt_generated
Expand Down
37 changes: 33 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,41 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.3'
developmentOnly 'org.springframework.boot:spring-boot-devtools:2.5.3'

runtimeOnly 'com.h2database:h2:1.4.200'
// runtimeOnly 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.3'

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'de.codecentric:spring-boot-admin-starter-client:2.4.1'

implementation 'org.springdoc:springdoc-openapi-ui:1.5.7'

//security
implementation 'org.springframework.boot:spring-boot-starter-security:2.5.3'
implementation 'org.springframework.security:spring-security-test:5.5.1'

//jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'

//redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.modelmapper:modelmapper:2.3.6'

// aws cloud
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-aws', version: '2.2.6.RELEASE'

//sms 인증
implementation 'net.nurigo:javaSDK:2.2'


compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/example/youtubedb/YoutubeDbApplication.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.example.youtubedb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class YoutubeDbApplication {
public static final String APPLICATION_LOCATIONS = "spring.config.location="
+ "classpath:application.yaml,"
+ "classpath:aws.yaml";

public static void main(String[] args) {
SpringApplication.run(YoutubeDbApplication.class, args);
new SpringApplicationBuilder(YoutubeDbApplication.class)
.properties(APPLICATION_LOCATIONS)
.run(args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
package com.example.youtubedb.config;

import com.example.youtubedb.auth.JwtAuthenticationFilter;
import com.example.youtubedb.auth.JwtTokenProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager;
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;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@EnableWebSecurity
public class MultiSecurityConfig {

@Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

private final JwtTokenProvider jwtTokenProvider;

@Autowired
public ApiWebSecurityConfigurationAdapter(JwtTokenProvider jwtTokenProvider) {
this.jwtTokenProvider = jwtTokenProvider;
}

@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}

protected void configure(HttpSecurity http) throws Exception {
http
.headers().frameOptions().disable() // h2 콘솔때문에
.and()
.httpBasic().disable()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/member/**").permitAll()
.antMatchers("/api/**").hasAnyRole("USER", "ADMIN")
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().permitAll()
.and()
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider),
UsernamePasswordAuthenticationFilter.class);
}
}

@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.headers().frameOptions().disable() // h2 콘솔때문에
.and()
.httpBasic().disable()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/member/**").permitAll()
.antMatchers("/api/**").hasAnyRole("USER", "ADMIN")
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().permitAll()
.and()
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider),
UsernamePasswordAuthenticationFilter.class).formLogin();


}
}
}*/


// 그냥 테스트 페이지 무시 ㄱ
lette1394 marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 54 additions & 0 deletions src/main/java/com/example/youtubedb/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.example.youtubedb.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

@Configuration
//@RequiredArgsConstructor
@EnableRedisRepositories
public class RedisConfig {

// TODO Redis 현재 DEAMON으로 돌려놓음 -> SYSTEMD로 추후 전환 필요

// private final ObjectMapper objectMapper;
// private final RedisProperties redisProperties;
lette1394 marked this conversation as resolved.
Show resolved Hide resolved
@Value("${spring.redis.host}")
private String redisHost;

@Value("${spring.redis.port}")
private int redisPort;

// @Bean
// public ModelMapper modelMapper(){
// ModelMapper modelMapper = new ModelMapper();
// modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
// return modelMapper;
// }

@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory();
}

// @Bean
// public RedisTemplate<String, Object> redisTemplate() {
// RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
// redisTemplate.setConnectionFactory(redisConnectionFactory());
// redisTemplate.setKeySerializer(new StringRedisSerializer());
// redisTemplate.setValueSerializer(new StringRedisSerializer());
//
// return redisTemplate;
// }

@Bean
public RedisTemplate<?, ?> redisTemplate() {
RedisTemplate<byte[], byte[]> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
return redisTemplate;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/example/youtubedb/config/SpringConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.youtubedb.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpringConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*");
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/example/youtubedb/config/TestConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//package com.example.youtubedb.config;
//
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
//@Configuration
//public class TestConfig implements WebMvcConfigurer {
// public void addViewControllers(ViewControllerRegistry registry) {
// registry.addViewController("/hello").setViewName("hello");
// registry.addViewController("/login").setViewName("login");
// }
//}
79 changes: 79 additions & 0 deletions src/main/java/com/example/youtubedb/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.example.youtubedb.config;

import com.example.youtubedb.config.jwt.JwtAccessDeniedHandler;
import com.example.youtubedb.config.jwt.JwtAuthenticationEntryPoint;
import com.example.youtubedb.config.jwt.JwtSecurityConfig;
import com.example.youtubedb.config.jwt.TokenProvider;
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.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.cors.CorsUtils;

@Configuration
@RequiredArgsConstructor
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

private final TokenProvider tokenProvider;
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
private final JwtAccessDeniedHandler jwtAccessDeniedHandler;

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()

.exceptionHandling()
.authenticationEntryPoint(jwtAuthenticationEntryPoint)
.accessDeniedHandler(jwtAccessDeniedHandler)

.and()
.headers()
.frameOptions()
.sameOrigin()

.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)

.and()
.authorizeRequests()
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
.antMatchers("/api/member").authenticated()
.antMatchers("/api/member/change").authenticated()
.antMatchers("/api/member/upload").authenticated()
.antMatchers("/api/member/**").permitAll()
.antMatchers("/api/**").authenticated()
// .antMatchers("/swagger-ui/**").hasRole("ADMIN")
// .anyRequest().permitAll()
.and()
.cors()
.and()
.apply(new JwtSecurityConfig(tokenProvider));



// .authorizeRequests()
// .antMatchers("/", "/applications").authenticated()
// .antMatchers("/admin").hasRole("ADMIN")
// .anyRequest().permitAll()
// .and()
// .formLogin()
// .loginPage("/login")
// .successForwardUrl("/")
// .permitAll()
// .and()
// .logout()
// .permitAll();
}

@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.youtubedb.config.jwt;

import com.example.youtubedb.dto.error.AuthenticationEntryPointFailResponseDto;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class JwtAccessDeniedHandler implements AccessDeniedHandler {

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
response.setContentType("application/json;charset=UTF-8");
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
ObjectMapper mapper = new ObjectMapper();
lette1394 marked this conversation as resolved.
Show resolved Hide resolved
response.getWriter().write(
mapper.writeValueAsString(AuthenticationEntryPointFailResponseDto.builder()
.status(HttpStatus.FORBIDDEN.value())
.message(accessDeniedException.getMessage())
.build())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.youtubedb.config.jwt;

import com.example.youtubedb.dto.error.AuthenticationEntryPointFailResponseDto;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.setContentType("application/json;charset=UTF-8");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
ObjectMapper mapper = new ObjectMapper();
response.getWriter().write(
mapper.writeValueAsString(AuthenticationEntryPointFailResponseDto.builder()
.status(HttpStatus.UNAUTHORIZED.value())
.message(authException.getMessage())
.build())
);
}
}
Loading