Skip to content

Commit

Permalink
Merge pull request #43 from Team-Wable/feat/#42
Browse files Browse the repository at this point in the history
[FEAT] 운영 계정 확인 기능 개발
  • Loading branch information
Hong0329 authored Nov 15, 2024
2 parents c19b252 + 1f5b402 commit ed03f0b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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<Long> allowedIds = adminConfig.getAllowedIds();
return allowedIds.contains(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class AuthResponseDto {
private int memberLckYears;

private int memberLevel;

private Boolean isAdmin;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.List;
import java.util.Objects;

@Service
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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());
Expand Down Expand Up @@ -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<Long> allowedIds = adminConfig.getAllowedIds();
return allowedIds.contains(memberId);
}
}
Original file line number Diff line number Diff line change
@@ -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<Long> allowedIds;

public List<Long> getAllowedIds() {
return allowedIds;
}

public void setAllowedIds(List<Long> allowedIds) {
this.allowedIds = allowedIds;
}
}

0 comments on commit ed03f0b

Please sign in to comment.