Skip to content

Commit

Permalink
refactor: auth 패키지 내 클래스 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed Jun 7, 2024
1 parent 4c9a07f commit 8dc1dce
Show file tree
Hide file tree
Showing 66 changed files with 102 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.auth;

import com.festago.auth.domain.AuthenticateContext;
import com.festago.auth.domain.authentication.AdminAuthentication;
import com.festago.auth.domain.authentication.Authentication;
import com.festago.common.exception.UnexpectedException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.festago.auth;

import com.festago.auth.annotation.Authorization;
import com.festago.auth.application.HttpRequestTokenExtractor;
import com.festago.auth.domain.AuthenticateContext;
import com.festago.auth.domain.AuthenticationTokenExtractor;
import com.festago.auth.domain.authentication.Authentication;
import com.festago.auth.infrastructure.web.HttpRequestTokenExtractor;
import com.festago.common.exception.ErrorCode;
import com.festago.common.exception.ForbiddenException;
import com.festago.common.exception.UnauthorizedException;
Expand All @@ -23,8 +24,7 @@ public class AnnotationAuthorizationInterceptor implements HandlerInterceptor {
public AnnotationAuthorizationInterceptor(
HttpRequestTokenExtractor httpRequestTokenExtractor,
AuthenticationTokenExtractor authenticationTokenExtractor,
AuthenticateContext authenticateContext)
{
AuthenticateContext authenticateContext) {
Assert.notNull(httpRequestTokenExtractor, "The httpRequestTokenExtractor must not be null");
Assert.notNull(authenticationTokenExtractor, "The authenticationTokenExtractor must not be null");
Assert.notNull(authenticateContext, "The authenticateContext must not be null");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.festago.auth;

import com.festago.auth.application.HttpRequestTokenExtractor;
import com.festago.auth.domain.AuthenticateContext;
import com.festago.auth.domain.AuthenticationTokenExtractor;
import com.festago.auth.domain.Role;
import com.festago.auth.domain.authentication.Authentication;
import com.festago.auth.infrastructure.web.HttpRequestTokenExtractor;
import com.festago.common.exception.ErrorCode;
import com.festago.common.exception.ForbiddenException;
import com.festago.common.exception.UnauthorizedException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.auth;

import com.festago.auth.domain.AuthenticateContext;
import com.festago.auth.domain.authentication.Authentication;
import com.festago.auth.domain.authentication.MemberAuthentication;
import com.festago.common.exception.UnexpectedException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.auth;

import com.festago.auth.domain.AuthenticateContext;
import com.festago.auth.domain.Role;
import com.festago.common.exception.UnexpectedException;
import org.springframework.core.MethodParameter;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.festago.auth.domain.UserInfo;
import com.festago.auth.domain.UserInfoMemberMapper;
import com.festago.auth.dto.event.MemberDeletedEvent;
import com.festago.auth.dto.v1.LoginResult;
import com.festago.auth.dto.v1.MemberLoginResult;
import com.festago.auth.dto.v1.TokenRefreshResult;
import com.festago.auth.repository.RefreshTokenRepository;
import com.festago.common.exception.ErrorCode;
Expand Down Expand Up @@ -32,11 +32,11 @@ public class MemberAuthCommandService {
private final UserInfoMemberMapper userInfoMemberMapper;
private final Clock clock;

public LoginResult login(UserInfo userInfo) {
public MemberLoginResult login(UserInfo userInfo) {
Member member = memberRepository.findBySocialIdAndSocialType(userInfo.socialId(), userInfo.socialType())
.orElseGet(() -> signUp(userInfo));
RefreshToken refreshToken = saveRefreshToken(member.getId());
return new LoginResult(
return new MemberLoginResult(
member.getId(),
member.getNickname(),
member.getProfileImage(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.festago.auth.application.command;

import com.festago.auth.application.OAuth2Client;
import com.festago.auth.application.OAuth2Clients;
import com.festago.auth.domain.OAuth2Client;
import com.festago.auth.domain.OAuth2Clients;
import com.festago.auth.domain.OpenIdClient;
import com.festago.auth.domain.OpenIdClients;
import com.festago.auth.domain.SocialType;
import com.festago.auth.domain.UserInfo;
import com.festago.auth.domain.authentication.MemberAuthentication;
import com.festago.auth.dto.v1.LoginResult;
import com.festago.auth.dto.v1.LoginV1Response;
import com.festago.auth.dto.v1.MemberLoginResult;
import com.festago.auth.dto.v1.TokenRefreshResult;
import com.festago.auth.dto.v1.TokenRefreshV1Response;
import com.festago.auth.dto.v1.TokenResponse;
import com.festago.auth.infrastructure.MemberAuthenticationTokenProvider;
import com.festago.member.domain.SocialType;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -33,7 +33,7 @@ public LoginV1Response oAuth2Login(SocialType socialType, String code) {
}

private LoginV1Response login(UserInfo userInfo) {
LoginResult loginResult = memberAuthCommandService.login(userInfo);
MemberLoginResult loginResult = memberAuthCommandService.login(userInfo);

TokenResponse accessToken = authTokenProvider.provide(new MemberAuthentication(loginResult.memberId()));
return new LoginV1Response(
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/java/com/festago/auth/config/AuthConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.festago.auth.config;

import com.festago.auth.application.OAuth2Client;
import com.festago.auth.application.OAuth2Clients;
import com.festago.auth.domain.OAuth2Client;
import com.festago.auth.domain.OAuth2Clients;
import com.festago.auth.domain.OpenIdClient;
import com.festago.auth.domain.OpenIdClients;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import com.festago.auth.AdminAuthenticationArgumentResolver;
import com.festago.auth.AnnotationAuthorizationInterceptor;
import com.festago.auth.AuthenticateContext;
import com.festago.auth.FixedAuthorizationInterceptor;
import com.festago.auth.MemberAuthenticationArgumentResolver;
import com.festago.auth.RoleArgumentResolver;
import com.festago.auth.annotation.Authorization;
import com.festago.auth.domain.AuthenticateContext;
import com.festago.auth.domain.AuthenticationTokenExtractor;
import com.festago.auth.domain.Role;
import com.festago.auth.infrastructure.CompositeHttpRequestTokenExtractor;
import com.festago.auth.infrastructure.CookieHttpRequestTokenExtractor;
import com.festago.auth.infrastructure.HeaderHttpRequestTokenExtractor;
import com.festago.auth.infrastructure.web.CompositeHttpRequestTokenExtractor;
import com.festago.auth.infrastructure.web.CookieHttpRequestTokenExtractor;
import com.festago.auth.infrastructure.web.HeaderHttpRequestTokenExtractor;
import com.festago.common.interceptor.AnnotationDelegateInterceptor;
import com.festago.common.interceptor.HttpMethodDelegateInterceptor;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.festago.auth;
package com.festago.auth.domain;

import com.festago.auth.domain.Role;
import com.festago.auth.domain.authentication.AnonymousAuthentication;
import com.festago.auth.domain.authentication.Authentication;
import org.springframework.stereotype.Component;
Expand Down
10 changes: 10 additions & 0 deletions backend/src/main/java/com/festago/auth/domain/OAuth2Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.festago.auth.domain;

import com.festago.member.domain.SocialType;

public interface OAuth2Client {

UserInfo getUserInfo(String code);

SocialType getSocialType();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.festago.auth.application;
package com.festago.auth.domain;

import com.festago.auth.domain.SocialType;
import com.festago.common.exception.BadRequestException;
import com.festago.common.exception.ErrorCode;
import com.festago.common.exception.UnexpectedException;
import com.festago.member.domain.SocialType;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.festago.auth.domain;

import com.festago.member.domain.SocialType;

public interface OpenIdClient {

UserInfo getUserInfo(String idToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.festago.common.exception.BadRequestException;
import com.festago.common.exception.ErrorCode;
import com.festago.common.exception.UnexpectedException;
import com.festago.member.domain.SocialType;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.auth.domain;

import com.festago.member.domain.SocialType;
import lombok.Builder;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.LocalDateTime;
import java.util.UUID;

public record LoginResult(
public record MemberLoginResult(
Long memberId,
String nickname,
String profileImageUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.festago.auth.dto.v1;

import com.festago.auth.domain.SocialType;
import com.festago.member.domain.SocialType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.festago.auth.dto.v1;

import com.festago.auth.domain.SocialType;
import com.festago.member.domain.SocialType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.festago.auth.domain.AuthenticationTokenExtractor;
import com.festago.auth.domain.authentication.Authentication;
import com.festago.auth.infrastructure.jwt.AdminAuthenticationClaimsExtractor;
import com.festago.auth.infrastructure.jwt.JwtTokenParser;
import io.jsonwebtoken.Claims;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.festago.auth.domain.Role;
import com.festago.auth.domain.authentication.AdminAuthentication;
import com.festago.auth.dto.v1.TokenResponse;
import com.festago.auth.infrastructure.jwt.TokenProviderTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class AdminAuthenticationTokenProvider {

private static final String ADMIN_ID_KEY = "adminId";
private static final long EXPIRATION_MINUTES = 60L * 24L;

private final TokenProviderTemplate tokenProviderTemplate;
Expand All @@ -19,7 +19,6 @@ public TokenResponse provide(AdminAuthentication adminAuthentication) {
return tokenProviderTemplate.provide(EXPIRATION_MINUTES,
jwtBuilder -> jwtBuilder
.subject(adminAuthentication.getId().toString())
.claim(ADMIN_ID_KEY, adminAuthentication.getId())
.audience().add(Role.ADMIN.name()).and()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.festago.auth.domain.Role;
import com.festago.auth.domain.authentication.AnonymousAuthentication;
import com.festago.auth.domain.authentication.Authentication;
import com.festago.auth.infrastructure.jwt.AuthenticationClaimsExtractor;
import com.festago.auth.infrastructure.jwt.JwtTokenParser;
import io.jsonwebtoken.Claims;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.festago.auth.domain.AuthenticationTokenExtractor;
import com.festago.auth.domain.authentication.Authentication;
import com.festago.auth.infrastructure.jwt.JwtTokenParser;
import com.festago.auth.infrastructure.jwt.MemberAuthenticationClaimsExtractor;
import io.jsonwebtoken.Claims;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.festago.auth.domain.Role;
import com.festago.auth.domain.authentication.MemberAuthentication;
import com.festago.auth.dto.v1.TokenResponse;
import com.festago.auth.infrastructure.jwt.TokenProviderTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class MemberAuthenticationTokenProvider {

private static final String MEMBER_ID_KEY = "memberId";
private static final long EXPIRATION_MINUTES = 60L * 6L;

private final TokenProviderTemplate tokenProviderTemplate;
Expand All @@ -19,7 +19,6 @@ public TokenResponse provide(MemberAuthentication memberAuthentication) {
return tokenProviderTemplate.provide(EXPIRATION_MINUTES,
jwtBuilder -> jwtBuilder
.subject(memberAuthentication.getId().toString())
.claim(MEMBER_ID_KEY, memberAuthentication.getId())
.audience().add(Role.MEMBER.name()).and()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.auth.infrastructure;
package com.festago.auth.infrastructure.jwt;

import com.festago.auth.domain.Role;
import com.festago.auth.domain.authentication.AdminAuthentication;
Expand All @@ -10,14 +10,12 @@
@Component
public class AdminAuthenticationClaimsExtractor implements AuthenticationClaimsExtractor {

private static final String ADMIN_ID_KEY = "adminId";

@Override
public Authentication extract(Claims claims) {
if (!claims.getAudience().contains(Role.ADMIN.name())) {
return AnonymousAuthentication.getInstance();
}
Long adminId = claims.get(ADMIN_ID_KEY, Long.class);
Long adminId = Long.parseLong(claims.getSubject());
return new AdminAuthentication(adminId);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.auth.infrastructure;
package com.festago.auth.infrastructure.jwt;

import com.festago.auth.domain.authentication.Authentication;
import io.jsonwebtoken.Claims;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.auth.infrastructure;
package com.festago.auth.infrastructure.jwt;

import com.festago.common.exception.ErrorCode;
import com.festago.common.exception.UnauthorizedException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.auth.infrastructure;
package com.festago.auth.infrastructure.jwt;

import com.festago.auth.domain.Role;
import com.festago.auth.domain.authentication.AnonymousAuthentication;
Expand All @@ -10,14 +10,12 @@
@Component
public class MemberAuthenticationClaimsExtractor implements AuthenticationClaimsExtractor {

private static final String MEMBER_ID_KEY = "memberId";

@Override
public Authentication extract(Claims claims) {
if (!claims.getAudience().contains(Role.MEMBER.name())) {
return AnonymousAuthentication.getInstance();
}
Long memberId = claims.get(MEMBER_ID_KEY, Long.class);
Long memberId = Long.parseLong(claims.getSubject());
return new MemberAuthentication(memberId);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.auth.infrastructure;
package com.festago.auth.infrastructure.jwt;

import com.festago.auth.dto.v1.TokenResponse;
import io.jsonwebtoken.JwtBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.festago.auth.infrastructure.oauth2;

import com.festago.auth.application.OAuth2Client;
import com.festago.auth.domain.SocialType;
import com.festago.auth.domain.OAuth2Client;
import com.festago.auth.domain.UserInfo;
import com.festago.common.exception.BadRequestException;
import com.festago.common.exception.ErrorCode;
import com.festago.member.domain.SocialType;
import java.util.HashMap;
import java.util.Map;
import org.springframework.context.annotation.Profile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.festago.auth.infrastructure.oauth2;

import com.festago.auth.application.OAuth2Client;
import com.festago.auth.domain.SocialType;
import com.festago.auth.domain.OAuth2Client;
import com.festago.auth.domain.UserInfo;
import com.festago.auth.infrastructure.openid.KakaoOpenIdClient;
import com.festago.member.domain.SocialType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand Down
Loading

0 comments on commit 8dc1dce

Please sign in to comment.