Skip to content

Commit

Permalink
Merge pull request #129 from kakao-tech-campus-2nd-step3/weekly
Browse files Browse the repository at this point in the history
w11 weekly -> develop 일부 반영
  • Loading branch information
sunandrabbit authored Nov 13, 2024
2 parents 33edf52 + 9b91cbd commit 8a53a58
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public AuthController(AuthService authService) {
this.authService = authService;
}

@GetMapping("/success")
public SingleResult<Token> temp(@RequestParam("accessToken") String accessToken) {
return new SingleResult<>(new Token(accessToken));
}
// @GetMapping("/success")
// public SingleResult<Token> temp(@RequestParam("accessToken") String accessToken) {
// return new SingleResult<>(new Token(accessToken));
// }

@Operation(summary = "인증 코드로 멤버 토큰 반환")
@GetMapping("/memberCode")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package team1.be.seamless.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class AuthSuccessController {
private String returnURL;

@Autowired
public AuthSuccessController(@Value("${Url.Url}")String returnURL) {
this.returnURL = returnURL;
TestUrl();
}

@GetMapping("/api/auth/success")
public String redirectURL(HttpServletRequest request, RedirectAttributes redirectAttributes, @RequestParam("accessToken") String accessToken) {
String referer = request.getHeader("Referer");
// accessToken 값을 URL 파라미터로 전달
redirectAttributes.addAttribute("accessToken", accessToken);
return "redirect:"+returnURL+"/login";
}

@Profile("test")
public void TestUrl(){
returnURL="localhost:3000";
}
}
1 change: 0 additions & 1 deletion src/main/java/team1/be/seamless/dto/TaskDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ public TaskDetail(TaskEntity task) {
this.description = task.getDescription();
this.ownerId = task.getId();
this.progress = task.getProgress();
this.description = task.getDescription();
this.startDate = task.getStartDate();
this.endDate = task.getEndDate();
this.taskStatus = task.getStatus();
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/team1/be/seamless/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -54,6 +55,10 @@ public MemberResponseDTO getMember(Long projectId, Long memberId, String role) {
throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다.");
}

if(!memberEntity.getProjectEntity().isActive()) {
throw new BaseHandler(HttpStatus.BAD_REQUEST, "멤버가 속한 프로젝트가 존재 하지 않습니다.");
}

return memberMapper.toGetResponseDTO(memberEntity);
}

Expand All @@ -63,9 +68,16 @@ public Page<MemberResponseDTO> getMemberList(Long projectId,
if (Role.MEMBER.isRole(role)) {
throw new BaseHandler(HttpStatus.UNAUTHORIZED, "권한이 없습니다.");
}

return memberRepository.findAllByProjectEntityIdAndIsDeleteFalse(projectId,
memberList.toPageable()).map(memberMapper::toGetResponseDTO);
Page<MemberEntity> memberEntities = memberRepository.findAllByProjectEntityIdAndIsDeleteFalse(projectId, memberList.toPageable());

return new PageImpl<>(
memberEntities.stream()
.filter(memberEntity -> memberEntity.getProjectEntity().isActive())
.map(memberMapper::toGetResponseDTO)
.toList(),
memberEntities.getPageable(),
memberEntities.getTotalElements()
);

}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/team1/be/seamless/service/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public TaskDetail getTask(Long taskId) {
TaskEntity taskEntity = taskRepository.findByIdAndIsDeletedFalse(taskId)
.orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "존재하지 않는 태스크"));

if(!taskEntity.getProject().isActive()) {
throw new BaseHandler(HttpStatus.NOT_FOUND, "태스크가 속한 프로젝트가 존재 하지 않습니다.");
}

return taskMapper.toDetail(taskEntity);
}

Expand All @@ -65,7 +69,15 @@ public Page<TaskWithOwnerDetail> getTaskList(Long projectId, String status, Stri
Page<TaskEntity> taskEntities = taskRepository.findByProjectIdAndOptionalFilters(projectId,
status, priority, memberId, param.toPageable());

return taskEntities.map(taskMapper::toDetailWithOwner);
return new PageImpl<>(
taskEntities.stream()
.filter(taskEntity -> taskEntity.getProject().isActive())
.map(taskMapper::toDetailWithOwner)
.toList(),
taskEntities.getPageable(),
taskEntities.getTotalElements()
);

}

public ProjectProgress getProjectProgress(Long projectId, getList param) {
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/team1/be/seamless/util/auth/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import team1.be.seamless.service.AuthService;
import team1.be.seamless.util.errorException.SecurityEntryPoint;
import team1.be.seamless.util.fiter.TokenAuthenticationFilter;
import team1.be.seamless.util.fiter.TokenExceptionFilter;

@Configuration
@EnableWebSecurity
Expand All @@ -25,23 +23,14 @@ public class SecurityConfig {
private final AuthService authService;
private final OAuth2SuccessHandler successHandler;
private final TokenAuthenticationFilter tokenAuthenticationFilter;
private final TokenExceptionFilter tokenExceptionFilter;
private final SecurityEntryPoint SecurityException;
private final HttpCookieOAuth2AuthorizationRequestRepository authorizationRequestRepository;


@Autowired
public SecurityConfig(AuthService authService, OAuth2SuccessHandler successHandler,
TokenAuthenticationFilter tokenAuthenticationFilter,
TokenExceptionFilter tokenExceptionFilter,
SecurityEntryPoint securityException,
HttpCookieOAuth2AuthorizationRequestRepository authorizationRequestRepository) {
TokenAuthenticationFilter tokenAuthenticationFilter) {
this.authService = authService;
this.successHandler = successHandler;
this.tokenAuthenticationFilter = tokenAuthenticationFilter;
this.tokenExceptionFilter = tokenExceptionFilter;
SecurityException = securityException;
this.authorizationRequestRepository = authorizationRequestRepository;
}

@Bean
Expand Down Expand Up @@ -86,8 +75,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http,
.authorizationRequestRepository(httpCookieOAuth2AuthorizationRequestRepository)
)

.addFilterBefore(tokenAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(tokenExceptionFilter, tokenAuthenticationFilter.getClass());
.addFilterBefore(tokenAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);

return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package team1.be.seamless.util.fiter;

import io.jsonwebtoken.ExpiredJwtException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import team1.be.seamless.util.auth.JwtToken;
import team1.be.seamless.util.errorException.CustomExceptionHandler;
import team1.be.seamless.util.errorException.RuntimeHandler;
import team1.be.seamless.util.errorException.StatusResponse;
import team1.be.seamless.util.page.SingleResult;

@Component
public class TokenAuthenticationFilter extends OncePerRequestFilter {
Expand All @@ -28,17 +34,24 @@ public TokenAuthenticationFilter(JwtToken jwtToken) {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {

String path = request.getRequestURI();
String method = request.getMethod();

response.setCharacterEncoding("utf-8");
// String path = request.getRequestURI();
// String method = request.getMethod();
//
String token = request.getHeader(AUTHORIZATION_HEADER);
if (token != null && token.startsWith(BEARER_PREFIX)) {
token = token.substring(7);
jwtToken.validateToken(token).getExpiration().after(new Date());
setAuthentication(token);
try{
jwtToken.validateToken(token);
setAuthentication(token);
} catch (RuntimeHandler e){
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); // 401 상태 설정
response.setContentType("application/json");
response.getWriter().write("{\"errorCode\": 401, \"errorMessage\": \"" + e.getMessage() + "\"}");

return;
}
}

filterChain.doFilter(request, response);
}

Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# project name
spring.application.name=Team1_BE

# init
Expand All @@ -19,4 +18,5 @@ spring.jpa.show-sql=true
server.forward-headers-strategy=framework

# URL matching
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
Url.Url=https://team1-fe.pages.dev

0 comments on commit 8a53a58

Please sign in to comment.