Skip to content

Commit 96bcf12

Browse files
authored
Merge pull request #5 from isystk/feature/oauth
Google認証を追加
2 parents 0738124 + ab443cf commit 96bcf12

File tree

13 files changed

+81
-10
lines changed

13 files changed

+81
-10
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ subprojects {
7676
implementation("org.springframework.boot:spring-boot-starter-security")
7777
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity5")
7878

79+
/* spring security oauth2 */
80+
implementation("org.springframework.security:spring-security-oauth2-client")
81+
7982
/* mysql */
8083
runtimeOnly("mysql:mysql-connector-java")
8184

business/src/main/java/com/isystk/sample/common/FrontUrl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ public class FrontUrl {
1010
**/
1111
public static final String TOP = "/";
1212
public static final String REGISTER = "/register";
13-
1413
public static final String PASSWORD_RESET = "/password/reset";
1514

1615
public static final String PASSWORD_RESET_CONFIG = "/password/reset/config";
1716

17+
public static final String AUTH_GOOGLE_CALLBACK = "/auth/google/loginSuccess";
18+
1819
/**
1920
* ---- APIs ----
2021
**/

business/src/main/resources/application-common-local.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ spring:
2323
multipart:
2424
max-file-size: 20MB
2525
max-request-size: 20MB
26+
security:
27+
oauth2:
28+
client:
29+
registration:
30+
google:
31+
client-id: "xxxxx"
32+
client-secret: "xxxxx"
33+
redirectUri: "http://localhost:8080/auth/google/loginSuccess"
2634

2735
logging:
2836
level:

business/src/main/resources/application-common-product.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ spring:
2121
multipart:
2222
max-file-size: 20MB
2323
max-request-size: 20MB
24+
security:
25+
oauth2:
26+
client:
27+
registration:
28+
google:
29+
client-id: "xxxxx"
30+
client-secret: "xxxxx"
31+
redirectUri: "https://xxxx/auth/google/loginSuccess"
2432

2533
logging:
2634
level:

business/src/main/resources/application-common-staging.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ spring:
2121
multipart:
2222
max-file-size: 20MB
2323
max-request-size: 20MB
24+
security:
25+
oauth2:
26+
client:
27+
registration:
28+
google:
29+
client-id: "xxxxx"
30+
client-secret: "xxxxx"
31+
redirectUri: "https://xxxx/auth/google/loginSuccess"
2432

2533
logging:
2634
level:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.isystk.sample.web.admin.controller.html.login;
1+
package com.isystk.sample.web.admin.controller.html.auth;
22

33
import static com.isystk.sample.common.Const.*;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.isystk.sample.web.admin.controller.html.login;
1+
package com.isystk.sample.web.admin.controller.html.auth;
22

33
import java.io.Serializable;
44

web-front/resources/src/constants/url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const Url = {
77
/** ログイン処理 */
88
AUTHENTICATE: '/auth/authenticate',
99
/** Googleログイン */
10-
AUTH_GOOGLE: '/auth/google',
10+
AUTH_GOOGLE: '/oauth2/authorization/google',
1111
/** ログアウト */
1212
LOGOUT: '/auth/logout',
1313
/** 会員登録 */

web-front/src/main/java/com/isystk/sample/web/front/SecurityConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ protected void configure(HttpSecurity http) throws Exception {
8282
// ログインIDのパラメータ名
8383
.usernameParameter("loginId")
8484
// パスワードのパラメータ名
85-
.passwordParameter("password").permitAll();
85+
.passwordParameter("password").permitAll()
86+
// OAuth 2.0 Login機能を有効化
87+
.and()
88+
.oauth2Login();
8689

8790
// ログアウト処理
8891
http.logout().logoutRequestMatcher(new AntPathRequestMatcher(LOGOUT_URL))

web-front/src/main/java/com/isystk/sample/web/front/controller/html/IndexController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.isystk.sample.web.front.controller.html;
22

3+
34
import static com.isystk.sample.common.FrontUrl.TOP;
45

56
import com.isystk.sample.web.base.controller.html.AbstractHtmlController;
@@ -19,7 +20,7 @@ public String getFunctionName() {
1920
return "F_TOP";
2021
}
2122

22-
@GetMapping({"/", "{path:(?!^static|swagger-ui$).*}/**"})
23+
@GetMapping({"/", "{path:(?!^static|oauth|swagger-ui$).*}/**"})
2324
public String index(Model model) {
2425
return "modules/index";
2526
}

0 commit comments

Comments
 (0)