-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from lotteon2/dev-auth-refactoring
dev-auth-refactoring
- Loading branch information
Showing
20 changed files
with
152 additions
and
1,174 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
24 changes: 0 additions & 24 deletions
24
src/main/java/com/bit/lot/flower/auth/oauth/OauthController.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
src/main/java/com/bit/lot/flower/auth/oauth/facade/OauthLoginAccessTokenRequestFacade.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/main/java/com/bit/lot/flower/auth/oauth/facade/OauthUserMeInfoRequestFacade.java
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...main/java/com/bit/lot/flower/auth/oauth/http/util/RequestRestTemplateAccessTokenUtil.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
src/main/java/com/bit/lot/flower/auth/oauth/util/EncryptionUtil.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,39 @@ | ||
package com.bit.lot.flower.auth.oauth.util; | ||
|
||
import java.util.Base64; | ||
import javax.crypto.Cipher; | ||
import javax.crypto.SecretKey; | ||
import javax.crypto.SecretKeyFactory; | ||
import javax.crypto.spec.DESKeySpec; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class EncryptionUtil { | ||
|
||
@Value("${user.info.secret}") | ||
private String SECRET_KEY; | ||
|
||
public String encrypt(String data) throws Exception { | ||
Cipher cipher = getCipher(Cipher.ENCRYPT_MODE); | ||
byte[] encryptedBytes = cipher.doFinal(data.getBytes()); | ||
return Base64.getEncoder().encodeToString(encryptedBytes); | ||
} | ||
|
||
public String decrypt(String encryptedData) throws Exception { | ||
byte[] encryptedBytes = Base64.getDecoder().decode(encryptedData); | ||
Cipher cipher = getCipher(Cipher.DECRYPT_MODE); | ||
byte[] decryptedBytes = cipher.doFinal(encryptedBytes); | ||
return new String(decryptedBytes); | ||
} | ||
|
||
private Cipher getCipher(int mode) throws Exception { | ||
DESKeySpec desKeySpec = new DESKeySpec(SECRET_KEY.getBytes()); | ||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); | ||
SecretKey secretKey = keyFactory.generateSecret(desKeySpec); | ||
|
||
Cipher cipher = Cipher.getInstance("DES"); | ||
cipher.init(mode, secretKey); | ||
return cipher; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/bit/lot/flower/auth/oauth/util/UserInfoCipherHelper.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,47 @@ | ||
package com.bit.lot.flower.auth.oauth.util; | ||
|
||
import com.bit.lot.flower.auth.common.valueobject.AuthId; | ||
import com.bit.lot.flower.auth.social.dto.command.SocialLoginRequestCommand; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class UserInfoCipherHelper { | ||
|
||
private final EncryptionUtil encryptionUtil; | ||
|
||
public String encrpyt(String oauthRedirectURL, | ||
SocialLoginRequestCommand command) throws Exception { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append(oauthRedirectURL) | ||
.append("/") | ||
.append(encryptionUtil.encrypt(command.getSocialId().toString())) | ||
.append("/") | ||
.append(encryptionUtil.encrypt(command.getNickname())) | ||
.append("/") | ||
.append(encryptionUtil.encrypt(command.getEmail())) | ||
.append("/") | ||
.append(command.getPhoneNumber()); | ||
|
||
return sb.toString(); | ||
} | ||
|
||
|
||
public SocialLoginRequestCommand decrypt(SocialLoginRequestCommand command) throws Exception { | ||
String phoneNumber =encryptionUtil.decrypt(command.getPhoneNumber()); | ||
String email = encryptionUtil.decrypt(command.getEmail()); | ||
String socialId = encryptionUtil.decrypt(command.getSocialId().getValue().toString()); | ||
String nickname = encryptionUtil.decrypt(command.getNickname()); | ||
return createDecryptDto(phoneNumber, email, new AuthId(Long.valueOf(socialId)), nickname); | ||
} | ||
|
||
|
||
private SocialLoginRequestCommand createDecryptDto(String phoneNumber, String email, | ||
AuthId socialId, String nickName) { | ||
return SocialLoginRequestCommand.builder().phoneNumber(phoneNumber) | ||
.socialId(socialId).nickname(nickName).email( | ||
email).build(); | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
src/main/java/com/bit/lot/flower/auth/oauth/util/access/GetKakaoAccessKeyHttpUtil.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
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
Oops, something went wrong.