【新增】integrations新增Spring Security OAuth MaxKey SSO

This commit is contained in:
ecoolper
2023-03-22 11:26:47 +08:00
parent abd1bb632c
commit 48f5795d67
20 changed files with 621 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.concretepage</groupId>
<artifactId>spring-demo-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<name>spring-demo-client2</name>
<artifactId>spring-demo-client2</artifactId>
<description> </description>
</project>

View File

@@ -0,0 +1,25 @@
package com.concretepage.client2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.Map;
@Controller
public class AppController {
@GetMapping("hello")
public ModelAndView welcome() {
ModelAndView mav = new ModelAndView();
mav.setViewName("welcome");
return mav;
}
@GetMapping("error")
public ModelAndView error() {
Map<String, String> model = new HashMap<>();
ModelAndView mav = new ModelAndView();
mav.setViewName("error");
return mav;
}
}

View File

@@ -0,0 +1,11 @@
package com.concretepage.client2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainClient2 {
public static void main(String[] args) {
SpringApplication.run(MainClient2.class, args);
}
}

View File

@@ -0,0 +1,21 @@
package com.concretepage.client2;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableOAuth2Sso
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/error**").permitAll()
.anyRequest().authenticated()
.and().logout().logoutUrl("/logout")
.logoutSuccessUrl("http://sso.maxkey.top/sign/force/logout");
}
}

View File

@@ -0,0 +1,22 @@
server:
port: 8081
security:
oauth2:
client:
clientId: 830517174152986624
clientSecret: ElHEMDcwMzIwMjMxNjE5NTAyMTIx1K
accessTokenUri: http://sso.maxkey.top/sign/authz/oauth/v20/token
userAuthorizationUri: http://sso.maxkey.top/sign/authz/oauth/v20/authorize
clientAuthenticationScheme: form
resource:
userInfoUri: http://sso.maxkey.top/sign/api/oauth/v20/me
sso:
login-path: /login
logging:
level:
root: debug
spring:
mvc:
favicon:
enabled: false

View File

@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<title>Spring Security</title>
<link rel="icon" href="data:;base64,=">
</head>
<body>
<h3>Login with <a href="/hello">GitHub</a></h3>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<title>Spring Security</title>
<link rel="icon" href="data:;base64,=">
</head>
<body>
<h3>Error</h3>
<p th:if="${param.error}">
<div th:text="${param.error}"></div>
</p>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<title>Welcome</title>
<link rel="icon" href="data:;base64,=">
</head>
<body>
Welcome <b th:inline="text" > [[${#httpServletRequest.remoteUser}]] </b> <br/><br/>
<form th:action="@{/logout}" method="POST">
<input type="submit" value="Logout"/>
</form>
</body>
</html>