Skip to content

Commit

Permalink
πŸš€ [Deploy] - Discord μ†Œμ…œ 둜그인 배포 반영 (#200)
Browse files Browse the repository at this point in the history
* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ • (#154)

* Chore: λΆˆν•„μš”ν•œ λΆ€λΆ„ μ‚­μ œ (#157)

* πŸ› [Fix] - μž‘μ—… λͺ©λ‘ API μˆ˜μ • (#158)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* πŸ› [Fix] - PeerReview 단계 μ˜ˆμ™Έμ²˜λ¦¬ (#160)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: discord command 이름 λ³€κ²½ (#163)

* Hotfix: λΉ„λ°€λ²ˆν˜Έ 인증 둜직 μΆ”κ°€ (#165)

* πŸ–ŠοΈ [Chore] - README μˆ˜μ • (#168)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* πŸ–ŠοΈ [Chore] - README μˆ˜μ • (#169)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* πŸ› [Fix] - 백둜그 νƒ€μž„λΌμΈ API (#171)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* fix: R&R μ •λ ¬ 였λ₯˜ ν•΄κ²°

* πŸ› [Fix] - λ‘œκ·Έμ•„μ›ƒ μ‹œ μΏ ν‚€ μ‚­μ œ (#174)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* πŸ’… [Refactor] - ν•„μš” μ—†λŠ” μ½”λ“œ μ‚­μ œ (#177)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* ✏️ [Chore] - discord command 이름 λ³€κ²½ 및 도움말 κΈ°λŠ₯ μΆ”κ°€ (#180)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* Chore: λͺ…λ Ήμ–΄ 이름 및 μ„€λͺ…λž€ μˆ˜μ •

* Feat: 도움말 λͺ…λ Ήμ–΄ κ΅¬ν˜„

* πŸš‘ [Hotfix] - λ””μŠ€μ½”λ“œ λͺ…λ Ήμ–΄ 이름 μˆ˜μ •μ— λ”°λ₯Έ Discord listener 반영 (#183)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* !HOTFIX: λͺ…λ Ήμ–΄ 이름 μˆ˜μ •μ— λ”°λ₯Έ listener μ½”λ“œ μˆ˜μ •

* πŸ› [Fix] - μž‘μ—… 기둝, 질문 λͺ©λ‘ sorting 이슈 ν•΄κ²° (#186)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* !HOTFIX: λͺ…λ Ήμ–΄ 이름 μˆ˜μ •μ— λ”°λ₯Έ listener μ½”λ“œ μˆ˜μ •

* Fix: μž‘μ—… 기둝 μ •λ ¬ μ΅œμ‹ μˆœμœΌλ‘œ μˆ˜μ •

* Fix: 질문 λͺ©λ‘ μ •λ ¬ μ΅œμ‹ μˆœμœΌλ‘œ μˆ˜μ •

* ✨ [Feature] - λ””μŠ€μ½”λ“œ λ‹΅λ³€ 정보 μΆ”κ°€ (#189)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* !HOTFIX: λͺ…λ Ήμ–΄ 이름 μˆ˜μ •μ— λ”°λ₯Έ listener μ½”λ“œ μˆ˜μ •

* Feat: λ‹΅λ³€ 등둝에 λ‹΅λ³€ν•œ μ‚¬λžŒ 정보 μΆ”κ°€ 및 ν˜•μ‹ μˆ˜μ •

* πŸ’… [Refactor] - λ””μŠ€μ½”λ“œ λ‹΅λ³€ν•˜κΈ° 봇 멘트 μˆ˜μ • (#192)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* !HOTFIX: λͺ…λ Ήμ–΄ 이름 μˆ˜μ •μ— λ”°λ₯Έ listener μ½”λ“œ μˆ˜μ •

* Refactor: λ΄‡μ˜ λ‹΅λ³€ν•˜κΈ° 멘트 μˆ˜μ •

* ✏️ [Chore] - DB 정보 μˆ˜μ • (#195)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* !HOTFIX: λͺ…λ Ήμ–΄ 이름 μˆ˜μ •μ— λ”°λ₯Έ listener μ½”λ“œ μˆ˜μ •

* Chore: DB 정보 μˆ˜μ •

* Fix: μ„œλΈŒλͺ¨λ“ˆ μ»¨ν”Œλ¦­νŠΈ ν•΄κ²°

* Fix: μ„œλΈŒ λͺ¨λ“ˆ μ»¨ν”Œλ¦­νŠΈ ν•΄κ²°

* ✨ [Feature] - Discord μ†Œμ…œ 둜그인 κ΅¬ν˜„ (#198)

* refactor: μ½”λ“œ μŠ€νƒ€μΌ μˆ˜μ •

* fix: Work 생성 λ‚ μ§œ κΈ°μ€€μœΌλ‘œ λ‚΄λ¦Όμ°¨μˆœ μ„€μ •

* fix: PeerReview일 경우 μΆ”κ°€

* Chore: ν”„λ‘œμ νŠΈ readme κΎΈλ―ΈκΈ°

* chore: README μˆ˜μ •

* Fix: λ‘œκ·Έμ•„μ›ƒ μ‹œ, μΏ ν‚€ μ‚­μ œ μ½”λ“œ μˆ˜μ •

* Refactor: ν•„μš”μ—†λŠ” μ½”λ“œ μ‚­μ œ

* !HOTFIX: λͺ…λ Ήμ–΄ 이름 μˆ˜μ •μ— λ”°λ₯Έ listener μ½”λ“œ μˆ˜μ •

* Chore: DB 정보 μˆ˜μ •

* Fix: JDA 둜그 정보 기둝 μΆ”κ°€

* Chore: Discord μ†Œμ…œ 둜그인 Credentials μΆ”κ°€

* Feat: Discord μ†Œμ…œ 둜그인 κ΅¬ν˜„

* Feat: Discord μ†Œμ…œ 둜그인 κ΅¬ν˜„

* Chore: Discord μ†Œμ…œ 둜그인 Credentials μΆ”κ°€

* FIX

---------

Co-authored-by: Lim jeong woo <[email protected]>
  • Loading branch information
JeongHeumChoi and dlawjddn authored Jul 19, 2024
1 parent 87ffc9d commit f58cef6
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 9 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
// spring security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// spring boot
implementation 'org.springframework.boot:spring-boot-starter-web'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import goormthon.team28.startup_valley.discord.listener.DiscordListener;
import goormthon.team28.startup_valley.service.*;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
Expand All @@ -18,6 +19,7 @@

import java.util.TimeZone;

@Slf4j
@SpringBootApplication
public class StartupValleyApplication {
@PostConstruct
Expand All @@ -27,6 +29,7 @@ public void init() {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(StartupValleyApplication.class, args);

log.info("Initializing JDA");
JDA jda = JDABuilder.createDefault(context.getBean(DiscordBotToken.class).getToken())
.enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS)
.setChunkingFilter(ChunkingFilter.ALL)
Expand All @@ -45,6 +48,7 @@ public static void main(String[] args) {
)
)
.build();
log.info("Finished Initializing JDA");

jda.updateCommands().addCommands(
Commands.slash("1-νŒ€μ›μ—…λ°μ΄νŠΈ", "ν•΄λ‹Ή ν”„λ‘œμ νŠΈμ˜ νŒ€μ›λ“€μ„ λͺ¨λ‘ μ›ΉμœΌλ‘œ μ—°λ™ν•΄μš”."),
Expand Down Expand Up @@ -74,5 +78,4 @@ public static void main(String[] args) {
Commands.slash("도움말", "Startup Valley ν”„λ‘œλ•νŠΈλ₯Ό μ‚¬μš©ν•˜μ‹œκΈ° μ‹œμž‘ν•œ μ—¬λŸ¬λΆ„λ“€μ„ μœ„ν•œ μ•ˆλ‚΄μ„œμž…λ‹ˆλ‹€. πŸ“–πŸ€")
).queue();
}

}
17 changes: 13 additions & 4 deletions src/main/java/goormthon/team28/startup_valley/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goormthon.team28.startup_valley.domain;

import goormthon.team28.startup_valley.dto.type.EProfileImage;
import goormthon.team28.startup_valley.dto.type.EProvider;
import goormthon.team28.startup_valley.dto.type.ERole;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down Expand Up @@ -31,6 +32,9 @@ public class User {
@Column(name = "role", nullable = false)
@Enumerated(EnumType.STRING)
private ERole role;
@Column(name = "provider", nullable = false)
@Enumerated(EnumType.STRING)
private EProvider provider;

/* μ‚¬μš©μž 이용 정보 */
@Column(name = "nickname", nullable = false)
Expand All @@ -42,20 +46,25 @@ public class User {
private String refreshToken;

@Builder
public User(String serialId, String password, ERole role, String nickname, EProfileImage profileImage) {
public User(
String serialId,
String password,
ERole role,
EProfileImage profileImage,
EProvider provider
) {
this.serialId = serialId;
this.password = password;
this.role = role;
this.nickname = nickname;
this.profileImage = profileImage;
this.provider = provider;
}

public void updateRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}

public void updateUserInfo(String nickname, EProfileImage eProfileImage) {
this.nickname = nickname;
public void updateUserInfo(EProfileImage eProfileImage) {
this.profileImage = eProfileImage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package goormthon.team28.startup_valley.dto.type;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum EProvider {

DISCORD("DISCORD");

private final String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByIdAndRefreshToken(Long id, String refreshToken);
@Modifying(clearAutomatically = true)
@Query("update User u set u.refreshToken = :refreshToken where u.id = :userId")
void updateRefreshTokenAndLoginStatus(Long userId, String refreshToken);
void updateRefreshToken(Long userId, String refreshToken);
Optional<User> findById(Long userId);
Optional<User> findBySerialId(String serialId);
boolean existsBySerialId(String serialId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import goormthon.team28.startup_valley.security.handler.exception.CustomAuthenticationEntryPointHandler;
import goormthon.team28.startup_valley.security.handler.login.DefaultFailureHandler;
import goormthon.team28.startup_valley.security.handler.login.DefaultSuccessHandler;
import goormthon.team28.startup_valley.security.handler.login.Oauth2FailureHandler;
import goormthon.team28.startup_valley.security.handler.login.Oauth2SuccessHandler;
import goormthon.team28.startup_valley.security.handler.logout.CustomLogoutProcessHandler;
import goormthon.team28.startup_valley.security.handler.logout.CustomLogoutResultHandler;
import goormthon.team28.startup_valley.security.provider.JwtAuthenticationManager;
import goormthon.team28.startup_valley.security.service.CustomOauth2UserDetailService;
import goormthon.team28.startup_valley.util.JwtUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
Expand All @@ -24,14 +27,19 @@
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

private final JwtUtil jwtUtil;
private final JwtAuthenticationManager jwtAuthenticationManager;
private final DefaultSuccessHandler defaultSuccessHandler;
private final DefaultFailureHandler defaultFailureHandler;
private final Oauth2SuccessHandler oauth2SuccessHandler;
private final Oauth2FailureHandler oauth2FailureHandler;
private final CustomOauth2UserDetailService customOauth2UserDetailService;
private final CustomLogoutProcessHandler customLogoutProcessHandler;
private final CustomLogoutResultHandler customLogoutResultHandler;
private final CustomAccessDeniedHandler customAccessDeniedHandler;
private final CustomAuthenticationEntryPointHandler customAuthenticationEntryPointHandler;

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
Expand All @@ -55,6 +63,11 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.successHandler(defaultSuccessHandler)
.failureHandler(defaultFailureHandler)
)
.oauth2Login(login -> login
.successHandler(oauth2SuccessHandler)
.failureHandler(oauth2FailureHandler)
.userInfoEndpoint(it -> it.userService(customOauth2UserDetailService))
)
.logout(logout -> logout
.logoutUrl("/api/users/sign-out")
.addLogoutHandler(customLogoutProcessHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
JwtTokenDto jwtTokenDto = jwtUtil.generateTokens(userPrincipal.getUserId(), userPrincipal.getRole());

userRepository.updateRefreshTokenAndLoginStatus(userPrincipal.getUserId(), jwtTokenDto.refreshToken());
userRepository.updateRefreshToken(userPrincipal.getUserId(), jwtTokenDto.refreshToken());

AuthenticationResponse.makeLoginSuccessResponse(response, domain, jwtTokenDto, jwtUtil.getRefreshExpiration());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package goormthon.team28.startup_valley.security.handler.login;

import goormthon.team28.startup_valley.exception.ErrorCode;
import goormthon.team28.startup_valley.security.info.AuthenticationResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class Oauth2FailureHandler implements AuthenticationFailureHandler {

@Override
public void onAuthenticationFailure(
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception
) throws IOException, ServletException {
AuthenticationResponse.makeFailureResponse(response, ErrorCode.INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package goormthon.team28.startup_valley.security.handler.login;

import goormthon.team28.startup_valley.dto.response.JwtTokenDto;
import goormthon.team28.startup_valley.repository.UserRepository;
import goormthon.team28.startup_valley.security.info.AuthenticationResponse;
import goormthon.team28.startup_valley.security.info.UserPrincipal;
import goormthon.team28.startup_valley.util.JwtUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;

@Component
@RequiredArgsConstructor
public class Oauth2SuccessHandler implements AuthenticationSuccessHandler {

@Value("${server.domain}")
private String domain;
private final JwtUtil jwtUtil;
private final UserRepository userRepository;

@Override
@Transactional
public void onAuthenticationSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication authentication
) throws IOException, ServletException {
UserPrincipal principal = (UserPrincipal) authentication.getPrincipal();
JwtTokenDto jwtTokenDto = jwtUtil.generateTokens(principal.getUserId(), principal.getRole());

userRepository.updateRefreshToken(principal.getUserId(), jwtTokenDto.refreshToken());

AuthenticationResponse.makeLoginSuccessResponse(response, domain, jwtTokenDto, jwtUtil.getRefreshExpiration());

response.sendRedirect("https://" + domain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public void logout(HttpServletRequest request, HttpServletResponse response, Aut
throw new CommonException(ErrorCode.INVALID_TOKEN_ERROR);
}
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
userRepository.updateRefreshTokenAndLoginStatus(userPrincipal.getUserId(), null);
userRepository.updateRefreshToken(userPrincipal.getUserId(), null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package goormthon.team28.startup_valley.security.info;

import goormthon.team28.startup_valley.security.info.factory.Oauth2UserInfo;

import java.util.Map;

public class DiscordOauth2UserInfo extends Oauth2UserInfo {
public DiscordOauth2UserInfo(Map<String, Object> attributes) {
super(attributes);
}

@Override
public String getId() {
return this.attributes.get("id").toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.core.user.OAuth2User;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

@Getter
@Builder
@RequiredArgsConstructor
public class UserPrincipal implements UserDetails {
public class UserPrincipal implements UserDetails, OAuth2User {
private final Long userId;
private final String password;
private final ERole role;
private final Map<String, Object> attributes;
private final Collection<? extends GrantedAuthority> authorities;

public static UserPrincipal create(UserRepository.UserSecurityForm securityForm){
return UserPrincipal.builder()
.userId(securityForm.getId())
Expand All @@ -29,6 +33,16 @@ public static UserPrincipal create(UserRepository.UserSecurityForm securityForm)
.build();
}

public static UserPrincipal create(UserRepository.UserSecurityForm securityForm, Map<String, Object> attributes) {
return UserPrincipal.builder()
.userId(securityForm.getId())
.password(securityForm.getPassword())
.role(securityForm.getRole())
.attributes(attributes)
.authorities(Collections.singleton(new SimpleGrantedAuthority(securityForm.getRole().getSecurityRole())))
.build();
}

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.authorities;
Expand Down Expand Up @@ -63,4 +77,14 @@ public boolean isCredentialsNonExpired() {
public boolean isEnabled() {
return true;
}

@Override
public Map<String, Object> getAttributes() {
return attributes;
}

@Override
public String getName() {
return userId.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package goormthon.team28.startup_valley.security.info.factory;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;

@Getter
@RequiredArgsConstructor
public abstract class Oauth2UserInfo {
protected final Map<String, Object> attributes;
public abstract String getId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package goormthon.team28.startup_valley.security.info.factory;

import goormthon.team28.startup_valley.dto.type.EProvider;
import goormthon.team28.startup_valley.security.info.DiscordOauth2UserInfo;

import java.util.Map;

public class Oauth2UserInfoFactory {
public static Oauth2UserInfo getOauth2UserInfo(
EProvider provider,
Map<String, Object> attributes
){
Oauth2UserInfo ret;
switch (provider) {
case DISCORD -> ret = new DiscordOauth2UserInfo(attributes);
default -> throw new IllegalAccessError("잘λͺ»λœ 제곡자 μž…λ‹ˆλ‹€.");
}
return ret;
}
}
Loading

0 comments on commit f58cef6

Please sign in to comment.