-
Notifications
You must be signed in to change notification settings - Fork 6
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
[BE/FEAT] 토큰 저장소를 redis로 변경한다.
- Loading branch information
Showing
36 changed files
with
281 additions
and
326 deletions.
There are no files selected for viewing
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
24 changes: 0 additions & 24 deletions
24
...ava/com/blackcompany/eeos/auth/application/domain/converter/OauthInfoEntityConverter.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...a/com/blackcompany/eeos/auth/application/domain/converter/OauthMemberEntityConverter.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,24 @@ | ||
package com.blackcompany.eeos.auth.application.domain.converter; | ||
|
||
import com.blackcompany.eeos.auth.application.domain.OauthMemberModel; | ||
import com.blackcompany.eeos.auth.persistence.OAuthMemberEntity; | ||
import com.blackcompany.eeos.common.support.converter.AbstractEntityConverter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OauthMemberEntityConverter | ||
implements AbstractEntityConverter<OAuthMemberEntity, OauthMemberModel> { | ||
@Override | ||
public OauthMemberModel from(final OAuthMemberEntity entity) { | ||
return OauthMemberModel.builder().oauthId(entity.getOauthId()).build(); | ||
} | ||
|
||
@Override | ||
public OAuthMemberEntity toEntity(final OauthMemberModel model) { | ||
return OAuthMemberEntity.builder().oauthId(model.getOauthId()).build(); | ||
} | ||
|
||
public OAuthMemberEntity toEntity(final String oauthId, Long memberId) { | ||
return OAuthMemberEntity.builder().oauthId(oauthId).memberId(memberId).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
30 changes: 14 additions & 16 deletions
30
BE/eeos/src/main/java/com/blackcompany/eeos/auth/application/service/AuthService.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,44 +1,42 @@ | ||
package com.blackcompany.eeos.auth.application.service; | ||
|
||
import com.blackcompany.eeos.auth.application.domain.OauthMemberModel; | ||
import com.blackcompany.eeos.auth.application.domain.converter.OauthInfoEntityConverter; | ||
import com.blackcompany.eeos.auth.persistence.OauthInfoEntity; | ||
import com.blackcompany.eeos.auth.persistence.OauthInfoRepository; | ||
import com.blackcompany.eeos.auth.application.domain.converter.OauthMemberEntityConverter; | ||
import com.blackcompany.eeos.auth.persistence.OAuthMemberEntity; | ||
import com.blackcompany.eeos.auth.persistence.OAuthMemberRepository; | ||
import com.blackcompany.eeos.member.application.model.converter.MemberEntityConverter; | ||
import com.blackcompany.eeos.member.persistence.MemberEntity; | ||
import com.blackcompany.eeos.member.persistence.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AuthService { | ||
|
||
private final OauthInfoRepository oauthInfoRepository; | ||
private final MemberRepository memberRepository; | ||
private final OAuthMemberRepository oAuthMemberRepository; | ||
private final MemberEntityConverter memberEntityConverter; | ||
private final OauthInfoEntityConverter oauthInfoEntityConverter; | ||
private final OauthMemberEntityConverter oauthMemberEntityConverter; | ||
|
||
@Transactional(propagation = Propagation.REQUIRED) | ||
public OauthInfoEntity login(final OauthMemberModel model) { | ||
return oauthInfoRepository | ||
@Transactional | ||
public OAuthMemberEntity authenticate(final OauthMemberModel model) { | ||
return oAuthMemberRepository | ||
.findByOauthId(model.getOauthId()) | ||
.orElseGet(() -> signUpMember(model)); | ||
} | ||
|
||
private OauthInfoEntity signUpMember(final OauthMemberModel model) { | ||
private OAuthMemberEntity signUpMember(final OauthMemberModel model) { | ||
MemberEntity entity = | ||
memberEntityConverter.toEntity(model.getName(), model.getOauthServerType()); | ||
|
||
MemberEntity savedMember = memberRepository.save(entity); | ||
return createOauthInfoEntity(model.getOauthId(), savedMember.getId()); | ||
return saveOauthInfoEntity(model.getOauthId(), savedMember.getId()); | ||
} | ||
|
||
private OauthInfoEntity createOauthInfoEntity(final String oauthId, final Long memberId) { | ||
OauthInfoEntity entity = oauthInfoEntityConverter.toEntity(oauthId, memberId); | ||
return oauthInfoRepository.save(entity); | ||
private OAuthMemberEntity saveOauthInfoEntity(final String oauthId, final Long memberId) { | ||
OAuthMemberEntity entity = oauthMemberEntityConverter.toEntity(oauthId, memberId); | ||
return oAuthMemberRepository.save(entity); | ||
} | ||
} |
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
23 changes: 4 additions & 19 deletions
23
...plication/service/CreateTokenService.java → ...support/AuthenticationTokenGenerator.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,42 +1,27 @@ | ||
package com.blackcompany.eeos.auth.application.service; | ||
package com.blackcompany.eeos.auth.application.support; | ||
|
||
import com.blackcompany.eeos.auth.application.domain.TokenModel; | ||
import com.blackcompany.eeos.auth.application.domain.converter.TokenModelConverter; | ||
import com.blackcompany.eeos.auth.application.domain.token.TokenProvider; | ||
import com.blackcompany.eeos.auth.application.domain.token.TokenResolver; | ||
import com.blackcompany.eeos.auth.persistence.AuthInfoEntity; | ||
import com.blackcompany.eeos.auth.persistence.AuthInfoEntityConverter; | ||
import com.blackcompany.eeos.auth.persistence.AuthInfoRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Service | ||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CreateTokenService { | ||
public class AuthenticationTokenGenerator { | ||
private final TokenProvider tokenProvider; | ||
private final TokenModelConverter tokenModelConverter; | ||
private final TokenResolver tokenResolver; | ||
private final AuthInfoRepository authInfoRepository; | ||
private final AuthInfoEntityConverter authInfoEntityConverter; | ||
|
||
@Transactional | ||
public TokenModel execute(final Long memberId) { | ||
String accessToken = tokenProvider.createAccessToken(memberId); | ||
String refreshToken = tokenProvider.createRefreshToken(memberId); | ||
|
||
saveToken(memberId, refreshToken); | ||
|
||
return tokenModelConverter.from( | ||
accessToken, | ||
tokenResolver.getExpiredDateByHeader(accessToken), | ||
refreshToken, | ||
tokenResolver.getExpiredDateByCookie(refreshToken)); | ||
} | ||
|
||
private void saveToken(final Long memberId, final String token) { | ||
AuthInfoEntity authInfoEntity = authInfoEntityConverter.from(memberId, token); | ||
authInfoRepository.save(authInfoEntity); | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
BE/eeos/src/main/java/com/blackcompany/eeos/auth/persistence/AuthInfoEntity.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
BE/eeos/src/main/java/com/blackcompany/eeos/auth/persistence/AuthInfoEntityConverter.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
BE/eeos/src/main/java/com/blackcompany/eeos/auth/persistence/AuthInfoRepository.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
BE/eeos/src/main/java/com/blackcompany/eeos/auth/persistence/MemberAuthenticationEntity.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,22 @@ | ||
package com.blackcompany.eeos.auth.persistence; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
@RedisHash("MemberAuthentication") | ||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class MemberAuthenticationEntity { | ||
@Id private String token; | ||
private Long memberId; | ||
@TimeToLive private Long expiration; | ||
} |
Oops, something went wrong.