-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactor/#82 : Auth Domain 리팩토링
- Loading branch information
Showing
18 changed files
with
181 additions
and
137 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...th/service/implementation/AuthReader.java → ...omain/auth/implementation/AuthReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...h/service/implementation/AuthUpdater.java → ...main/auth/implementation/AuthUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...service/implementation/AuthValidator.java → ...in/auth/implementation/AuthValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...service/implementation/TokenProvider.java → ...in/auth/implementation/TokenProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/project/bumawiki/domain/auth/infra/BsmLoginHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.project.bumawiki.domain.auth.infra; | ||
|
||
import java.io.IOException; | ||
|
||
import com.project.bumawiki.domain.user.domain.User; | ||
import com.project.bumawiki.domain.user.domain.authority.Authority; | ||
import com.project.bumawiki.global.annotation.Implementation; | ||
import com.project.bumawiki.global.error.exception.BumawikiException; | ||
import com.project.bumawiki.global.error.exception.ErrorCode; | ||
|
||
import leehj050211.bsmOauth.BsmOauth; | ||
import leehj050211.bsmOauth.dto.response.BsmResourceResponse; | ||
import leehj050211.bsmOauth.exceptions.BsmAuthCodeNotFoundException; | ||
import leehj050211.bsmOauth.exceptions.BsmAuthInvalidClientException; | ||
import leehj050211.bsmOauth.exceptions.BsmAuthTokenNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Implementation | ||
@RequiredArgsConstructor | ||
public class BsmLoginHandler { | ||
private final BsmOauth bsmOauth; | ||
|
||
public User getUserByAuthId(String authId) { | ||
try { | ||
String token = bsmOauth.getToken(authId); | ||
BsmResourceResponse response = bsmOauth.getResource(token); | ||
return createUnknownUser(response); | ||
} catch (BsmAuthCodeNotFoundException | BsmAuthTokenNotFoundException e) { | ||
throw new BumawikiException(ErrorCode.INVALID_AUTHID); | ||
} catch (BsmAuthInvalidClientException e) { | ||
throw new BumawikiException(ErrorCode.INVALID_BSM_CLIENT); | ||
} catch (IOException e) { | ||
throw new BumawikiException(ErrorCode.INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
private User createUnknownUser(BsmResourceResponse resource) { | ||
return User.builder() | ||
.email(resource.getEmail()) | ||
.nickName(resource.getNickname()) | ||
.authority(Authority.USER) | ||
.enroll(resource.getStudent().getEnrolledAt()) | ||
.name(resource.getStudent().getName()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...esentation/dto/AccessTokenRequestDto.java → ...auth/presentation/dto/LoginReqestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.project.bumawiki.domain.auth.presentation.dto; | ||
|
||
public record AccessTokenRequestDto( | ||
public record LoginReqestDto( | ||
String accessToken | ||
) { | ||
} |
33 changes: 0 additions & 33 deletions
33
src/main/java/com/project/bumawiki/domain/auth/service/AccessTokenRefreshService.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/main/java/com/project/bumawiki/domain/auth/service/CommandAuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.project.bumawiki.domain.auth.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.project.bumawiki.domain.auth.domain.Token; | ||
import com.project.bumawiki.domain.auth.implementation.AuthReader; | ||
import com.project.bumawiki.domain.auth.implementation.AuthValidator; | ||
import com.project.bumawiki.domain.auth.implementation.TokenProvider; | ||
import com.project.bumawiki.domain.auth.infra.BsmLoginHandler; | ||
import com.project.bumawiki.domain.auth.util.BearerTokenExtractor; | ||
import com.project.bumawiki.domain.user.domain.User; | ||
import com.project.bumawiki.domain.user.implementation.UserCreator; | ||
import com.project.bumawiki.domain.user.implementation.UserReader; | ||
import com.project.bumawiki.domain.user.implementation.UserUpdater; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CommandAuthService { | ||
private final AuthValidator authValidator; | ||
private final AuthReader authReader; | ||
private final BsmLoginHandler bsmLoginHandler; | ||
private final TokenProvider tokenProvider; | ||
private final UserReader userReader; | ||
private final UserCreator userCreator; | ||
private final UserUpdater userUpdater; | ||
|
||
public Token login(String authId) { | ||
User unknownUser = bsmLoginHandler.getUserByAuthId(authId); | ||
User user = userReader.getByEmail(unknownUser.getEmail()); | ||
|
||
if (user == null) { | ||
userCreator.create(unknownUser); | ||
} else { | ||
userUpdater.update(user, unknownUser); | ||
} | ||
|
||
return tokenProvider.createNewTokens(user); | ||
} | ||
|
||
public Token refresh(String bearer) { | ||
String refreshToken = BearerTokenExtractor.extract(bearer); | ||
authValidator.shouldRefreshTokenValid(refreshToken); | ||
|
||
Long userId = authReader.getIdFromJwt(refreshToken); | ||
String accessToken = tokenProvider.createAccessToken(userReader.getById(userId)); | ||
|
||
return new Token(accessToken, refreshToken); | ||
} | ||
} |
66 changes: 0 additions & 66 deletions
66
src/main/java/com/project/bumawiki/domain/auth/service/UserSignUpOrUpdateService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/project/bumawiki/domain/user/implementation/UserCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.project.bumawiki.domain.user.implementation; | ||
|
||
import com.project.bumawiki.domain.user.domain.User; | ||
import com.project.bumawiki.domain.user.domain.repository.UserRepository; | ||
import com.project.bumawiki.global.annotation.Implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Implementation | ||
@RequiredArgsConstructor | ||
public class UserCreator { | ||
private final UserRepository userRepository; | ||
|
||
public void create(User user) { | ||
userRepository.save(user); | ||
} | ||
} |
Oops, something went wrong.