Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -10,8 +10,7 @@
public enum AuthException implements BaseException {

OAUTH_PROVIDER_ERROR(HttpStatus.UNAUTHORIZED, "인증 제공자 오류"),
OAUTH_USER_CANCELLED(HttpStatus.UNAUTHORIZED, "사용자가 인증을 취소함"),
USER_MAPPING_FAILED(HttpStatus.UNAUTHORIZED, "OAuth 사용자 정보를 처리할 수 없음"),
OAUTH_USER_CANCELED(HttpStatus.UNAUTHORIZED, "사용자가 인증을 취소함"),
INVALID_REDIRECT_URI(HttpStatus.UNAUTHORIZED, "리다이렉트 URI가 유효하지 않음"),
EMPTY_OAUTH_TOKEN(HttpStatus.UNAUTHORIZED, "ACCESS TOKEN이 비어있음");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public class JwtTokenProvider {
private final SecretKey secretKey;

public JwtTokenProvider(@Value("${spring.jwt.secret-key}") String secret) {

secretKey = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8),
SIG.HS256.key().build().getAlgorithm());
}

public String createVoteUserToken(String email, Date issuedAt, long expirationMillis) {

Date expiration = new Date(issuedAt.getTime() + expirationMillis);

return Jwts.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
if (exception.getMessage().contains("redirect")) {
log.warn(new GeneralException(AuthException.INVALID_REDIRECT_URI).getMessage());
} else if (exception.getMessage().contains("user cancelled")) {
log.warn(new GeneralException(AuthException.OAUTH_USER_CANCELLED).getMessage());
log.warn(new GeneralException(AuthException.OAUTH_USER_CANCELED).getMessage());
} else {
log.warn(new GeneralException(AuthException.OAUTH_PROVIDER_ERROR).getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class CustomOAuth2UserService implements OAuth2UserService<OAuth2UserRequ

@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2UserService<OAuth2UserRequest, OAuth2User> delegate =
new DefaultOAuth2UserService();

OAuth2UserService<OAuth2UserRequest, OAuth2User> delegate = new DefaultOAuth2UserService();
OAuth2User oauth2User = delegate.loadUser(userRequest);

// GitHub 사용자 정보 추출
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ public class SessionAuthenticationFilter extends OncePerRequestFilter {
private final SessionManager sessionManager;

@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain)
throws ServletException, IOException {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {

Long userId = sessionManager.getUserId(request);

if (userId == null) {
response.sendRedirect("/login/failure");
return;
Expand All @@ -36,7 +33,9 @@ protected void doFilterInternal(HttpServletRequest request,

@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {

String path = request.getRequestURI();

return PERMIT_ALL_PATHS.contains(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
public class SessionManager {

public void createSession(HttpServletRequest request, Long userId) {

HttpSession session = request.getSession();
session.setAttribute("userId", userId);
}

public Long getUserId(HttpServletRequest request) {

HttpSession session = request.getSession(false);

return Optional.ofNullable(session)
Expand All @@ -23,6 +25,7 @@ public Long getUserId(HttpServletRequest request) {
}

public void clearSession(HttpServletRequest request) {

HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.specialwarriors.conal.common.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

Expand All @@ -23,16 +23,19 @@ public class RedisConfig {

@Bean
public RedisConnectionFactory redisConnectionFactory() {

return new LettuceConnectionFactory(redisHost, redisPort);
}

@Bean
public ReactiveRedisConnectionFactory reactiveRedisConnectionFactory() {

return new LettuceConnectionFactory(redisHost, redisPort);
}

@Bean
public RedisTemplate<String, String> redisTemplate() {

RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class WebClientConfig {

@Bean
public WebClient githubWebClient() {

return WebClient.builder()
.baseUrl("https://api.github.com")
.defaultHeader(HttpHeaders.USER_AGENT, "spring-webclient")
Expand All @@ -32,6 +33,7 @@ public WebClient githubWebClient() {

@Bean
public WebClient githubRevokeWebClient() {

String basicAuth = Base64.getEncoder()
.encodeToString((clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class GlobalExceptionHandler {
@ExceptionHandler(GeneralException.class)
public ResponseEntity<ExceptionResponse> handleGeneralException(GeneralException e) {

return ResponseEntity.status(e.getStatus())
.body(new ExceptionResponse(e.getMessage()));
return ResponseEntity.status(e.getStatus()).body(new ExceptionResponse(e.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ public class ContributionScheduler {

@Scheduled(cron = "0 0 9 ? * FRI")
public void sendContribution() {

List<NotificationAgreement> notificationAgreements = notificationAgreementQuery
.findAllByType(NotificationType.CONTRIBUTION);
.findAllByType(NotificationType.CONTRIBUTION);

List<Long> githubRepoIds = notificationAgreements.stream()
.map(NotificationAgreement::getGithubRepoId)
.toList();
.map(NotificationAgreement::getGithubRepoId)
.toList();

List<GithubRepo> githubRepos = githubRepoRepository.findAllById(githubRepoIds);

for (GithubRepo githubRepo : githubRepos) {
for (Contributor contributor : githubRepo.getContributors()) {
mailUtil.sendContributionForm(
contributionService.sendEmail(contributor, githubRepo));
contributionService.sendEmail(contributor, githubRepo));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
public class ContributionService {

public ContributionFormResponse sendEmail(Contributor contributor, GithubRepo githubRepo) {

Long userId = githubRepo.getUser().getId();
Long repoId = githubRepo.getId();

return new ContributionFormResponse(userId, repoId,
contributor.getEmail());
contributor.getEmail());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ public class GitHubController {

@GetMapping("/repos/{owner}/{repo}/details")
public Mono<Map<String, Map<String, String>>> getContributorDetailsFromRedis(
@PathVariable String owner,
@PathVariable String repo
@PathVariable String owner,
@PathVariable String repo
) {

return githubService.getContributorsFromRedis(owner, repo)
.flatMapMany(Flux::fromIterable)
.flatMap(login ->
githubService.getContributorDetailFromRedis(owner, repo, login)
.map(detailMap -> Map.entry(login, detailMap)))
.collectMap(Map.Entry::getKey, Map.Entry::getValue);
.flatMapMany(Flux::fromIterable)
.flatMap(login ->
githubService.getContributorDetailFromRedis(owner, repo, login)
.map(detailMap -> Map.entry(login, detailMap)))
.collectMap(Map.Entry::getKey, Map.Entry::getValue);
}

@PostMapping("/repos/{owner}/{repo}/update")
public Mono<ResponseEntity<String>> updateAllGithubContributorAndContribution(
@PathVariable String owner,
@PathVariable String repo
@PathVariable String owner,
@PathVariable String repo
) {

return githubService.updateRepoContribution(owner, repo)
.thenReturn(ResponseEntity.ok("전체 랭킹 업데이트 완료"));
.thenReturn(ResponseEntity.ok("전체 랭킹 업데이트 완료"));
}


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.specialwarriors.conal.github.dto;

public record GitHubContributor(

String login
String login
) {

}
Loading