Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
public class AuthenticationController {

private static final Logger logger = LoggerFactory.getLogger(AuthenticationController.class);
private final SocialSignHandlerMap handlerMap;
private final AccountService accountService;
private final EmailVerificationService emailVerificationService;
private final SocialSignHandlerMap handlerMap;
private final PlayerQueryService playerQueryService;

private final TokenProvider tokenProvider;
private final TokenCookieProvider tokenCookieProvider;
private final TokenGenerator tokenGenerator;
private final TokenProvider tokenProvider;

@GetMapping("/{provider}/url")
@Operation(summary = "소셜 로그인 URL 발급", description = "구글/카카오/네이버/깃허브 로그인 URL을 반환")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.codequistify.master.application.account.controller;

import lombok.RequiredArgsConstructor;
import org.codequistify.master.core.domain.account.model.EmailVerificationType;
import org.codequistify.master.application.account.service.EmailVerificationService;
import org.codequistify.master.core.domain.account.model.EmailVerificationType;
import org.codequistify.master.global.aspect.LogMonitoring;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -16,9 +16,13 @@
@RequiredArgsConstructor
public class EmailVerificationController {
private final EmailVerificationService emailVerificationService;

@GetMapping("home/auth/email/verify")
@LogMonitoring
public String verifyMail(@RequestParam String email, @RequestParam String code, @RequestParam EmailVerificationType type, Model model) {
public String verifyMail(@RequestParam String email,
@RequestParam String code,
@RequestParam EmailVerificationType type,
Model model) {
if (email.isBlank() || code.isBlank() || type == null) {
return "redirect:/home/failure";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@
@Service
@RequiredArgsConstructor
public class AccountService {
private final PlayerQueryService playerQueryService;
private final PlayerProfileService playerProfileService;
private final Logger logger = LoggerFactory.getLogger(AccountService.class);
private final PlayerJpaRepository playerJpaRepository;
private final PlayerPasswordManager playerPasswordManager;
private final PlayerProfileService playerProfileService;
private final PlayerQueryService playerQueryService;
private final PlayerValidator playerValidator;
private final TokenProvider tokenProvider;
private final PlayerJpaRepository playerJpaRepository;

private final Logger logger = LoggerFactory.getLogger(AccountService.class);

@Transactional
@LogMonitoring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
@RequiredArgsConstructor
public class EmailVerificationService {

private final EmailVerificationRepository emailVerificationRepository;
private final EmailVerificationPolicyHandler policyHandler;
private final EmailVerificationCodeManager codeManager;
private final EmailMessageFactory emailMessageFactory;
private final EmailSender emailSender;
private final EmailVerificationCodeManager codeManager;
private final EmailVerificationRepository emailVerificationRepository;
private final Logger logger = LoggerFactory.getLogger(EmailVerificationService.class);

private final EmailVerificationPolicyHandler policyHandler;
@Value("${mail.secret}")
private String mailSecret;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.codequistify.master.application.account.service;

import lombok.RequiredArgsConstructor;
import org.codequistify.master.application.account.vo.*;
import org.codequistify.master.application.account.vo.OAuthProfile;
import org.codequistify.master.application.account.vo.OAuthResource;
import org.codequistify.master.application.account.vo.OAuthToken;
import org.codequistify.master.application.account.vo.ResourceOfGithub;
import org.codequistify.master.application.exception.ApplicationException;
import org.codequistify.master.core.domain.player.model.OAuthType;
import org.codequistify.master.core.domain.player.model.Player;
Expand All @@ -28,10 +31,9 @@ public class GithubSocialSignService implements SocialSignService {

private static final String LOGIN_URL_TEMPLATE =
"https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code&state=%s";

private final RestTemplate restTemplate;
private final OAuthKey oAuthKey;
private final PlayerRepository playerRepository;
private final RestTemplate restTemplate;

@Override
public String getSocialLogInURL() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public class GoogleSocialSignService implements SocialSignService {

private static final String LOGIN_URL_TEMPLATE =
"https://accounts.google.com/o/oauth2/auth?client_id=%s&redirect_uri=%s&response_type=code&scope=email%%20profile";

private final RestTemplate restTemplate;
private final OAuthKey oAuthKey;
private final PlayerRepository playerRepository;
private final RestTemplate restTemplate;

@Override
public String getSocialLogInURL() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ public class KakaoSocialSignService implements SocialSignService {

private static final String LOGIN_URL_TEMPLATE =
"https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=%s&redirect_uri=%s";

private final RestTemplate restTemplate;
private final OAuthKey oAuthKey;
private final PlayerRepository playerRepository;
private final RestTemplate restTemplate;

/**
* 카카오 소셜 로그인 주소 반환
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.codequistify.master.application.account.service;

import lombok.RequiredArgsConstructor;
import org.codequistify.master.application.account.vo.*;
import org.codequistify.master.application.account.vo.OAuthProfile;
import org.codequistify.master.application.account.vo.OAuthResource;
import org.codequistify.master.application.account.vo.OAuthToken;
import org.codequistify.master.application.account.vo.ResourceOfNaver;
import org.codequistify.master.application.exception.ApplicationException;
import org.codequistify.master.core.domain.player.model.OAuthType;
import org.codequistify.master.core.domain.player.model.Player;
Expand All @@ -28,10 +31,9 @@ public class NaverSocialSignService implements SocialSignService {

private static final String LOGIN_URL_TEMPLATE =
"https://nid.naver.com/oauth2.0/authorize?client_id=%s&redirect_uri=%s&response_type=code&state=%s";

private final RestTemplate restTemplate;
private final PlayerRepository playerRepository;
private final OAuthKey oAuthKey;
private final PlayerRepository playerRepository;
private final RestTemplate restTemplate;

/**
* 네이버 소셜 로그인 URL 반환
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

public interface SocialSignService {
String getSocialLogInURL();

Player socialLogIn(OAuthProfile oAuthProfile);

Player socialSignUp(OAuthProfile oAuthProfile);

OAuthProfile getOAuthProfile(String code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

public interface EmailVerificationPolicy {
boolean supports(EmailVerificationType type);

void validate(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
@Component
public class TokenCookieProvider {

private static final String PROD_DOMAIN = "pol.or.kr";
private static final String DEV_DOMAIN = "localhost";
private static final int ACCESS_TOKEN_EXPIRATION_SECONDS = 60 * 60; // 1 hour
private static final String DEV_DOMAIN = "localhost";
private static final String PROD_DOMAIN = "pol.or.kr";
private static final int REFRESH_TOKEN_EXPIRATION_SECONDS = 7 * 24 * 60 * 60; // 7 days

public void addTokenCookies(HttpServletResponse response, TokenResponse token) {
addCookie(response, "POL_ACCESS_TOKEN", token.accessToken(), PROD_DOMAIN, ACCESS_TOKEN_EXPIRATION_SECONDS);
addCookie(response, "POL_REFRESH_TOKEN", token.refreshToken(), PROD_DOMAIN, REFRESH_TOKEN_EXPIRATION_SECONDS);
addCookie(response, "POL_ACCESS_TOKEN_DEV", token.accessToken(), DEV_DOMAIN, ACCESS_TOKEN_EXPIRATION_SECONDS);
addCookie(response, "POL_REFRESH_TOKEN_DEV", token.refreshToken(), DEV_DOMAIN, REFRESH_TOKEN_EXPIRATION_SECONDS);
addCookie(response,
"POL_REFRESH_TOKEN_DEV",
token.refreshToken(),
DEV_DOMAIN,
REFRESH_TOKEN_EXPIRATION_SECONDS);
}

public void removeTokenCookies(HttpServletResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@RequiredArgsConstructor
public class TokenGenerator {

private final TokenProvider tokenProvider;
private final AccountService accountService;
private final TokenProvider tokenProvider;

public TokenResponse generate(Player player) {
String refreshToken = tokenProvider.generateRefreshToken(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
public record ResourceOfKakao(
@JsonProperty("properties") Properties properties
) {
public record Properties(
String id,
String email,
String nickname
) {}

public OAuthResource toOAuthResource() {
return new OAuthResource(
properties.id(),
properties.email(),
properties.nickname()
);
}

public record Properties(
String id,
String email,
String nickname
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
public record ResourceOfNaver(
@JsonProperty("response") Response response
) {
public record Response(
String id,
String email,
String name
) {}

public OAuthResource toOAuthResource() {
return new OAuthResource(
response.id(),
response.email(),
response.name()
);
}

public record Response(
String id,
String email,
String name
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.springframework.http.HttpStatus;

public class ApplicationException extends RuntimeException {
private final HttpStatus httpStatus;
private final ErrorCode errorCode;
private final String detail;
private final ErrorCode errorCode;
private final HttpStatus httpStatus;

public ApplicationException(ErrorCode errorCode, HttpStatus httpStatus) {
super(errorCode.getMessage());
Expand Down Expand Up @@ -43,7 +43,11 @@ public ApplicationException(BusinessException businessException, HttpStatus http
this.detail = businessException.getDetail();
}

public ApplicationException(ErrorCode errorCode, HttpStatus httpStatus, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
public ApplicationException(ErrorCode errorCode,
HttpStatus httpStatus,
Throwable cause,
boolean enableSuppression,
boolean writableStackTrace) {
super(errorCode.getMessage(), cause, enableSuppression, writableStackTrace);
this.httpStatus = httpStatus;
this.errorCode = errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.codequistify.master.application.exception.ApplicationException;
import org.codequistify.master.application.player.service.PlayerCredentialService;
import org.codequistify.master.application.player.dto.UpdatePasswordRequest;
import org.codequistify.master.application.player.service.PlayerCredentialService;
import org.codequistify.master.core.domain.player.model.Player;
import org.codequistify.master.global.aspect.LogMonitoring;
import org.codequistify.master.global.exception.ErrorCode;
Expand All @@ -23,8 +23,8 @@
@RequestMapping("api/players")
public class PlayerCredentialController {

private final PlayerCredentialService playerCredentialService;
private final Logger logger = LoggerFactory.getLogger(PlayerCredentialController.class);
private final PlayerCredentialService playerCredentialService;

@Operation(
summary = "비밀번호 재설정",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@
@RequiredArgsConstructor
public class PlayerCredentialService {

private final Logger logger = LoggerFactory.getLogger(PlayerCredentialService.class);
private final PlayerJpaRepository playerJpaRepository;
private final PlayerPasswordManager playerPasswordManager;

private final Logger logger = LoggerFactory.getLogger(PlayerCredentialService.class);

@Transactional
@LogExecutionTime
public void updatePassword(Player player, UpdatePasswordRequest request) {
Player updated = playerJpaRepository.findByUid(player.getUid().getValue())
.map(PlayerConverter::toDomain)
.map(current -> {
if (!playerPasswordManager.matches(current, request.rawPassword())) {
throw new ApplicationException(ErrorCode.INVALID_EMAIL_OR_PASSWORD, HttpStatus.BAD_REQUEST);
}
return playerPasswordManager.encodePassword(current, request.password());
})
.orElseThrow(() -> new ApplicationException(ErrorCode.PLAYER_NOT_FOUND, HttpStatus.NOT_FOUND));
if (!playerPasswordManager.matches(current, request.rawPassword())) {
throw new ApplicationException(ErrorCode.INVALID_EMAIL_OR_PASSWORD,
HttpStatus.BAD_REQUEST);
}
return playerPasswordManager.encodePassword(current,
request.password());
})
.orElseThrow(() -> new ApplicationException(ErrorCode.PLAYER_NOT_FOUND,
HttpStatus.NOT_FOUND));

playerJpaRepository.save(PlayerConverter.toEntity(updated));
logger.info("[updatePassword] Player: {}, 비밀번호 변경 성공", updated.getUid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public Player findOneByUid(PolId uid) {
return playerJpaRepository.findByUid(uid.getValue())
.map(PlayerConverter::toDomain)
.orElseThrow(() -> {
logger.warn("[findOneByUid] 존재하지 않는 player. uid={}", uid);
return new ApplicationException(ErrorCode.PLAYER_NOT_FOUND, HttpStatus.NOT_FOUND);
});
logger.warn("[findOneByUid] 존재하지 않는 player. uid={}", uid);
return new ApplicationException(ErrorCode.PLAYER_NOT_FOUND, HttpStatus.NOT_FOUND);
});
}

/**
Expand All @@ -44,9 +44,9 @@ public Player findOneByEmail(String email) {
return playerJpaRepository.findByEmail(email)
.map(PlayerConverter::toDomain)
.orElseThrow(() -> {
logger.warn("[findOneByEmail] 존재하지 않는 email. email={}", email);
return new ApplicationException(ErrorCode.PLAYER_NOT_FOUND, HttpStatus.NOT_FOUND);
});
logger.warn("[findOneByEmail] 존재하지 않는 email. email={}", email);
return new ApplicationException(ErrorCode.PLAYER_NOT_FOUND, HttpStatus.NOT_FOUND);
});
}

/**
Expand All @@ -56,9 +56,9 @@ public Player findOneByEmail(String email) {
public OAuthType findOAuthTypeByEmail(String email) {
return playerJpaRepository.getOAuthTypeByEmail(email)
.orElseThrow(() -> {
logger.warn("[findOAtuhTypebyEmail] 존재하지 않는 email, email={}", email);
return new ApplicationException(ErrorCode.PLAYER_NOT_FOUND, HttpStatus.NOT_FOUND);
});
logger.warn("[findOAtuhTypebyEmail] 존재하지 않는 email, email={}", email);
return new ApplicationException(ErrorCode.PLAYER_NOT_FOUND, HttpStatus.NOT_FOUND);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Controller
public class HomeController {
@GetMapping(value = {"", "index", "home"})
public String home(){
public String home() {
return "index";
}
}
Loading