-
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.
추후 베타테스터에 대한 접근 제한 및 서비스 제한적 사용으로 로그인 정책을 추가해야 할 것에 대비
- Loading branch information
1 parent
0bcfaef
commit f7bd7f8
Showing
5 changed files
with
90 additions
and
0 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
48 changes: 48 additions & 0 deletions
48
server/api/src/main/java/vook/server/api/web/common/auth/oauth2/LoginPolicyChecker.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,48 @@ | ||
package vook.server.api.web.common.auth.oauth2; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.security.web.firewall.RequestRejectedException; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class LoginPolicyChecker { | ||
|
||
private final Boolean loginRestrictionEnable; | ||
private final String[] allowedEmails; | ||
|
||
public LoginPolicyChecker( | ||
@Value("${service.loginPolicy.loginRestriction.enable:false}") | ||
Boolean loginRestrictionEnable, | ||
@Value("${service.loginPolicy.loginRestriction.allowedEmails:}") | ||
String[] allowedEmails | ||
) { | ||
this.loginRestrictionEnable = loginRestrictionEnable; | ||
this.allowedEmails = allowedEmails; | ||
} | ||
|
||
public void check(OAuth2Response response) { | ||
if (!loginRestrictionEnable) { | ||
return; | ||
} | ||
|
||
// allowedEmails가 비어 있으면 모든 이메일을 허용 | ||
if (allowedEmails.length != 0 && !isAllowedEmail(response)) { | ||
throw new VookRequestRejectedException("Not allowed email: " + response.getEmail()); | ||
} | ||
} | ||
|
||
private boolean isAllowedEmail(OAuth2Response response) { | ||
for (String allowedEmail : this.allowedEmails) { | ||
if (response.getEmail().equals(allowedEmail)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static class VookRequestRejectedException extends RequestRejectedException { | ||
public VookRequestRejectedException(String message) { | ||
super(message); | ||
} | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
server/api/src/main/java/vook/server/api/web/common/response/GlobalControllerAdvice.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,20 @@ | ||
package vook.server.api.web.common.response; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
@Slf4j | ||
@ControllerAdvice | ||
public class GlobalControllerAdvice { | ||
|
||
@Value("${service.oauth2.loginFailUrl}") | ||
private String loginFailUrl; | ||
|
||
@ExceptionHandler(Exception.class) | ||
public String handleException(Exception e) { | ||
log.error(e.getMessage(), e); | ||
return "redirect:" + loginFailUrl; | ||
} | ||
} |
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