diff --git a/ddl/schema.sql b/ddl/schema.sql index 13e2bb0..dbfc311 100644 --- a/ddl/schema.sql +++ b/ddl/schema.sql @@ -69,7 +69,6 @@ oid bigint not null, updated_at timestamp(6) not null, updated_oid bigint, - role varchar(40) not null check (role in ('MEMBER','ADMIN','SYSTEM_ADMIN')), login_ip varchar(45), name varchar(100) not null, password varchar(100) not null, diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java b/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java index 95c821e..22d4068 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java @@ -14,6 +14,5 @@ import java.time.LocalDateTime; public class LoginResponseDto { private String userId; - private String role; private LocalDateTime lastLoginAt; } diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/dto/MemberDto.java b/src/main/java/com/bio/bio_backend/domain/base/member/dto/MemberDto.java index 53ab425..178304f 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/dto/MemberDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/dto/MemberDto.java @@ -1,6 +1,5 @@ package com.bio.bio_backend.domain.base.member.dto; -import com.bio.bio_backend.domain.base.member.enums.MemberRole; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -24,7 +23,6 @@ public class MemberDto implements UserDetails { private String password; private String name; private String email; - private MemberRole role; private Boolean useFlag; private String refreshToken; private String loginIp; @@ -34,7 +32,7 @@ public class MemberDto implements UserDetails { @Override public Collection getAuthorities() { - return Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + this.role.getValue())); + return Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER")); } @Override diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/entity/Member.java b/src/main/java/com/bio/bio_backend/domain/base/member/entity/Member.java index 86b8b9e..f3d68a0 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/entity/Member.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/entity/Member.java @@ -1,6 +1,5 @@ package com.bio.bio_backend.domain.base.member.entity; -import com.bio.bio_backend.domain.base.member.enums.MemberRole; import com.bio.bio_backend.global.constants.AppConstants; import com.bio.bio_backend.global.entity.BaseEntity; import jakarta.persistence.*; @@ -37,9 +36,7 @@ public class Member extends BaseEntity { @Column(name = "email", nullable = false, length = 255) private String email; - @Enumerated(EnumType.STRING) - @Column(name = "role", nullable = false, length = 40) - private MemberRole role; + @Column(name = "use_flag", nullable = false) @Builder.Default diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/enums/MemberRole.java b/src/main/java/com/bio/bio_backend/domain/base/member/enums/MemberRole.java deleted file mode 100644 index d005375..0000000 --- a/src/main/java/com/bio/bio_backend/domain/base/member/enums/MemberRole.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.bio.bio_backend.domain.base.member.enums; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * 회원 역할을 정의하는 Enum - */ -@Getter -@RequiredArgsConstructor -public enum MemberRole { - - MEMBER("MEMBER", "일반 회원"), - ADMIN("ADMIN", "관리자"), - SYSTEM_ADMIN("SYSTEM_ADMIN", "시스템 관리자"); - - private final String value; - private final String description; - - /** - * 문자열 값으로부터 MemberRole을 찾는 메서드 - */ - public static MemberRole fromValue(String value) { - for (MemberRole role : values()) { - if (role.value.equals(value)) { - return role; - } - } - throw new IllegalArgumentException("Unknown MemberRole value: " + value); - } - - /** - * 기본 역할 반환 - */ - public static MemberRole getDefault() { - return MEMBER; - } -} diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java index f5468d7..779c323 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java @@ -16,10 +16,9 @@ public interface MemberMapper { /** * CreateMemberRequestDto를 MemberDto로 변환 - * 기본값 설정: role = MemberRole.MEMBER, useFlag = true + * 기본값 설정: useFlag = true */ @Mapping(target = "oid", ignore = true) - @Mapping(target = "role", expression = "java(com.bio.bio_backend.domain.base.member.enums.MemberRole.getDefault())") @Mapping(target = "useFlag", constant = "true") @Mapping(target = "refreshToken", ignore = true) @Mapping(target = "loginIp", ignore = true) diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java index 55d1176..651306b 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java @@ -2,7 +2,6 @@ package com.bio.bio_backend.domain.base.member.service; import com.bio.bio_backend.domain.base.member.dto.MemberDto; import com.bio.bio_backend.domain.base.member.entity.Member; -import com.bio.bio_backend.domain.base.member.enums.MemberRole; import com.bio.bio_backend.domain.base.member.mapper.MemberMapper; import com.bio.bio_backend.domain.base.member.repository.MemberRepository; import com.bio.bio_backend.global.exception.ApiException; @@ -50,7 +49,6 @@ public class MemberServiceImpl implements MemberService { .password(bCryptPasswordEncoder.encode(memberDto.getPassword())) .name(memberDto.getName()) .email(memberDto.getEmail()) - .role(MemberRole.getDefault()) .build(); member.setCreatedOid(AppConstants.ADMIN_OID); diff --git a/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java b/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java index 87acfd6..7c5d12d 100644 --- a/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java +++ b/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java @@ -64,8 +64,8 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter MemberDto member = (MemberDto) userDetails; // 토큰 생성 - String accessToken = jwtUtils.createAccessToken(member.getUserId(), member.getRole().getValue()); - String refreshToken = jwtUtils.createRefreshToken(member.getUserId(), member.getRole().getValue(), httpUtils.getClientIp()); + String accessToken = jwtUtils.createAccessToken(member.getUserId()); + String refreshToken = jwtUtils.createRefreshToken(member.getUserId(), httpUtils.getClientIp()); member.setRefreshToken(refreshToken); member.setLoginIp(httpUtils.getClientIp()); @@ -85,7 +85,6 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter LoginResponseDto memberData = new LoginResponseDto(); memberData.setUserId(member.getUserId()); - memberData.setRole(member.getRole().getValue()); memberData.setLastLoginAt(member.getLastLoginAt()); // login 성공 메시지 전송 diff --git a/src/main/java/com/bio/bio_backend/global/utils/JwtUtils.java b/src/main/java/com/bio/bio_backend/global/utils/JwtUtils.java index 7c9347b..c3a46b3 100644 --- a/src/main/java/com/bio/bio_backend/global/utils/JwtUtils.java +++ b/src/main/java/com/bio/bio_backend/global/utils/JwtUtils.java @@ -36,10 +36,9 @@ public class JwtUtils { } // Token 생성 - public String generateToken(String username, String role, long expirationTime) { + public String generateToken(String username, long expirationTime) { return Jwts.builder() .subject(username) - .claim("role", role) .issuedAt(new Date(System.currentTimeMillis())) .expiration(new Date(System.currentTimeMillis() + expirationTime)) .signWith(getSigningKey()) @@ -47,10 +46,9 @@ public class JwtUtils { } // Token 생성(IP 정보 포함) - public String generateToken(String username, String role, String clientIp, long expirationTime) { + public String generateToken(String username, String clientIp, long expirationTime) { return Jwts.builder() .subject(username) - .claim("role", role) .claim("ip", clientIp) // IP 정보 추가 .issuedAt(new Date(System.currentTimeMillis())) .expiration(new Date(System.currentTimeMillis() + expirationTime)) @@ -59,15 +57,15 @@ public class JwtUtils { } // Access Token 생성 - public String createAccessToken(String username, String role) { + public String createAccessToken(String username) { long expirationTime = Long.parseLong(Objects.requireNonNull(env.getProperty("token.expiration_time_access"))); - return generateToken(username, role, expirationTime); + return generateToken(username, expirationTime); } // Refresh Token 생성 시 IP 정보 포함 - public String createRefreshToken(String username, String role, String clientIp) { + public String createRefreshToken(String username, String clientIp) { long expirationTime = Long.parseLong(Objects.requireNonNull(env.getProperty("token.expiration_time_refresh"))); - return generateToken(username, role, clientIp, expirationTime); + return generateToken(username, clientIp, expirationTime); } // Token 검증 @@ -126,11 +124,7 @@ public class JwtUtils { return extractAllClaims(token).getSubject(); } - // Role 정보 추출 - public String extractRole(String token) { - Claims claims = extractAllClaims(token); - return claims.get("role", String.class); - } + public Claims extractAllClaims(String token) { return Jwts.parser() diff --git a/src/main/java/com/bio/bio_backend/global/utils/SecurityUtils.java b/src/main/java/com/bio/bio_backend/global/utils/SecurityUtils.java index ace8a35..7c5a656 100644 --- a/src/main/java/com/bio/bio_backend/global/utils/SecurityUtils.java +++ b/src/main/java/com/bio/bio_backend/global/utils/SecurityUtils.java @@ -57,12 +57,5 @@ public class SecurityUtils { return authentication != null && authentication.isAuthenticated(); } - /** - * 현재 인증된 사용자의 역할을 반환합니다. - * @return 역할 문자열 - */ - public static String getCurrentUserRole() { - MemberDto member = getCurrentMember(); - return member != null ? member.getRole().name() : null; - } + }