Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/MEME-UMC/MEME_AUTH into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
sunwupark committed Feb 15, 2024
2 parents d590f0a + f14e306 commit 97eecf5
Show file tree
Hide file tree
Showing 33 changed files with 503 additions and 292 deletions.
File renamed without changes.
34 changes: 20 additions & 14 deletions src/main/java/umc/meme/auth/domain/artist/entity/Artist.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import umc.meme.auth.domain.artist.entity.enums.Category;
import umc.meme.auth.domain.artist.entity.enums.MakeupLocation;
import umc.meme.auth.domain.artist.entity.enums.Region;
import umc.meme.auth.domain.artist.entity.enums.WorkExperience;
import umc.meme.auth.global.enums.Category;
import umc.meme.auth.global.enums.MakeupLocation;
import umc.meme.auth.global.enums.Region;
import umc.meme.auth.global.enums.WorkExperience;
import umc.meme.auth.domain.user.entity.User;
import umc.meme.auth.domain.user.dto.UserRequest;
import umc.meme.auth.global.enums.DayOfWeek;
Expand All @@ -22,7 +22,6 @@
@Getter @Setter
@AllArgsConstructor
@NoArgsConstructor
@DiscriminatorValue(value = "Artist")
@Entity
public class Artist extends User {

Expand Down Expand Up @@ -64,14 +63,21 @@ public void update(UserRequest.ArtistExtraDto joinDto) {
this.profileImg = joinDto.getProfileImg();
if (joinDto.getNickname() != null)
this.nickname = joinDto.getNickname();

// 여기서 유효성 검증을 어떻게 하지
this.introduction = joinDto.getIntroduction();
this.workExperience = joinDto.getWorkExperience();
this.region = joinDto.getRegion();
this.specialization = joinDto.getSpecialization();
this.makeupLocation = joinDto.getMakeupLocation();
this.shopLocation = joinDto.getShopLocation();
this.availableDayOfWeekAndTime = joinDto.getAvailableDayOfWeekAndTime();
if (joinDto.getGender() != null)
this.gender = joinDto.getGender();
if (joinDto.getIntroduction() != null)
this.introduction = joinDto.getIntroduction();
if (joinDto.getWorkExperience() != null)
this.workExperience = joinDto.getWorkExperience();
if (joinDto.getRegion() != null)
this.region = joinDto.getRegion();
if (joinDto.getSpecialization() != null)
this.specialization = joinDto.getSpecialization();
if (joinDto.getMakeupLocation() != null)
this.makeupLocation = joinDto.getMakeupLocation();
if (joinDto.getShopLocation() != null)
this.shopLocation = joinDto.getShopLocation();
if (joinDto.getAvailableDayOfWeekAndTime() != null)
this.availableDayOfWeekAndTime = joinDto.getAvailableDayOfWeekAndTime();
}
}

This file was deleted.

5 changes: 2 additions & 3 deletions src/main/java/umc/meme/auth/domain/model/entity/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import umc.meme.auth.domain.model.entity.enums.PersonalColor;
import umc.meme.auth.domain.model.entity.enums.SkinType;
import umc.meme.auth.global.enums.PersonalColor;
import umc.meme.auth.global.enums.SkinType;
import umc.meme.auth.domain.user.entity.User;

@SuperBuilder @Getter
@NoArgsConstructor
@AllArgsConstructor
@DiscriminatorValue(value = "Model")
@Entity
public class Model extends User {

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/umc/meme/auth/domain/token/entity/Token.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package umc.meme.auth.domain.token.entity;

import jakarta.persistence.Id;
import lombok.Builder;

import java.io.Serializable;

@Builder
public class Token implements Serializable {

@Id
private String accessToken;

private String refreshToken;

public Token(String accessToken, String refreshToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public class UserController {
private final UserService userService;

@Operation(summary = "모델 회원가입", description = "모델이 회원가입할때 사용하는 API입니다.")
@PostMapping("/api/v0/auth/model/signup")
@PostMapping("/api/v1/signup/model")
public BaseResponseDto<UserResponse.JoinSuccessDto> modelSignUp(@RequestBody UserRequest.ModelJoinDto joinDto) {
return BaseResponseDto.SuccessResponse(SuccessStatus.MODEL_JOIN_SUCCESS, userService.modelSignUp(joinDto));
}

@Operation(summary = "아티스트 회원가입", description = "아티스트가 회원가입할때 사용하는 API입니다.")
@PostMapping("/api/v0/auth/artist/signup")
@PostMapping("/api/v1/signup/artist")
public BaseResponseDto<UserResponse.JoinSuccessDto> artistSignUp(@RequestBody UserRequest.ArtistJoinDto joinDto) {
return BaseResponseDto.SuccessResponse(SuccessStatus.ARTIST_JOIN_SUCCESS, userService.artistSignUp(joinDto));
}

@Operation(summary = "아티스트 추가 회원가입", description = "아티스트가 회원가입하고 추가 정보를 입력할때 사용하는 API입니다.")
@PostMapping("/api/v0/auth/artist/extra")
@PostMapping("/api/v1/signup/artist/extra")
public BaseResponseDto<?> artistExtra(@RequestBody UserRequest.ArtistExtraDto joinDto) {
userService.artistExtra(joinDto);
return BaseResponseDto.SuccessResponse(SuccessStatus.ARTIST_EXTRA_JOIN_SUCCESS);
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/umc/meme/auth/domain/user/dto/UserRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import umc.meme.auth.domain.artist.entity.enums.*;
import umc.meme.auth.domain.model.entity.enums.PersonalColor;
import umc.meme.auth.domain.model.entity.enums.SkinType;
import umc.meme.auth.global.enums.DayOfWeek;
import umc.meme.auth.global.enums.Provider;
import umc.meme.auth.global.enums.Times;
import umc.meme.auth.global.enums.PersonalColor;
import umc.meme.auth.global.enums.SkinType;
import umc.meme.auth.global.enums.*;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -53,12 +50,11 @@ public static class ArtistJoinDto {
@AllArgsConstructor
public static class ArtistExtraDto {
private Long userId;

private String profileImg;
private String nickname;
private Gender gender;
private String introduction;
private WorkExperience workExperience;

private List<Region> region;
private List<Category> specialization;
private MakeupLocation makeupLocation;
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/umc/meme/auth/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import umc.meme.auth.domain.artist.entity.enums.Gender;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import umc.meme.auth.global.enums.Gender;
import umc.meme.auth.global.enums.Provider;
import umc.meme.auth.global.enums.UserStatus;

import java.time.LocalDate;
import java.time.LocalDateTime;

@SuperBuilder @Getter
@NoArgsConstructor
@AllArgsConstructor
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn
@Entity
public class User {

Expand Down Expand Up @@ -47,11 +49,17 @@ public class User {

@Enumerated(EnumType.STRING)
@Column(nullable = true)
private Gender gender;
protected Gender gender;

@Column(nullable = true)
private LocalDate inactiveDate;

@CreatedDate
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;

@Enumerated(EnumType.STRING)
@NotNull
private UserStatus userStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
import org.springframework.transaction.annotation.Transactional;
import umc.meme.auth.domain.artist.entity.Artist;
import umc.meme.auth.domain.artist.entity.ArtistRepository;
import umc.meme.auth.domain.artist.entity.enums.Gender;
import umc.meme.auth.domain.model.entity.Model;
import umc.meme.auth.domain.model.entity.ModelRepository;
import umc.meme.auth.domain.model.entity.enums.PersonalColor;
import umc.meme.auth.domain.model.entity.enums.SkinType;
import umc.meme.auth.domain.user.dto.UserRequest;
import umc.meme.auth.domain.user.dto.UserResponse;
import umc.meme.auth.global.common.status.ErrorStatus;
import umc.meme.auth.global.config.SecurityConfig;
import umc.meme.auth.global.enums.Provider;
import umc.meme.auth.global.enums.UserStatus;
import umc.meme.auth.global.exception.handler.MemberHandler;

import java.time.LocalDate;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/umc/meme/auth/global/auth/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
import umc.meme.auth.global.common.BaseResponseDto;
import umc.meme.auth.global.common.status.ErrorStatus;
import umc.meme.auth.global.common.status.SuccessStatus;
import umc.meme.auth.global.exception.handler.AuthException;

@RequiredArgsConstructor
@RestController
public class AuthController {

private final AuthService authService;

@PostMapping("/api/v0/auth/login")
public BaseResponseDto<AuthResponse.TokenDto> login(@RequestBody AuthRequest.LoginDto loginDto) {
@PostMapping("/api/v1/login")
public BaseResponseDto<AuthResponse.TokenDto> login(@RequestBody AuthRequest.LoginDto loginDto) throws AuthException {
return BaseResponseDto.SuccessResponse(SuccessStatus.LOGIN_SUCCESS, authService.login(loginDto));
}

@PostMapping("/api/v0/auth/reissue")
@PostMapping("/api/v1/reissue")
public BaseResponseDto<?> reissue(@RequestBody AuthRequest.ReissueDto reissueDto) {
AuthResponse.TokenDto reissueResult = authService.reissue(reissueDto);

Expand All @@ -32,13 +33,13 @@ public BaseResponseDto<?> reissue(@RequestBody AuthRequest.ReissueDto reissueDto
return BaseResponseDto.SuccessResponse(SuccessStatus.REISSUE_SUCCESS, reissueResult);
}

@PostMapping("/api/v0/auth/logout")
@PostMapping("/api/v1/auth/logout")
public BaseResponseDto<?> logout(@RequestHeader("Authorization") AuthRequest.AccessTokenDto requestAccessTokenDto) {
authService.logout(requestAccessTokenDto);
return BaseResponseDto.SuccessResponse(SuccessStatus.LOGOUT_SUCCESS);
}

@PostMapping("/api/v0/auth/withdraw")
@PostMapping("/api/v1/auth/withdraw")
public BaseResponseDto<?> withdraw(@RequestHeader("Authorization") AuthRequest.AccessTokenDto requestAccessTokenDto) {
authService.withdraw(requestAccessTokenDto);
return BaseResponseDto.SuccessResponse(SuccessStatus.WITHDRAW_SUCCESS);
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/umc/meme/auth/global/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
import umc.meme.auth.domain.user.entity.UserRepository;
import umc.meme.auth.global.auth.dto.AuthRequest;
import umc.meme.auth.global.auth.dto.AuthResponse;
import umc.meme.auth.global.common.status.ErrorStatus;
import umc.meme.auth.global.exception.handler.AuthException;
import umc.meme.auth.global.exception.handler.JwtHandler;
import umc.meme.auth.global.infra.RedisRepository;
import umc.meme.auth.global.jwt.JwtTokenProvider;
import umc.meme.auth.global.oauth.OAuthService;
import umc.meme.auth.global.oauth.apple.AppleAuthService;
import umc.meme.auth.global.oauth.kakao.KakaoAuthService;

Expand All @@ -32,18 +36,17 @@ public class AuthService {
private final PrincipalDetailsService principalDetailsService;
private final JwtTokenProvider jwtTokenProvider;
private final TokenRepository tokenRepository;
private final KakaoAuthService kakaoAuthService;
private final AppleAuthService appleAuthService;
private final UserRepository userRepository;
private final RedisRepository redisRepository;

private final static String TOKEN_PREFIX = "Bearer ";

@Transactional
public AuthResponse.TokenDto login(AuthRequest.LoginDto loginDto) {
public AuthResponse.TokenDto login(AuthRequest.LoginDto loginDto) throws AuthException {
String userName;
Authentication authentication;
try {
User userInfo = kakaoAuthService.getUserInfo(loginDto.getId_token());
User userInfo = getUser(loginDto);
userName = userInfo.getUsername();
authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(userInfo.getUsername(), userInfo.getEmail()));
SecurityContextHolder.getContext().setAuthentication(authentication);
Expand All @@ -53,13 +56,29 @@ public AuthResponse.TokenDto login(AuthRequest.LoginDto loginDto) {
throw new LockedException("LOCKED_EXCEPTION", exception);
} catch (BadCredentialsException exception) {
throw new BadCredentialsException("BAD_CREDENTIALS_EXCEPTION", exception);
} catch (AuthException exception) {
throw exception;
}

UserDetails userDetails = principalDetailsService.loadUserByUsername(userName);
AuthResponse.TokenDto tokenDto = generateToken(userDetails.getUsername(), getAuthorities(authentication));
return tokenDto;
}

private User getUser(AuthRequest.LoginDto loginDto) throws AuthException {
OAuthService oAuthService;

if (loginDto.getProvider().equals("KAKAO")) {
oAuthService = new KakaoAuthService(userRepository, redisRepository);
} else if (loginDto.getProvider().equals("APPLE")) {
oAuthService = new AppleAuthService(userRepository, redisRepository);
} else {
throw new AuthException(ErrorStatus.PROVIDER_ERROR);
}

return oAuthService.getUserInfo(loginDto.getId_token());
}

@Transactional
public AuthResponse.TokenDto reissue(AuthRequest.ReissueDto reissueDto) {
String requestAccessToken = reissueDto.getAccessToken();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package umc.meme.auth.global.common.status;

import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.coyote.http2.HpackDecoder;
import org.springframework.http.HttpStatus;
import umc.meme.auth.global.common.BaseErrorCode;
import umc.meme.auth.global.common.ErrorReasonDto;
Expand Down Expand Up @@ -42,7 +45,19 @@ public enum ErrorStatus implements BaseErrorCode {
TOKEN_MISMATCH_EXCEPTION(HttpStatus.UNAUTHORIZED, 401, "사용자가 일치하지 않습니다"),
INVALID_SIGNATURE_EXCEPTION(HttpStatus.BAD_REQUEST,400,"잘못된 JWT 서명입니다."),

CANNOT_REISSUE_JWT_TOKEN(HttpStatus.BAD_REQUEST, 404, "토큰 재발급을 진행할 수 없습니다.");
CANNOT_REISSUE_JWT_TOKEN(HttpStatus.BAD_REQUEST, 404, "토큰 재발급을 진행할 수 없습니다."),

// 에러 모음
UNSUPPORTED_JWT_EXCEPTION(HttpStatus.UNAUTHORIZED, 401, "지원하지 않은 JWT 입니다."),
MALFORMED_JWT_EXCEPTION(HttpStatus.UNAUTHORIZED, 401, "올바르지 않은 JWT 입니다."),
SIGNATURE_EXCEPTION(HttpStatus.UNAUTHORIZED, 401, "JWT 토큰 서명 오류입니다."),
EXPIRED_JWT_EXCEPTION(HttpStatus.UNAUTHORIZED, 401, "만료된 JWT 토큰 입니다."),
ILLEGAL_ARGUMENT_EXCEPTION(HttpStatus.UNAUTHORIZED, 401, "올바르지 않은 JWT 입니다."),
GENERAL_SECURITY_EXCEPTION(HttpStatus.UNAUTHORIZED, 401, "공개 키 서명 오류입니다."),
NOT_FOUND(HttpStatus.NOT_FOUND, 404, "요청한 주소로 응답을 받을 수 없습니다."),

PROVIDER_ERROR(HttpStatus.UNAUTHORIZED, 401, "지정한 소셜 로그인 방식을 찾을 수 없습니다."),
KEY_NOT_FOUND(HttpStatus.NOT_FOUND, 404, "일치하는 Web Key를 찾을 수 없습니다.");


private final HttpStatus httpStatus;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/umc/meme/auth/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
)
.authorizeHttpRequests((authorizeHttpRequests) ->
authorizeHttpRequests
.requestMatchers("/api/v0/auth/model/signup").permitAll()
.requestMatchers("/api/v0/auth/artist/signup").permitAll()
.requestMatchers("/api/v0/auth/artist/extra").permitAll()
.requestMatchers("/api/v0/auth/login").permitAll()
.requestMatchers("/api/v0/auth/logout").permitAll()
.requestMatchers("/api/v0/auth/withdraw").permitAll()
.requestMatchers("/api/v0/auth/reissue").permitAll()
.requestMatchers("/api/v1/signup/model").permitAll()
.requestMatchers("/api/v1/signup/artist").permitAll()
.requestMatchers("/api/v1/signup/artist/extra").permitAll()
.requestMatchers("/api/v1/login").permitAll()
.requestMatchers("/api/v1/reissue").permitAll()
.requestMatchers("/api/v1/auth/logout").permitAll()
.requestMatchers("/api/v1/auth/withdraw").permitAll()
.requestMatchers("/auth/**").permitAll()
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package umc.meme.auth.domain.artist.entity.enums;
package umc.meme.auth.global.enums;

public enum Category {
DAILY("daily"), INTERVIEW("interview"), ACTOR("actor"), PARTY("party"),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/umc/meme/auth/global/enums/Gender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package umc.meme.auth.global.enums;

public enum Gender {
MALE, FEMALE
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package umc.meme.auth.domain.artist.entity.enums;
package umc.meme.auth.global.enums;

public enum MakeupLocation {
SHOP, VISIT, BOTH
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package umc.meme.auth.domain.model.entity.enums;
package umc.meme.auth.global.enums;

public enum PersonalColor {
SPRING, SUMMER, AUTUMN, WINTER
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package umc.meme.auth.domain.artist.entity.enums;
package umc.meme.auth.global.enums;

public enum Region {
JONGNO("jongno"), JUNG("jung"), YONGSAN("yongsan"), SEONGDONG("seongdong"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package umc.meme.auth.domain.model.entity.enums;
package umc.meme.auth.global.enums;

public enum SkinType {
DRY, COMMON, OILY, COMBINATIONAL
Expand Down
Loading

0 comments on commit 97eecf5

Please sign in to comment.