@@ -84,6 +84,12 @@ | |||
<artifactId>spring-boot-starter-validation</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | |||
</dependency> | |||
</dependencies> | |||
<!-- 构建环境变量 --> |
@@ -66,7 +66,6 @@ public class SecurityConfig { | |||
RequestMatcher endpointsMatcher = authorizationServerConfigurer.getEndpointsMatcher(); | |||
return http.requestMatcher(endpointsMatcher) | |||
//.userDetailsService(userService) | |||
.authorizeRequests((authorizeRequests) -> { | |||
((ExpressionUrlAuthorizationConfigurer.AuthorizedUrl) authorizeRequests.anyRequest()).authenticated(); | |||
}).csrf((csrf) -> { | |||
@@ -87,13 +86,16 @@ public class SecurityConfig { | |||
http.csrf().disable() | |||
.authorizeHttpRequests((authorize) -> authorize | |||
.antMatchers("/getHealth").permitAll() | |||
.antMatchers("/user/create").permitAll() | |||
.antMatchers("/login").permitAll() | |||
.anyRequest().authenticated() | |||
) | |||
// Form login handles the redirect to the login page from the | |||
// authorization server filter chain | |||
.formLogin(Customizer.withDefaults()); | |||
//.formLogin(Customizer.withDefaults()); | |||
.formLogin(form -> | |||
form.loginPage("/login") | |||
.loginProcessingUrl("/login") | |||
); | |||
return http.build(); | |||
} | |||
@@ -0,0 +1,19 @@ | |||
package com.tuoheng.controller; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Controller; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/10/9 14:57 | |||
*/ | |||
@Slf4j | |||
@Controller | |||
public class Oauth2Controller { | |||
@GetMapping("login") | |||
public String login() { | |||
return "login"; | |||
} | |||
} |
@@ -26,7 +26,7 @@ public class OidcUserInfoServiceImpl implements OidcUserInfoService { | |||
@Override | |||
public OidcUserInfo loadUser(String name, Set<String> scopes, UserBaseInfoDto userBaseInfoDto) { | |||
OidcUserInfo.Builder builder = OidcUserInfo.builder().subject(String.valueOf(Calendar.getInstance().getTimeInMillis())); | |||
OidcUserInfo.Builder builder = OidcUserInfo.builder().subject(name); | |||
if (!CollectionUtils.isEmpty(scopes)) { | |||
if (scopes.contains(OidcScopes.PROFILE)) { | |||
builder.claim("userId", userBaseInfoDto.getUserId()) |
@@ -0,0 +1,27 @@ | |||
<!DOCTYPE html> | |||
<html lang="zh" xmlns:th="http://www.thymeleaf.org"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>登录页面</title> | |||
</head> | |||
<body> | |||
<h3>登录</h3> | |||
<form th:action="@{/login}" method="post"> | |||
<table> | |||
<tr> | |||
<td>用户名:</td> | |||
<td><input type="text" name="username"></td> | |||
</tr> | |||
<tr> | |||
<td>密码:</td> | |||
<td><input type="password" name="password"></td> | |||
</tr> | |||
<tr> | |||
<td colspan="2"> | |||
<button type="submit">登录</button> | |||
</td> | |||
</tr> | |||
</table> | |||
</form> | |||
</body> | |||
</html> |