Browse Source

first commit

tags/V2.2.0
chenjiandong 2 years ago
parent
commit
6d0dd2443c
5 changed files with 59 additions and 5 deletions
  1. +6
    -0
      Spring_Authorization_Server/pom.xml
  2. +6
    -4
      Spring_Authorization_Server/src/main/java/com/tuoheng/config/SecurityConfig.java
  3. +19
    -0
      Spring_Authorization_Server/src/main/java/com/tuoheng/controller/Oauth2Controller.java
  4. +1
    -1
      Spring_Authorization_Server/src/main/java/com/tuoheng/service/impl/OidcUserInfoServiceImpl.java
  5. +27
    -0
      Spring_Authorization_Server/src/main/resources/templates/login.html

+ 6
- 0
Spring_Authorization_Server/pom.xml View File

@@ -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>

<!-- 构建环境变量 -->

+ 6
- 4
Spring_Authorization_Server/src/main/java/com/tuoheng/config/SecurityConfig.java View File

@@ -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();
}


+ 19
- 0
Spring_Authorization_Server/src/main/java/com/tuoheng/controller/Oauth2Controller.java View File

@@ -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";
}
}

+ 1
- 1
Spring_Authorization_Server/src/main/java/com/tuoheng/service/impl/OidcUserInfoServiceImpl.java View File

@@ -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())

+ 27
- 0
Spring_Authorization_Server/src/main/resources/templates/login.html View File

@@ -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>

Loading…
Cancel
Save