google sso
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package io.bluemoon.authorizationserver.config;
|
||||
|
||||
import io.bluemoon.authorizationserver.config.handler.CustomAuthFailureHandler;
|
||||
import io.bluemoon.authorizationserver.service.user.CustomUserDetailsServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -12,7 +14,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||
//import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
|
||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
||||
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
|
||||
import org.springframework.security.web.csrf.CsrfFilter;
|
||||
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||
|
||||
@@ -22,6 +26,9 @@ import org.springframework.web.filter.CharacterEncodingFilter;
|
||||
@Order(-1)
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
CustomAuthFailureHandler customAuthFailureHandler;
|
||||
|
||||
private CustomUserDetailsServiceImpl customUserDetailsService;
|
||||
|
||||
public WebSecurityConfig(
|
||||
@@ -58,8 +65,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
// .loginPage("/login").permitAll()
|
||||
//// .defaultSuccessUrl("http://localhost:8765/login")
|
||||
// .failureUrl("/loginFailure")
|
||||
// .and()
|
||||
// .headers().frameOptions().disable()
|
||||
|
||||
// .and()
|
||||
// .exceptionHandling()
|
||||
// .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login"))
|
||||
@@ -78,8 +84,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.and()
|
||||
.authorizeRequests().anyRequest().authenticated()
|
||||
.and()
|
||||
.headers().frameOptions().disable()
|
||||
.and()
|
||||
.oauth2Login()
|
||||
.loginPage("/login").defaultSuccessUrl("/mk-auth/login/success").permitAll();
|
||||
// .loginPage("/login").defaultSuccessUrl("/mk-auth/login/success").permitAll();
|
||||
.loginPage("/login").permitAll().defaultSuccessUrl("/login/success", true).failureHandler(customAuthFailureHandler);
|
||||
// .and()
|
||||
// .addFilterBefore(filter, CsrfFilter.class);
|
||||
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
package io.bluemoon.authorizationserver.config.handler;
|
||||
|
||||
public class CustomAuthFailureHandler {
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CustomAuthFailureHandler implements AuthenticationFailureHandler {
|
||||
@Override
|
||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
|
||||
// logging 붙이기
|
||||
System.out.println(exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
package io.bluemoon.authorizationserver.config.handler;
|
||||
|
||||
public class CustomAuthSuccessHandler {
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CustomAuthSuccessHandler implements AuthenticationSuccessHandler {
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
||||
// logging 붙이기
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,18 +81,20 @@ public class SsoController {
|
||||
return user;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/login/success")
|
||||
public String loginComplete(@SocialUser User user) {
|
||||
System.out.println(user);
|
||||
return "redirect:/user";
|
||||
}
|
||||
|
||||
// @GetMapping(value = "/login/success")
|
||||
// @ResponseBody
|
||||
// public String test2() {
|
||||
// return "kkk";
|
||||
// public String loginComplete(@SocialUser User user) {
|
||||
// System.out.println(user);
|
||||
// return "redirect:/mk-auth/login/user";
|
||||
//// return "why not";
|
||||
// }
|
||||
|
||||
@GetMapping(value = "/login/success")
|
||||
@ResponseBody
|
||||
public String test2() {
|
||||
return "kkk";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a class="facebook-login-text" href="/mk-auth/oauth2/authorization/facebook">facebook으로 로그인</a>
|
||||
<a class="facebook-login-text" href="/mk-auth/oauth2/authorization/facebook">facebook 로그인</a>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a class="facebook-login-text" href="/mk-auth/oauth2/authorization/google">facebook으로 로그인</a>
|
||||
<a class="google-login-text" href="/mk-auth/oauth2/authorization/google">google 로그인</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,6 +8,7 @@ zuul.routes.mk2-service.sensitive-headers=
|
||||
|
||||
zuul.routes.mk2-oauth.path=/mk-auth/**
|
||||
zuul.routes.mk2-oauth.url=https://59a7bc58.ngrok.io
|
||||
#zuul.routes.mk2-oauth.url=http://localhost:8081
|
||||
zuul.routes.mk2-oauth.sensitive-headers=
|
||||
#zuul.routes.mk2-oauth.path=/mk2auth/**
|
||||
|
||||
@@ -18,14 +19,17 @@ security.oauth2.sso.login-path=/login
|
||||
|
||||
|
||||
|
||||
#security.oauth2.client.access-token-uri=http://localhost:8081/mk-auth/oauth/token
|
||||
security.oauth2.client.access-token-uri=https://59a7bc58.ngrok.io/mk-auth/oauth/token
|
||||
|
||||
# /oauth/authorize 요청은 클라이언트가 리소스 서버의 api를 사용하기 위해 사용자(리소스 소유자)에게
|
||||
# 권한 위임 동의를 받기 위한 페이지를 출력하는 기능을 수행
|
||||
#security.oauth2.client.user-authorization-uri=http://localhost:8081/mk-auth/oauth/authorize
|
||||
security.oauth2.client.user-authorization-uri=https://59a7bc58.ngrok.io/mk-auth/oauth/authorize
|
||||
|
||||
#security.oauth2.resource.user-info-uri=http://localhost:8081/mk-auth/user
|
||||
security.oauth2.resource.user-info-uri=https://59a7bc58.ngrok.io/mk-auth/user
|
||||
#security.oauth2.resource.prefer-token-info=false
|
||||
security.oauth2.resource.prefer-token-info=false
|
||||
|
||||
security.oauth2.client.client-id=system1
|
||||
security.oauth2.client.client-secret=1234
|
||||
|
||||
Reference in New Issue
Block a user