Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.example.kdtbe5_miniproject._core.util.ApiUtils;
import com.example.kdtbe5_miniproject.user.User;
import com.example.kdtbe5_miniproject.user.UserRoles;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;

import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -55,15 +58,23 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
myUserDetails.getAuthorities()
);
SecurityContextHolder.getContext().setAuthentication(authentication);
chain.doFilter(request, response);
log.debug("디버그 : 인증 객체 만들어짐");
} catch (SignatureVerificationException sve) {
log.error("토큰 검증 실패");
} catch (TokenExpiredException tee) {
log.error("토큰 만료됨");
AuthorizationTokenError(response);
} catch (JWTDecodeException tee) {
log.error("토큰 만료됨");
} finally {
chain.doFilter(request, response);
}
}

private void AuthorizationTokenError(HttpServletResponse response) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.getWriter().write(objectMapper.writeValueAsString(ApiUtils.error("다시 로그인 해주세요")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ public List<User> findAllUsers() {

return query.getResultList();
}
*/
public List<Object[]> findAllUsers() {
//대기 상태인 연차 중 numOfDayOff가 가장 낮은 값으로 가져옴
Query query = entityManager.createQuery(
"SELECT DISTINCT u.id, u FROM User u");

return query.getResultList();
}

public User findUserById(Long userId) {
Query query = entityManager.createQuery(
Expand All @@ -80,15 +72,6 @@ public User findUserById(Long userId) {

return (User) query.getSingleResult();
}
*/

public Object[] findUserById(Long userId) {
Query query = entityManager.createQuery(
"SELECT DISTINCT u.id, u FROM User u WHERE u.id = :id");
query.setParameter("id", userId);

return (Object[]) query.getSingleResult();
}

@Transactional
public void updateNumOfDayOffById(Long id, DayOffStatus status, LocalDate now) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public DutyStatusDTO(Duty duty) {
@Getter
@Setter
public static class UsersDTO {
private Long id;
private Long userId;
private String username;
private String email;
private String phoneNumber;
Expand All @@ -93,7 +93,7 @@ public static class UsersDTO {
private int roles;

public UsersDTO(User user) {
this.id = user.getId();
this.userId = user.getId();
this.username = user.getUsername();
this.email = user.getEmail();
this.phoneNumber = user.getPhoneNumber();
Expand Down