Skip to content

Commit

Permalink
Merge pull request #84 from JNU-econovation/BE
Browse files Browse the repository at this point in the history
Be
  • Loading branch information
capDoYeonLee authored Jul 19, 2024
2 parents f600274 + 35d26a7 commit 131664b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.example.demo.auth.application.support.CookieTokenExtractor;
import com.example.demo.auth.application.support.HeaderTokenExtractor;
import com.example.demo.auth.application.support.MemberArgumentResolver;
import com.example.demo.auth.presentation.interceptor.AuthInterceptor;
//import com.example.demo.auth.presentation.interceptor.AuthInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -21,36 +21,36 @@ public class LoginConfig implements WebMvcConfigurer {
private final MemberArgumentResolver memberArgumentResolver;
private final TokenResolver tokenResolver;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry
.addInterceptor(memberAuthInterceptor())
.addPathPatterns("/api/**")
.excludePathPatterns("/api/guest/**", "/api/auth/**", "/api/health-check","/api/programs/**");
registry
.addInterceptor(reissueAuthInterceptor())
.addPathPatterns("/auth/reissue")
.excludePathPatterns("/api/guest/**", "/api/auth/**", "/api/health-check");
}
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// registry
// .addInterceptor(memberAuthInterceptor())
// .addPathPatterns("/api/**")
// .excludePathPatterns("/api/guest/**", "/api/auth/**", "/api/health-check","/api/programs/**");
// registry
// .addInterceptor(reissueAuthInterceptor())
// .addPathPatterns("/auth/reissue")
// .excludePathPatterns("/api/guest/**", "/api/auth/**", "/api/health-check");
// }

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(memberArgumentResolver);
}

@Bean
public AuthInterceptor memberAuthInterceptor() {
return AuthInterceptor.builder()
.tokenExtractor(new HeaderTokenExtractor())
.tokenResolver(tokenResolver)
.build();
}

@Bean
public AuthInterceptor reissueAuthInterceptor() {
return AuthInterceptor.builder()
.tokenExtractor(new CookieTokenExtractor())
.tokenResolver(tokenResolver)
.build();
}
// @Bean
// public AuthInterceptor memberAuthInterceptor() {
// return AuthInterceptor.builder()
// .tokenExtractor(new HeaderTokenExtractor())
// .tokenResolver(tokenResolver)
// .build();
// }
//
// @Bean
// public AuthInterceptor reissueAuthInterceptor() {
// return AuthInterceptor.builder()
// .tokenExtractor(new CookieTokenExtractor())
// .tokenResolver(tokenResolver)
// .build();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ public class AuthCookieManager implements CookieManager {
private static final String SAMESITE = "None";
private static final Long EXPIRATION = 0L;

@Value("${token.cookie.domain:http://localhost}")
@Value("${token.cookie.domain}")
private String domain;

@Value("${token.cookie.path:/}")
@Value("${token.cookie.path}")
private String path;

@Value("${security.jwt.refresh.validTime:3600}")
@Value("${security.jwt.refresh.validTime}")
private Long validTime;

@Override
public ResponseCookie setCookie(String key, String value) {
return ResponseCookie.from(key, value)
.path(path)
.domain(domain)
.httpOnly(HTTP_ONLY)
.domain(".econo-calendar.com")
.secure(SECURE)
.sameSite(SAMESITE)
.maxAge(TimeUtil.convertSecondsFromMillis(validTime))
Expand All @@ -39,8 +39,8 @@ public ResponseCookie setCookie(String key, String value) {
public ResponseCookie deleteCookie(String key) {
return ResponseCookie.from(key, "")
.path(path)
.domain(domain)
.httpOnly(HTTP_ONLY)
.domain(".econo-calendar.com")
.secure(SECURE)
.sameSite(SAMESITE)
.maxAge(TimeUtil.convertSecondsFromMillis(EXPIRATION))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
package com.example.demo.auth.presentation.interceptor;


import com.example.demo.auth.application.model.token.TokenResolver;
import com.example.demo.auth.application.support.TokenExtractor;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.cors.CorsUtils;
import org.springframework.web.servlet.HandlerInterceptor;

public class AuthInterceptor implements HandlerInterceptor {
private final TokenExtractor tokenExtractor;
private final TokenResolver tokenResolver;

public AuthInterceptor(
@Qualifier("header") TokenExtractor tokenExtractor, TokenResolver tokenResolver) {
this.tokenExtractor = tokenExtractor;
this.tokenResolver = tokenResolver;
}

public static AuthInterceptorBuilder builder() {
return new AuthInterceptorBuilder();
}

@Override
public boolean preHandle(
HttpServletRequest request, HttpServletResponse response, Object handler) {
if (CorsUtils.isPreFlightRequest(request)) {
return true;
}

String token = tokenExtractor.extract(request);
System.out.println("token :" + token);
tokenResolver.getUserDataByAccessToken(token);
return true;
}

public static class AuthInterceptorBuilder {

private TokenExtractor tokenExtractor;
private TokenResolver tokenResolver;

public AuthInterceptorBuilder tokenExtractor(TokenExtractor tokenExtractor) {
this.tokenExtractor = tokenExtractor;
return this;
}

public AuthInterceptorBuilder tokenResolver(TokenResolver tokenResolver) {
this.tokenResolver = tokenResolver;
return this;
}

public AuthInterceptor build() {
return new AuthInterceptor(tokenExtractor, tokenResolver);
}
}
}
//package com.example.demo.auth.presentation.interceptor;
//
//
//import com.example.demo.auth.application.model.token.TokenResolver;
//import com.example.demo.auth.application.support.TokenExtractor;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.web.cors.CorsUtils;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//public class AuthInterceptor implements HandlerInterceptor {
// private final TokenExtractor tokenExtractor;
// private final TokenResolver tokenResolver;
//
// public AuthInterceptor(
// @Qualifier("header") TokenExtractor tokenExtractor, TokenResolver tokenResolver) {
// this.tokenExtractor = tokenExtractor;
// this.tokenResolver = tokenResolver;
// }
//
// public static AuthInterceptorBuilder builder() {
// return new AuthInterceptorBuilder();
// }
//
// @Override
// public boolean preHandle(
// HttpServletRequest request, HttpServletResponse response, Object handler) {
// if (CorsUtils.isPreFlightRequest(request)) {
// return true;
// }
//
// String token = tokenExtractor.extract(request);
// System.out.println("token :" + token);
// tokenResolver.getUserDataByAccessToken(token);
// return true;
// }
//
// public static class AuthInterceptorBuilder {
//
// private TokenExtractor tokenExtractor;
// private TokenResolver tokenResolver;
//
// public AuthInterceptorBuilder tokenExtractor(TokenExtractor tokenExtractor) {
// this.tokenExtractor = tokenExtractor;
// return this;
// }
//
// public AuthInterceptorBuilder tokenResolver(TokenResolver tokenResolver) {
// this.tokenResolver = tokenResolver;
// return this;
// }
//
// public AuthInterceptor build() {
// return new AuthInterceptor(tokenExtractor, tokenResolver);
// }
// }
//}
2 changes: 1 addition & 1 deletion BE/error/src/main/resources/env.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ AT_TOKEN_SECRET_KEY=erroroverflowsecretekeyerroroverflowsecretekey
RT_TOKEN_SECRET_KEY=erroroverflowsecretekeyerroroverflowsecretekey
AT_VALID_TIME=3600000
RT_VALID_TIME=26280000
COOKIE_DOMAIN=localhost, econo-calendar
COOKIE_DOMAIN=localhost
COOKIE_PATH=/

0 comments on commit 131664b

Please sign in to comment.