-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: kakao oauth 연동 및 oauth type별 팩토리 패턴 적용, apple oauth 기초공사
- Loading branch information
1 parent
3ec2245
commit fb65236
Showing
17 changed files
with
248 additions
and
83 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/com/gt/genti/config/auth/AppleOauthAttributes.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,40 @@ | ||
package com.gt.genti.config.auth; | ||
|
||
import java.util.Map; | ||
|
||
import com.gt.genti.domain.enums.OauthType; | ||
|
||
public class AppleOauthAttributes implements OauthAttributes { | ||
|
||
private Map<String, Object> attributes; | ||
// private String nameAttributeKey; | ||
private String name; | ||
private String email; | ||
private final OauthType oauthType = OauthType.APPLE; | ||
|
||
public AppleOauthAttributes(Map<String, Object> attributes) { | ||
this.attributes = attributes; | ||
this.name = (String)attributes.get("name"); | ||
this.email = (String)attributes.get("email"); | ||
} | ||
|
||
@Override | ||
public String getEmail() { | ||
return this.email; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public OauthType getOauthType() { | ||
return this.oauthType; | ||
} | ||
|
||
// @Override | ||
// public OauthAttribute of(Map<String, Object> attribute) { | ||
// return null; | ||
// } | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/gt/genti/config/auth/GoogleOauthAttributes.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,35 @@ | ||
package com.gt.genti.config.auth; | ||
|
||
import java.util.Map; | ||
|
||
import com.gt.genti.domain.enums.OauthType; | ||
|
||
public class GoogleOauthAttributes implements OauthAttributes { | ||
|
||
private Map<String, Object> attributes; | ||
// private String nameAttributeKey; | ||
private String name; | ||
private String email; | ||
private final OauthType oauthType = OauthType.GOOGLE; | ||
|
||
public GoogleOauthAttributes(Map<String, Object> attributes) { | ||
this.attributes = attributes; | ||
this.name = (String)attributes.get("name"); | ||
this.email = (String)attributes.get("email"); | ||
} | ||
|
||
@Override | ||
public String getEmail() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public OauthType getOauthType() { | ||
return this.oauthType; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/gt/genti/config/auth/KakaoOauthAttributes.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,41 @@ | ||
package com.gt.genti.config.auth; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import com.gt.genti.domain.enums.OauthType; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class KakaoOauthAttributes implements OauthAttributes { | ||
|
||
private Map<String, Object> attributes; | ||
// private String nameAttributeKey; | ||
private String nickname; | ||
private String email; | ||
private final OauthType oauthType = OauthType.KAKAO; | ||
|
||
public KakaoOauthAttributes(Map<String, Object> attributes) { | ||
log.info("attributes.toString() : " + attributes.toString()); | ||
Map<String, Object> properties = (Map<String, Object>)attributes.get("properties"); | ||
this.nickname = (String)properties.get("nickname"); | ||
log.info("this.nickname : " + this.nickname); | ||
this.email = UUID.randomUUID().toString(); | ||
} | ||
|
||
@Override | ||
public String getEmail() { | ||
return this.email; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return this.nickname; | ||
} | ||
|
||
@Override | ||
public OauthType getOauthType() { | ||
return this.oauthType; | ||
} | ||
} |
54 changes: 4 additions & 50 deletions
54
src/main/java/com/gt/genti/config/auth/OAuthAttributes.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,55 +1,9 @@ | ||
package com.gt.genti.config.auth; | ||
|
||
import java.util.Map; | ||
|
||
import com.gt.genti.domain.enums.OauthType; | ||
import com.gt.genti.domain.enums.converter.EnumUtil; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class OAuthAttributes { | ||
private Map<String, Object> attributes; | ||
private String nameAttributeKey; | ||
private String name; | ||
private String email; | ||
|
||
@Builder | ||
public OAuthAttributes(Map<String, Object> attributes, String nameAttributeKey, String name, String email) { | ||
this.attributes = attributes; | ||
this.nameAttributeKey = nameAttributeKey; | ||
this.name = name; | ||
this.email = email; | ||
} | ||
|
||
public static OAuthAttributes of(String registrationId, String userNameAttributeName, | ||
Map<String, Object> attributes) { | ||
OauthType oauthType = EnumUtil.stringToEnum(OauthType.class, registrationId); | ||
switch (oauthType) { | ||
case GOOGLE -> { | ||
return ofGoogle(userNameAttributeName, attributes); | ||
} | ||
case KAKAO -> { | ||
// return ofGoogle(userNameAttributeName, attributes); | ||
} | ||
case APPLE -> { | ||
// return ofGoogle(userNameAttributeName, attributes); | ||
} | ||
case NULL -> { | ||
|
||
} | ||
} | ||
throw new RuntimeException("등록되지 않은 oauth type? "); | ||
} | ||
|
||
private static OAuthAttributes ofGoogle(String userNameAttributeName, Map<String, Object> attributes) { | ||
return OAuthAttributes.builder() | ||
.name((String)attributes.get("name")) | ||
.email((String)attributes.get("email")) | ||
.attributes(attributes) | ||
.nameAttributeKey(userNameAttributeName) | ||
.build(); | ||
} | ||
|
||
public interface OauthAttributes { | ||
String getEmail(); | ||
String getUsername(); | ||
OauthType getOauthType(); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/gt/genti/config/auth/OauthAttributeBuilder.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.gt.genti.config.auth; | ||
|
||
import java.util.Map; | ||
|
||
import com.gt.genti.domain.enums.OauthType; | ||
import com.gt.genti.domain.enums.converter.EnumUtil; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Getter | ||
@Slf4j | ||
public class OauthAttributeBuilder { | ||
private Map<String, Object> attributes; | ||
// private String nameAttributeKey; | ||
private String name; | ||
private String email; | ||
|
||
@Builder | ||
public OauthAttributeBuilder(Map<String, Object> attributes, String nameAttributeKey, String name, String email) { | ||
this.attributes = attributes; | ||
// this.nameAttributeKey = nameAttributeKey; | ||
this.name = name; | ||
this.email = email; | ||
} | ||
|
||
public static OauthAttributes of(String registrationId, Map<String, Object> attributes) { | ||
OauthType oauthType = EnumUtil.stringToEnumIgnoreCase(OauthType.class, registrationId); | ||
switch (oauthType) { | ||
case GOOGLE -> { | ||
return new GoogleOauthAttributes(attributes); | ||
} | ||
case KAKAO -> { | ||
return new KakaoOauthAttributes(attributes); | ||
} | ||
case APPLE -> { | ||
return new AppleOauthAttributes(attributes); | ||
} | ||
case NULL -> { | ||
|
||
} | ||
} | ||
throw new RuntimeException("등록되지 않은 oauth type :" + registrationId); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/gt/genti/domain/enums/converter/IgnoreCaseStringAttributeConverter.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,21 @@ | ||
package com.gt.genti.domain.enums.converter; | ||
|
||
import com.gt.genti.domain.enums.ConvertableEnum; | ||
|
||
public class IgnoreCaseStringAttributeConverter<T extends Enum<T> & ConvertableEnum> | ||
extends DefaultStringAttributeConverter<T> { | ||
public IgnoreCaseStringAttributeConverter(Class<T> enumClassType) { | ||
super(enumClassType); | ||
} | ||
|
||
@Override | ||
public String convertToDatabaseColumn(T attribute) { | ||
return attribute.getStringValue().toUpperCase(); | ||
} | ||
|
||
@Override | ||
public T convertToEntityAttribute(String dbData) { | ||
return EnumUtil.stringToEnumIgnoreCase(getEnumClassType(), dbData); | ||
} | ||
|
||
} |
Oops, something went wrong.