Skip to content

Commit

Permalink
feat : auth admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong0329 committed Nov 15, 2024
1 parent c19b252 commit c1130cd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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 c1130cd

Please sign in to comment.