Skip to content

Commit

Permalink
chore: merge conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
miseongk committed May 18, 2024
2 parents 731c8a4 + 9152846 commit c30ea37
Show file tree
Hide file tree
Showing 264 changed files with 3,186 additions and 3,595 deletions.
16 changes: 9 additions & 7 deletions backend/kirikiri/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ jacocoTestReport {
classDirectories.setFrom(
files(classDirectories.files.collect {
fileTree(dir: it, excludes: [
"co/kirikiri/persistence/QuerydslRepositorySupporter",
"co/kirikiri/domain/**",
"co/kirikiri/persistence/goalroom/dto/**",
"co/kirikiri/common/persistence/QuerydslRepositorySupporter",
"co/kirikiri/common/service/dto/**",
"co/kirikiri/**/domain/**",
"co/kirikiri/**/persistence/dto/**",
"**/*Application*",
"**/*Config*",
"**/*Dto*",
Expand Down Expand Up @@ -112,11 +113,12 @@ jacocoTestCoverageVerification {
value = 'COVEREDRATIO'
minimum = 0.80
}

excludes = [
"co.kirikiri.persistence.QuerydslRepositorySupporter",
"co.kirikiri.domain.**.**",
"co.kirikiri.persistence.goalroom.dto.**",
"co.kirikiri.common.persistence.QuerydslRepositorySupporter",
"co.kirikiri.common.service.dto.**",
"co.kirikiri.**.domain.**",
"co.kirikiri.**.persistence.dto.**",
"**.*Application*",
"**.*Config*",
"**.*Dto*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package co.kirikiri.controller;
package co.kirikiri.auth.controller;

import co.kirikiri.service.auth.AuthService;
import co.kirikiri.service.auth.NaverOauthService;
import co.kirikiri.service.dto.auth.OauthRedirectResponse;
import co.kirikiri.service.dto.auth.request.LoginRequest;
import co.kirikiri.service.dto.auth.request.ReissueTokenRequest;
import co.kirikiri.service.dto.auth.response.AuthenticationResponse;
import co.kirikiri.auth.service.AuthService;
import co.kirikiri.auth.service.NaverOauthService;
import co.kirikiri.auth.service.dto.request.LoginRequest;
import co.kirikiri.auth.service.dto.request.ReissueTokenRequest;
import co.kirikiri.auth.service.dto.response.AuthenticationResponse;
import co.kirikiri.auth.service.dto.response.OauthRedirectResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.kirikiri.infra;
package co.kirikiri.auth.infra;

import co.kirikiri.service.OauthNetworkService;
import co.kirikiri.auth.service.OauthNetworkService;
import lombok.RequiredArgsConstructor;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package co.kirikiri.auth.interceptor;

import co.kirikiri.auth.service.AuthService;
import co.kirikiri.common.exception.AuthenticationException;
import co.kirikiri.common.interceptor.AuthInterceptor;
import co.kirikiri.common.interceptor.Authenticated;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;

@Component
@RequiredArgsConstructor
public class AuthInterceptorImpl implements AuthInterceptor {

private static final String BEARER = "Bearer ";

private final AuthService authService;

@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response,
final Object handler) {
if (!(handler instanceof final HandlerMethod handlerMethod)) {
return true;
}
if (handlerMethod.hasMethodAnnotation(Authenticated.class)) {
final String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
checkHeader(authorizationHeader);
final String token = authorizationHeader.substring(BEARER.length());
checkTokenCertify(token);
}
return true;
}

private void checkHeader(final String authorizationHeader) {
if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) {
throw new AuthenticationException("인증 헤더가 적절하지 않습니다.");
}
}

private void checkTokenCertify(final String token) {
if (!authService.isCertified(token)) {
throw new AuthenticationException("토큰이 유효하지 않습니다.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.persistence.auth;
package co.kirikiri.auth.persistence;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package co.kirikiri.persistence.auth;
package co.kirikiri.auth.persistence;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

@Repository
public class RefreshTokenRepositoryImpl implements RefreshTokenRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package co.kirikiri.auth.resolver;

import co.kirikiri.auth.service.AuthService;
import co.kirikiri.common.exception.AuthenticationException;
import co.kirikiri.common.exception.ServerException;
import co.kirikiri.common.interceptor.Authenticated;
import co.kirikiri.common.resolver.MemberIdentifier;
import co.kirikiri.common.resolver.MemberIdentifierArgumentResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.ModelAndViewContainer;

@Component
@RequiredArgsConstructor
public class MemberIdentifierArgumentResolverImpl implements MemberIdentifierArgumentResolver {

private static final String BEARER = "Bearer ";

private final AuthService authService;

@Override
public boolean supportsParameter(final MethodParameter parameter) {
if (!parameter.hasMethodAnnotation(Authenticated.class)) {
throw new ServerException("MemberIdentifier는 인증된 사용자만 사용 가능합니다. (@Authenticated)");
}
return parameter.getParameterType().equals(String.class)
&& parameter.hasParameterAnnotation(MemberIdentifier.class);
}

@Override
public String resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer,
final NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) {
final String authorizationHeader = webRequest.getHeader(HttpHeaders.AUTHORIZATION);
checkHeader(authorizationHeader);
final String token = authorizationHeader.substring(BEARER.length());
return authService.findIdentifierByToken(token);
}

private void checkHeader(final String authorizationHeader) {
if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) {
throw new AuthenticationException("인증 헤더가 적절하지 않습니다.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package co.kirikiri.service.auth;
package co.kirikiri.auth.service;

import co.kirikiri.auth.persistence.RefreshTokenRepository;
import co.kirikiri.auth.service.dto.LoginDto;
import co.kirikiri.auth.service.dto.request.LoginRequest;
import co.kirikiri.auth.service.dto.request.ReissueTokenRequest;
import co.kirikiri.auth.service.dto.response.AuthenticationResponse;
import co.kirikiri.auth.service.mapper.AuthMapper;
import co.kirikiri.common.aop.ExceptionConvert;
import co.kirikiri.common.exception.AuthenticationException;
import co.kirikiri.domain.member.Member;
import co.kirikiri.domain.member.vo.Identifier;
import co.kirikiri.domain.member.vo.Password;
import co.kirikiri.persistence.auth.RefreshTokenRepository;
import co.kirikiri.persistence.member.MemberRepository;
import co.kirikiri.service.dto.auth.LoginDto;
import co.kirikiri.service.dto.auth.request.LoginRequest;
import co.kirikiri.service.dto.auth.request.ReissueTokenRequest;
import co.kirikiri.service.dto.auth.response.AuthenticationResponse;
import co.kirikiri.service.mapper.AuthMapper;
import java.util.Map;
import co.kirikiri.member.domain.Member;
import co.kirikiri.member.domain.vo.Identifier;
import co.kirikiri.member.domain.vo.Password;
import co.kirikiri.member.persistence.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;

@Service
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.auth;
package co.kirikiri.auth.service;

import co.kirikiri.common.exception.AuthenticationException;
import io.jsonwebtoken.Claims;
Expand All @@ -7,16 +7,16 @@
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.crypto.SecretKey;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.crypto.SecretKey;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class JwtTokenProvider implements TokenProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package co.kirikiri.service.auth;
package co.kirikiri.auth.service;

import co.kirikiri.domain.member.Member;
import co.kirikiri.persistence.member.MemberRepository;
import co.kirikiri.service.OauthNetworkService;
import co.kirikiri.service.dto.auth.NaverMemberProfileDto;
import co.kirikiri.service.dto.auth.NaverMemberProfileResponseDto;
import co.kirikiri.service.dto.auth.NaverOauthTokenDto;
import co.kirikiri.service.dto.auth.OauthRedirectResponse;
import co.kirikiri.service.dto.auth.response.AuthenticationResponse;
import co.kirikiri.service.dto.member.OauthMemberJoinDto;
import co.kirikiri.service.dto.member.request.GenderType;
import co.kirikiri.service.mapper.OauthMapper;
import co.kirikiri.service.member.MemberService;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Optional;
import co.kirikiri.auth.service.dto.NaverMemberProfileDto;
import co.kirikiri.auth.service.dto.NaverMemberProfileResponseDto;
import co.kirikiri.auth.service.dto.NaverOauthTokenDto;
import co.kirikiri.auth.service.dto.response.AuthenticationResponse;
import co.kirikiri.auth.service.dto.response.OauthRedirectResponse;
import co.kirikiri.auth.service.mapper.OauthMapper;
import co.kirikiri.member.domain.Member;
import co.kirikiri.member.persistence.MemberRepository;
import co.kirikiri.member.service.MemberService;
import co.kirikiri.member.service.dto.OauthMemberJoinDto;
import co.kirikiri.member.service.dto.request.GenderType;
import lombok.RequiredArgsConstructor;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Optional;

@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -58,17 +57,19 @@ private String getProperty(final String property) {

@Transactional
public AuthenticationResponse login(final Map<String, String> queryParams) {
final NaverOauthTokenDto naverOauthTokenDto = oauthNetworkService.requestToken(NaverOauthTokenDto.class,
queryParams).getBody();
final NaverOauthTokenDto naverOauthTokenDto = oauthNetworkService.requestToken(NaverOauthTokenDto.class, queryParams)
.getBody();
final NaverMemberProfileDto naverMemberProfileDto = getNaverMemberProfileDto(naverOauthTokenDto.accessToken());
final NaverMemberProfileResponseDto naverMemberProfileResponseDto = naverMemberProfileDto.response();
final Optional<Member> optionalMember = memberRepository.findByOauthId(naverMemberProfileResponseDto.id());
if (optionalMember.isPresent()) {
final Member member = optionalMember.get();
return authService.oauthLogin(member);
}
final Member savedMember = optionalMember.orElseGet(() -> saveMember(naverMemberProfileResponseDto));
return authService.oauthLogin(savedMember);
}

private Member saveMember(final NaverMemberProfileResponseDto naverMemberProfileResponseDto) {
return memberService.oauthJoin(
new OauthMemberJoinDto(naverMemberProfileResponseDto.id(), naverMemberProfileResponseDto.email(),
new OauthMemberJoinDto(naverMemberProfileResponseDto.id(),
naverMemberProfileResponseDto.email(),
naverMemberProfileResponseDto.nickname(),
GenderType.findByOauthType(naverMemberProfileResponseDto.gender())));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service;
package co.kirikiri.auth.service;

import org.springframework.http.ResponseEntity;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.auth;
package co.kirikiri.auth.service;

import java.time.LocalDateTime;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.kirikiri.auth.service.dto;

import co.kirikiri.member.domain.vo.Identifier;
import co.kirikiri.member.domain.vo.Password;

public record LoginDto(
Identifier identifier,
Password password
) {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.dto.auth;
package co.kirikiri.auth.service.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.dto.auth;
package co.kirikiri.auth.service.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.dto.auth;
package co.kirikiri.auth.service.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.dto.auth.request;
package co.kirikiri.auth.service.dto.request;

import jakarta.validation.constraints.NotBlank;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.dto.auth.request;
package co.kirikiri.auth.service.dto.request;

import jakarta.validation.constraints.NotBlank;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.dto.auth.response;
package co.kirikiri.auth.service.dto.response;

public record AuthenticationResponse(
String refreshToken,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.service.dto.auth;
package co.kirikiri.auth.service.dto.response;

public record OauthRedirectResponse(
String url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package co.kirikiri.service.mapper;
package co.kirikiri.auth.service.mapper;

import co.kirikiri.domain.member.vo.Identifier;
import co.kirikiri.domain.member.vo.Password;
import co.kirikiri.service.dto.auth.LoginDto;
import co.kirikiri.service.dto.auth.request.LoginRequest;
import co.kirikiri.service.dto.auth.response.AuthenticationResponse;
import co.kirikiri.auth.service.dto.LoginDto;
import co.kirikiri.auth.service.dto.request.LoginRequest;
import co.kirikiri.auth.service.dto.response.AuthenticationResponse;
import co.kirikiri.member.domain.vo.Identifier;
import co.kirikiri.member.domain.vo.Password;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.kirikiri.service.mapper;
package co.kirikiri.auth.service.mapper;

import co.kirikiri.service.dto.auth.OauthRedirectResponse;
import co.kirikiri.auth.service.dto.response.OauthRedirectResponse;

public class OauthMapper {

Expand Down
Loading

0 comments on commit c30ea37

Please sign in to comment.