commit
This commit is contained in:
@@ -47,8 +47,4 @@ public class AgentUserToken extends AuditEntity {
|
|||||||
this.refreshToken = refreshToken;
|
this.refreshToken = refreshToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateRefreshToken(String refreshToken) {
|
|
||||||
return this.refreshToken.equals(refreshToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.spring.domain.user.dto.UserManagementResponse;
|
|||||||
import com.spring.domain.user.entity.AgentUser;
|
import com.spring.domain.user.entity.AgentUser;
|
||||||
import com.spring.domain.user.error.UserNotFoundException;
|
import com.spring.domain.user.error.UserNotFoundException;
|
||||||
import com.spring.domain.user.repository.AgentUserRepository;
|
import com.spring.domain.user.repository.AgentUserRepository;
|
||||||
|
import com.spring.domain.user.repository.AgentUserTokenRepository;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
public class UserManagementService {
|
public class UserManagementService {
|
||||||
|
|
||||||
private final AgentUserRepository agentUserRepository;
|
private final AgentUserRepository agentUserRepository;
|
||||||
|
private final AgentUserTokenRepository agentUserTokenRepository;
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<UserManagementResponse> getUsers(UserFindRequest request) {
|
public List<UserManagementResponse> getUsers(UserFindRequest request) {
|
||||||
@@ -42,8 +44,10 @@ public class UserManagementService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteUser(String id) {
|
public void deleteUser(String id) {
|
||||||
AgentUser user = agentUserRepository.findById(UUID.fromString(id))
|
AgentUser user = agentUserRepository.findById(UUID.fromString(id)).orElseThrow(UserNotFoundException::new);
|
||||||
.orElseThrow(UserNotFoundException::new);
|
if (agentUserTokenRepository.findById(UUID.fromString(id)).isPresent()) {
|
||||||
|
agentUserTokenRepository.deleteById(UUID.fromString(id));
|
||||||
|
}
|
||||||
agentUserRepository.delete(user);
|
agentUserRepository.delete(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ public class UserRefreshTokenService implements RefreshTokenService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void deleteRefreshToken(String key) {
|
public void deleteRefreshToken(String key) {
|
||||||
|
if (agentUserTokenRepository.findById(UUID.fromString(key)).isPresent()) {
|
||||||
agentUserTokenRepository.deleteById(UUID.fromString(key));
|
agentUserTokenRepository.deleteById(UUID.fromString(key));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public final class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
} else {
|
} else {
|
||||||
// 액세스 토큰이 유효하지 않은 경우 리프레시 토큰을 사용하여 새로운 액세스 토큰을 발급합니다.
|
// 액세스 토큰이 유효하지 않은 경우 리프레시 토큰을 사용하여 새로운 액세스 토큰을 발급합니다.
|
||||||
String refreshToken = jwtTokenService.resolveTokenFromCookie(request, JwtTokenRule.REFRESH_PREFIX);
|
String refreshToken = jwtTokenService.resolveTokenFromCookie(request, JwtTokenRule.REFRESH_PREFIX);
|
||||||
jwtTokenService.validateToken(refreshToken);
|
jwtTokenService.validateRefreshToken(refreshToken);
|
||||||
String reissuedAccessToken = jwtTokenService.getRefreshToken(refreshToken);
|
String reissuedAccessToken = jwtTokenService.getRefreshToken(refreshToken);
|
||||||
Authentication authentication = jwtTokenService.getAuthentication(reissuedAccessToken);
|
Authentication authentication = jwtTokenService.getAuthentication(reissuedAccessToken);
|
||||||
jwtTokenService.saveRefreshToken(authentication.getName(), jwtTokenService.generateRefreshToken(response, authentication));
|
jwtTokenService.saveRefreshToken(authentication.getName(), jwtTokenService.generateRefreshToken(response, authentication));
|
||||||
@@ -117,7 +117,7 @@ public final class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
return Optional.ofNullable(request.getHeader(headerName))
|
return Optional.ofNullable(request.getHeader(headerName))
|
||||||
.filter(token -> token.substring(0, 7).equalsIgnoreCase(JwtTokenRule.BEARER_PREFIX.getValue()))
|
.filter(token -> token.substring(0, 7).equalsIgnoreCase(JwtTokenRule.BEARER_PREFIX.getValue()))
|
||||||
.map(token -> token.substring(7))
|
.map(token -> token.substring(7))
|
||||||
.orElse(jwtTokenService.resolveTokenFromCookie(request, JwtTokenRule.ACCESS_PREFIX));
|
.orElseGet(() -> jwtTokenService.resolveTokenFromCookie(request, JwtTokenRule.ACCESS_PREFIX));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -161,25 +161,16 @@ public class JwtTokenService {
|
|||||||
* @param maxAgeSeconds 쿠키 유효 시간(초)
|
* @param maxAgeSeconds 쿠키 유효 시간(초)
|
||||||
* @return 생성된 ResponseCookie 객체
|
* @return 생성된 ResponseCookie 객체
|
||||||
*/
|
*/
|
||||||
private ResponseCookie setTokenToCookie(String tokenPrefix, String token, long maxAgeSeconds) {
|
private ResponseCookie setTokenToCookie(String tokenPrefix, String token, long maxAgeMinutes) {
|
||||||
return ResponseCookie.from(tokenPrefix, token)
|
return ResponseCookie.from(tokenPrefix, token)
|
||||||
.path("/")
|
.path("/")
|
||||||
.maxAge(Duration.ofSeconds(maxAgeSeconds))
|
.maxAge(Duration.ofMinutes(maxAgeMinutes))
|
||||||
.httpOnly(true)
|
.httpOnly(true)
|
||||||
.sameSite("None")
|
.sameSite("None")
|
||||||
.secure(true)
|
.secure(true)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 액세스 토큰의 유효성을 검증합니다.
|
|
||||||
*
|
|
||||||
* @param token 검증할 토큰
|
|
||||||
*/
|
|
||||||
public void validateToken(String token) {
|
|
||||||
jwtTokenUtil.tokenStatus(token, accessSecretKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 액세스 토큰의 유효성을 검증합니다.
|
* 액세스 토큰의 유효성을 검증합니다.
|
||||||
*
|
*
|
||||||
@@ -196,8 +187,8 @@ public class JwtTokenService {
|
|||||||
* @param token 검증할 토큰
|
* @param token 검증할 토큰
|
||||||
* @return 토큰의 유효성 여부
|
* @return 토큰의 유효성 여부
|
||||||
*/
|
*/
|
||||||
public boolean validateRefreshToken(String token) {
|
public void validateRefreshToken(String token) {
|
||||||
return jwtTokenUtil.getTokenStatus(token, refreshSecretKey) == JwtTokenStatus.AUTHENTICATED;
|
jwtTokenUtil.tokenStatus(token, refreshSecretKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,19 +31,21 @@ const updateTable = (users) => {
|
|||||||
<td class="align-middle">${user.userName}</td>
|
<td class="align-middle">${user.userName}</td>
|
||||||
<td class="align-middle">${user.email}</td>
|
<td class="align-middle">${user.email}</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<select id="userRole-${user.id}" class="form-select form-select-sm">
|
<select id="userRole-${user.id}" class="form-select form-select-sm" ${USER_INFO.userId === user.userId ? 'disabled' : ''}>
|
||||||
${ROLES.length > 0 ? ROLES.map(role => `
|
${ROLES.length > 0 ? ROLES.map(role => `
|
||||||
<option value="${role}" ${user.userRole === role ? 'selected' : ''}>${role}</option>
|
<option value="${role}" ${user.userRole === role ? 'selected' : ''}>${role}</option>
|
||||||
`).join('') : '<option value=""></option>'}
|
`).join('') : '<option value=""></option>'}
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<input id="approved-${user.id}" type="checkbox" ${user.approved ? 'checked' : ''} class="form-check-input">
|
<input id="approved-${user.id}" type="checkbox" ${user.approved ? 'checked' : ''} class="form-check-input" ${USER_INFO.userId === user.userId ? 'disabled' : ''}>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
|
${USER_INFO.userId !== user.userId ? `
|
||||||
<button class="btn btn-sm btn-outline-danger delete-btn" data-id="${user.id}" title="사용자 삭제">
|
<button class="btn btn-sm btn-outline-danger delete-btn" data-id="${user.id}" title="사용자 삭제">
|
||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
|
` : ''}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`).join('');
|
`).join('');
|
||||||
|
|||||||
Reference in New Issue
Block a user