Skip to content

Commit

Permalink
Merge pull request #6 from Timetris-Trendithon/loginError
Browse files Browse the repository at this point in the history
๐Ÿ”งFix: redirection ์ฝ”๋“œ ์ˆ˜์ •
  • Loading branch information
jiinkyung authored Feb 17, 2024
2 parents 3480dfc + 1c3fbcf commit 02ecf90
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE
echo "$TIME_NOW > $JAR_FILE ํŒŒ์ผ ์‹คํ–‰" >> $DEPLOY_LOG

nohup sudo java -jar \
-Dspring.config.location=/home/ubuntu/app/src/main/resources/application.yml, /home/ubuntu/app/src/main/resources/application-jwt, /home/ubuntu/app/src/main/resources/application-oauth.yml.yml \
-Dspring.config.location=/home/ubuntu/app/application.yml, /home/ubuntu/app/application-jwt, /home/ubuntu/app/application-oauth.yml \
-Duser.timezone=Asia/Seoul\
$JAR_FILE > $APP_LOG 2> $ERROR_LOG &

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.trendithon.timetris.domain.mainpage.dto.MainPageDTO;
import com.trendithon.timetris.domain.mainpage.service.MainPageService;
import com.trendithon.timetris.global.auth.jwt.TokenProvider;
import com.trendithon.timetris.global.exception.ApiResponse;
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import com.trendithon.timetris.global.exception.enums.SuccessStatus;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -19,13 +23,25 @@
public class MainPageController {

private final MainPageService mainPageService;
private final TokenProvider tokenProvider;

@GetMapping("/{userId}")
public ApiResponse<MainPageDTO> getMainPage(Authentication authentication,
@PathVariable long userId)
{
@PathVariable long userId) {
MainPageDTO mainPageDTO = mainPageService.getMainPage(userId);
return ApiResponse.success(SuccessStatus.OK, mainPageDTO);
}


@GetMapping
public ApiResponse<String> MainForTest(HttpServletRequest request) {
String userName = (String) request.getSession().getAttribute("name");

if (userName == null) {
return ApiResponse.of("LOGIN", "๋กœ๊ทธ์ธ ํ•˜์„ธ์š”");
} else {
return ApiResponse.success(SuccessStatus.OK, userName);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@Slf4j
@Configuration
@Getter
@PropertySource(value = "classpath:application-jwt.yml")
public class TokenProvider {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo

String accessToken = tokenProvider.createAccessToken(foundAccount);
response.addHeader(tokenProvider.getAccessHeader(), "Bearer " + accessToken);
response.sendRedirect("/member/detail");
response.sendRedirect("/main");

tokenProvider.sendAccessAndRefreshToken(response, accessToken, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http.authorizeRequests()
.requestMatchers("/","/css/**","/images/**","/js/**","/favicon.ico","/h2-console/**", "/index.html").permitAll()
.requestMatchers("/api/v1/google/*").permitAll() // ๋ชจ๋“  ์œ ์ € ์ ‘๊ทผ ๊ฐ€๋Šฅ (์ธ์ฆ ํ•„์š” X)
.requestMatchers("/login").permitAll() // ๋ชจ๋“  ์œ ์ € ์ ‘๊ทผ ๊ฐ€๋Šฅ (์ธ์ฆ ํ•„์š” X)
.requestMatchers(
// Swagger ํ—ˆ์šฉ URL
"/v2/api-docs", "/v3/api-docs", "/v3/api-docs/**", "/swagger-resources",
"/swagger-resources/**", "/configuration/ui", "/configuration/security", "/swagger-ui/**",
"/webjars/**", "/swagger-ui.html").permitAll()
.requestMatchers("/main").hasRole("USER") // "/main/authenticated"์— ๋Œ€ํ•œ ์ ‘๊ทผ์€ "USER" ์—ญํ• ์ด ์žˆ์–ด์•ผ ํ•จ
//.requestMatchers("/main").hasRole("USER") // "/main/authenticated"์— ๋Œ€ํ•œ ์ ‘๊ทผ์€ "USER" ์—ญํ• ์ด ์žˆ์–ด์•ผ ํ•จ
.requestMatchers("/api/**").authenticated() // ์ธ์ฆ ํ•„์š”

.anyRequest().permitAll();
Expand Down

0 comments on commit 02ecf90

Please sign in to comment.