Skip to content

Commit

Permalink
Merge pull request #182 from GEON-PPANG/feature/#178
Browse files Browse the repository at this point in the history
[FEAT] 소셜&자체 통합 회원탈퇴 로직 구현
  • Loading branch information
sung-silver authored Sep 2, 2023
2 parents 1af8244 + 142070f commit e940b74
Show file tree
Hide file tree
Showing 32 changed files with 291 additions and 163 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
## create application.yml in client module
mkdir ./client/src/main/resources
cd ./client/src/main/resources
mkdir ./client/client-feign/src/main/resources
cd ./client/client-feign/src/main/resources
touch ./application.yml
touch ./client.yml
ls -al
Expand All @@ -63,14 +63,9 @@ jobs:
echo "${{ secrets.GUNBBANG_SECRET_API_APPLICATION_YML }}" >> ./api/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_DB_CORE_APPLICATION_YML }}" >> ./storage/db-core/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_DB_CORE }}" >> ./storage/db-core/src/main/resources/db-core.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT }}" >> ./client/src/main/resources/client.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT_APPLICATION_YML }}" >> ./client/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT }}" >> ./client/client-feign/src/main/resources/client.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT_APPLICATION_YML }}" >> ./client/client-feign/src/main/resources/application.yml
pwd
# application.yml 파일 확인
cat ./api/src/main/resources/application.yml
cat ./client/src/main/resources/application.yml
cat ./storage/db-core/src/main/resources/application.yml
shell: bash

Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ jobs:
## create application.yml in client module
mkdir ./client/src/main/resources
cd ./client/src/main/resources
mkdir ./client/client-feign/src/main/resources
cd ./client/client-feign/src/main/resources
touch ./application.yml
touch ./client.yml
ls -al
Expand All @@ -75,14 +75,9 @@ jobs:
echo "${{ secrets.GUNBBANG_SECRET_API_APPLICATION_YML }}" >> ./api/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_DB_CORE_APPLICATION_YML }}" >> ./storage/db-core/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_DB_CORE }}" >> ./storage/db-core/src/main/resources/db-core.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT }}" >> ./client/src/main/resources/client.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT_APPLICATION_YML }}" >> ./client/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT }}" >> ./client/client-feign/src/main/resources/client.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT_APPLICATION_YML }}" >> ./client/client-feign/src/main/resources/application.yml
pwd
# application.yml 파일 확인
cat ./api/src/main/resources/application.yml
cat ./client/src/main/resources/application.yml
cat ./storage/db-core/src/main/resources/application.yml
shell: bash

Expand Down
4 changes: 3 additions & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation project(':common:domain')
implementation project(':common:util')
implementation project (path: ':storage:db-core')
implementation project(':client')
implementation project(':client:client-feign')
implementation "org.springframework.boot:spring-boot-starter-data-jpa" // 이거 개선해야됨
implementation "org.springframework.security:spring-security-web"
implementation "org.springframework.security:spring-security-config"
Expand All @@ -42,6 +42,8 @@ dependencies {
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
// annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0"
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ private void setInputStream(JoinPoint joinPoint, ObjectMapper objectMapper) {
if (parameterNames[i].equals("request")) {
this.body = args[i].toString();
} else {
this.parameters = args[i].toString();
if (args[i] != null) {
this.parameters = args[i].toString();
}
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.org.gunbbang"})
@EnableJpaAuditing
@EnableConfigurationProperties
public class GunbbangApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public ApiResponse<MemberSignUpResponseDTO> signUp(
}

@DeleteMapping("/withdraw")
public ApiResponse<MemberWithdrawResponseDTO> withdraw() {
public ApiResponse<MemberWithdrawResponseDTO> withdraw(
@RequestHeader(name = "Apple-refresh", required = false) String appleRefreshToken)
throws Exception {
Long memberId = SecurityUtil.getLoginMemberId();
return ApiResponse.success(SuccessType.DELETE_MEMBER_SUCCESS, memberService.withdraw(memberId));
return ApiResponse.success(
SuccessType.DELETE_MEMBER_SUCCESS, memberService.withdraw(memberId, appleRefreshToken));
}
}
11 changes: 0 additions & 11 deletions api/src/main/java/com/org/gunbbang/controller/DTO/FileDTO.java

This file was deleted.

13 changes: 0 additions & 13 deletions api/src/main/java/com/org/gunbbang/controller/DTO/FilesDTO.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.org.gunbbang.AOP.annotation.SearchApiLog;
import com.org.gunbbang.common.dto.ApiResponse;
import com.org.gunbbang.controller.DTO.response.BakerySearchResponseDTO;
import com.org.gunbbang.controller.DTO.response.BakerySearchResponseDTOV2;
import com.org.gunbbang.errorType.SuccessType;
import com.org.gunbbang.service.BakeryService;
import com.org.gunbbang.util.security.SecurityUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -26,14 +24,4 @@ public ApiResponse<BakerySearchResponseDTO> searchBakery(@RequestParam final Str
return ApiResponse.success(
SuccessType.SEARCH_BAKERIES_SUCCESS, bakeryService.getBakeriesBySearch(searchTerm.trim()));
}

@GetMapping("/v2/bakeries")
@SearchApiLog
public ApiResponse<BakerySearchResponseDTOV2> searchBakeryV2(
@RequestParam final String bakeryName) {
Long memberId = SecurityUtil.getLoginMemberId();
return ApiResponse.success(
SuccessType.SEARCH_BAKERIES_SUCCESS,
bakeryService.getBakeriesByNameV2(bakeryName.strip(), memberId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public void saveAuthentication(Member myMember) {
myMember.getMainPurpose(),
myMember.getBreadType().getBreadTypeId(),
myMember.getNutrientType().getNutrientTypeId(),
myMember.getNickname());
myMember.getNickname(),
myMember.getRole().toString());

System.out.println("엑세스 요청 성공 시 userDetails: " + userDetailsUser);

Authentication authentication =
new UsernamePasswordAuthenticationToken(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.org.gunbbang.jwt.service;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import java.security.KeyFactory;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.time.Instant;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Getter
@Slf4j
public class AppleJWTService {
@Value("${apple.api.key-id}")
private String keyId;

@Value("${apple.api.client-id}")
private String clientId;

@Value("${apple.api.team-id}")
private String teamId;

@Value("${apple.api.private-key}")
private String privateKey;

private static final String url = "https://appleid.apple.com";
private static final String alg = "ES256";

public String createAppleSecret() throws Exception {
try {
Map<String, Object> appleSecretHeader = new HashMap<>();
appleSecretHeader.put("alg", alg);
appleSecretHeader.put("kid", keyId);

long now = Instant.now().getEpochSecond();
String appleSecret =
JWT.create()
.withHeader(appleSecretHeader)
.withClaim("iss", teamId)
.withClaim("iat", now)
.withClaim("exp", now + 180)
.withClaim("aud", url)
.withClaim("sub", clientId)
.sign(Algorithm.ECDSA256(stringToECPrivateKey(privateKey)));
System.out.println("appleSecret 생성: " + appleSecret);
return appleSecret;
} catch (Exception e) {
log.warn("apple secret 키를 발급하는데 에러가 발생했습니다 " + e.getMessage());
throw e;
}
}

private ECPrivateKey stringToECPrivateKey(String privateKey) throws Exception {
try {
byte[] decodedKey = Base64.getDecoder().decode(privateKey); // privateKey를 디코딩
KeyFactory keyFactory = KeyFactory.getInstance("EC");
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedKey);
return (ECPrivateKey) keyFactory.generatePrivate(keySpec);
} catch (Exception e) {
log.warn("apple private 키를 ECPrivateKey로 변환하는데 에러가 발생했습니다 " + e.getMessage());
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@Getter
@Slf4j
public class JwtService {

@Value("${jwt.secretKey}")
private String secretKey;

Expand Down
37 changes: 33 additions & 4 deletions api/src/main/java/com/org/gunbbang/login/CustomUserDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CustomUserDetails implements UserDetails {
private Long breadTypeId;
private Long nutrientTypeId;
private String nickName;
private String role;

public CustomUserDetails(
String username,
Expand All @@ -26,23 +27,23 @@ public CustomUserDetails(
MainPurpose mainPurpose,
Long breadTypeId,
Long nutrientTypeId,
String nickname) {
String nickname,
String role) {
this.username = username;
this.password = password;
this.memberId = memberId;
this.mainPurpose = mainPurpose;
this.breadTypeId = breadTypeId;
this.nutrientTypeId = nutrientTypeId;
this.nickName = nickname;
this.role = role;
}

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
List<GrantedAuthority> auth = new ArrayList<>();
auth.add(new SimpleGrantedAuthority("USER"));
auth.add(new SimpleGrantedAuthority("Guest"));
auth.add(new SimpleGrantedAuthority(this.role));
return auth;
// return null;
}

@Override
Expand Down Expand Up @@ -94,4 +95,32 @@ public boolean isCredentialsNonExpired() {
public boolean isEnabled() {
return enabled;
}

@Override
public String toString() {
return "CustomUserDetails{"
+ "username='"
+ username
+ '\''
+ ", memberId="
+ memberId
+ ", password='"
+ password
+ '\''
+ ", enabled="
+ enabled
+ ", mainPurpose="
+ mainPurpose
+ ", breadTypeId="
+ breadTypeId
+ ", nutrientTypeId="
+ nutrientTypeId
+ ", nickName='"
+ nickName
+ '\''
+ ", role='"
+ role
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;

Expand All @@ -35,8 +34,6 @@ public void onAuthenticationSuccess(
jwtService.sendAccessAndRefreshToken(response, accessToken, refreshToken);
jwtService.updateRefreshToken(email, refreshToken);
log.info("로그인 요청 성공. 이메일 : {} || memberId : {} ", email, memberId);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
log.info("auth: {}", auth.toString());
}

private String extractUsername(Authentication authentication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundEx
.findByEmail(userName)
.orElseThrow(() -> new UsernameNotFoundException("해당 이메일이 존재하지 않습니다."));

return new CustomUserDetails(
member.getEmail(),
member.getPassword(),
member.getMemberId(),
member.getMainPurpose(),
member.getBreadType().getBreadTypeId(),
member.getNutrientType().getNutrientTypeId(),
member.getNickname());
CustomUserDetails userDetailsUser =
new CustomUserDetails(
member.getEmail(),
member.getPassword(),
member.getMemberId(),
member.getMainPurpose(),
member.getBreadType().getBreadTypeId(),
member.getNutrientType().getNutrientTypeId(),
member.getNickname(),
member.getRole().toString());

System.out.println("로그인 요청 시 userDetails: " + userDetailsUser);
return userDetailsUser;
}
}
Loading

0 comments on commit e940b74

Please sign in to comment.