diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/HealthCheckController.java b/WableServer/src/main/java/com/wable/www/WableServer/api/HealthCheckController.java index cabe9a4..df55d5e 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/HealthCheckController.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/HealthCheckController.java @@ -1,23 +1,28 @@ package com.wable.www.WableServer.api; +import com.wable.www.WableServer.common.config.jwt.AdminConfig; import com.wable.www.WableServer.common.response.ApiResponse; import com.wable.www.WableServer.common.response.ErrorStatus; import com.wable.www.WableServer.common.util.MemberUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import java.security.Principal; +import java.util.List; @RestController +@RequiredArgsConstructor @Tag(name = "HealthCheck Controller", description = "HealthCheck API Document") @SecurityRequirement(name = "JWT Auth") public class HealthCheckController { + private final AdminConfig adminConfig; @GetMapping("health") @Operation(summary = "HealthCheck", description = "HealthCheck API입니다.") public Long healthCheck(Principal principal) { @@ -30,4 +35,15 @@ public Long healthCheck(Principal principal) { public ApiResponse test() throws Exception { throw new Exception(ErrorStatus.INTERNAL_SERVER_ERROR.getMessage()); } + + @GetMapping("admin/test") + public Boolean isAdmin(Principal principal) { + Long memberId = MemberUtil.getMemberId(principal); + return isAllowedId(memberId); + } + + public boolean isAllowedId(Long id) { + List allowedIds = adminConfig.getAllowedIds(); + return allowedIds.contains(id); + } } diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/auth/dto/response/AuthResponseDto.java b/WableServer/src/main/java/com/wable/www/WableServer/api/auth/dto/response/AuthResponseDto.java index 7586b21..45c2b56 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/auth/dto/response/AuthResponseDto.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/auth/dto/response/AuthResponseDto.java @@ -28,4 +28,6 @@ public class AuthResponseDto { private int memberLckYears; private int memberLevel; + + private Boolean isAdmin; } diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/auth/service/Impl/AuthServiceImpl.java b/WableServer/src/main/java/com/wable/www/WableServer/api/auth/service/Impl/AuthServiceImpl.java index 9ab2685..e4480b5 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/auth/service/Impl/AuthServiceImpl.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/auth/service/Impl/AuthServiceImpl.java @@ -10,6 +10,7 @@ import com.wable.www.WableServer.api.auth.service.KakaoAuthService; import com.wable.www.WableServer.api.member.domain.Member; import com.wable.www.WableServer.api.member.repository.MemberRepository; +import com.wable.www.WableServer.common.config.jwt.AdminConfig; import com.wable.www.WableServer.common.exception.BadRequestException; import com.wable.www.WableServer.common.response.ErrorStatus; import com.wable.www.WableServer.common.config.jwt.JwtTokenProvider; @@ -25,6 +26,7 @@ import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; +import java.util.List; import java.util.Objects; @Service @@ -38,6 +40,7 @@ public class AuthServiceImpl implements AuthService { private final MemberRepository memberRepository; private final SlackService slackService; private final Environment environment; + private final AdminConfig adminConfig; @Override @Transactional @@ -73,9 +76,11 @@ public AuthResponseDto socialLogin(String socialAccessToken, AuthRequestDto auth int memberLevel = MemberUtil.refineMemberExpToLevel(member.getMemberExp()); + boolean isAdmin = isAdmin(member.getId()); + return AuthResponseDto.of(member.getNickname(), member.getId(), accessToken, refreshToken, member.getProfileUrl(), true, member.getIsPushAlarmAllowed(), member.getMemberFanTeam(), member.getMemberLckYears(), - memberLevel); + memberLevel, isAdmin); } else { @@ -98,9 +103,11 @@ public AuthResponseDto socialLogin(String socialAccessToken, AuthRequestDto auth int signedMemberLevel = MemberUtil.refineMemberExpToLevel(signedMember.getMemberExp()); + boolean isAdmin = isAdmin(signedMember.getId()); + return AuthResponseDto.of(signedMember.getNickname(), signedMember.getId(), accessToken, refreshToken, signedMember.getProfileUrl(), false, signedMember.getIsPushAlarmAllowed(), - signedMember.getMemberFanTeam(), signedMember.getMemberLckYears(), signedMemberLevel); + signedMember.getMemberFanTeam(), signedMember.getMemberLckYears(), signedMemberLevel, isAdmin); } } catch (IllegalArgumentException ex) { throw new IllegalArgumentException(ErrorStatus.ANOTHER_ACCESS_TOKEN.getMessage()); @@ -135,4 +142,9 @@ private SocialInfoDto getSocialData(SocialPlatform socialPlatform, String social throw new IllegalArgumentException(ErrorStatus.ANOTHER_ACCESS_TOKEN.getMessage()); } } + + private boolean isAdmin(Long memberId) { + List allowedIds = adminConfig.getAllowedIds(); + return allowedIds.contains(memberId); + } } diff --git a/WableServer/src/main/java/com/wable/www/WableServer/common/config/jwt/AdminConfig.java b/WableServer/src/main/java/com/wable/www/WableServer/common/config/jwt/AdminConfig.java new file mode 100644 index 0000000..c33333d --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/common/config/jwt/AdminConfig.java @@ -0,0 +1,21 @@ +package com.wable.www.WableServer.common.config.jwt; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +@Configuration +@ConfigurationProperties(prefix = "admin-config") +public class AdminConfig { + + private List allowedIds; + + public List getAllowedIds() { + return allowedIds; + } + + public void setAllowedIds(List allowedIds) { + this.allowedIds = allowedIds; + } +} \ No newline at end of file