升级4.0
This commit is contained in:
parent
4946911f1c
commit
1c7e608778
16
api/pom.xml
16
api/pom.xml
@ -17,14 +17,9 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- 核心依赖-->
|
|
||||||
<dependency>
|
|
||||||
<artifactId>hserver</artifactId>
|
|
||||||
<groupId>cn.hserver</groupId>
|
|
||||||
</dependency>
|
|
||||||
<!-- web框架 -->
|
<!-- web框架 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<artifactId>hserver-plugin-web</artifactId>
|
<artifactId>hserver-web-starter</artifactId>
|
||||||
<groupId>cn.hserver</groupId>
|
<groupId>cn.hserver</groupId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -43,7 +38,12 @@
|
|||||||
<artifactId>JustAuth</artifactId>
|
<artifactId>JustAuth</artifactId>
|
||||||
<version>1.16.7</version>
|
<version>1.16.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>33.4.8-jre</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@ -68,7 +68,7 @@
|
|||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>hserver-plugin-maven</artifactId>
|
<artifactId>hserver-maven</artifactId>
|
||||||
<groupId>cn.hserver</groupId>
|
<groupId>cn.hserver</groupId>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
package com.lktx.center;
|
package com.lktx.center;
|
||||||
|
|
||||||
|
|
||||||
import cn.hserver.HServerApplication;
|
import cn.hserver.core.boot.HServerApplication;
|
||||||
import cn.hserver.core.ioc.annotation.HServerBoot;
|
import cn.hserver.core.boot.annotation.HServerBoot;
|
||||||
|
import cn.hserver.mvc.constants.WebConstConfig;
|
||||||
|
|
||||||
@HServerBoot
|
@HServerBoot
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HServerApplication.run(Main.class,8981, args);
|
HServerApplication.run(Main.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,16 +2,19 @@ package com.lktx.center.config;
|
|||||||
|
|
||||||
import cn.dev33.satoken.exception.NotLoginException;
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
import cn.hserver.core.ioc.annotation.Bean;
|
import cn.hserver.core.ioc.annotation.Bean;
|
||||||
import cn.hserver.core.server.util.JsonResult;
|
import cn.hserver.core.ioc.annotation.Component;
|
||||||
import cn.hserver.plugin.web.context.Webkit;
|
import cn.hserver.mvc.common.JsonResult;
|
||||||
import cn.hserver.plugin.web.interfaces.GlobalException;
|
import cn.hserver.mvc.context.WebContext;
|
||||||
|
import cn.hserver.mvc.exception.GlobalExceptionHandler;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AllException extends GlobalExceptionHandler {
|
||||||
|
|
||||||
@Bean
|
|
||||||
public class AllException implements GlobalException {
|
|
||||||
@Override
|
@Override
|
||||||
public void handler(Throwable throwable, int httpStatusCode, String errorDescription, Webkit webkit) {
|
public void handlerException(Throwable throwable, WebContext webContext) {
|
||||||
if (throwable.getCause() instanceof NotLoginException){
|
NotLoginException exception = getException(throwable, NotLoginException.class);
|
||||||
webkit.httpResponse.sendJson(JsonResult.error(-2, errorDescription));
|
if (exception!=null ){
|
||||||
|
webContext.response.sendJson(JsonResult.error(-2, exception.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package com.lktx.center.config;
|
package com.lktx.center.config;
|
||||||
|
|
||||||
|
import cn.hserver.core.config.annotation.Configuration;
|
||||||
|
import cn.hserver.core.config.annotation.Value;
|
||||||
import cn.hserver.core.ioc.annotation.Bean;
|
import cn.hserver.core.ioc.annotation.Bean;
|
||||||
import cn.hserver.core.ioc.annotation.Configuration;
|
|
||||||
import cn.hserver.core.ioc.annotation.Value;
|
|
||||||
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -10,13 +10,13 @@ import java.util.List;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class AuthRequestConfig {
|
public class AuthRequestConfig {
|
||||||
|
|
||||||
@Value("oauth.clientId")
|
@Value("oauth.client-id")
|
||||||
private String clientId;
|
private String clientId;
|
||||||
|
|
||||||
@Value("oauth.clientSecret")
|
@Value("oauth.client-secret")
|
||||||
private String clientSecret;
|
private String clientSecret;
|
||||||
|
|
||||||
@Value("oauth.redirectUri")
|
@Value("oauth.redirect-uri")
|
||||||
private String redirectUri;
|
private String redirectUri;
|
||||||
|
|
||||||
@Value("oauth.url")
|
@Value("oauth.url")
|
||||||
|
|||||||
@ -2,9 +2,9 @@ package com.lktx.center.controller;
|
|||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||||
import cn.hserver.core.ioc.annotation.Autowired;
|
import cn.hserver.core.ioc.annotation.Autowired;
|
||||||
import cn.hserver.core.server.util.JsonResult;
|
import cn.hserver.mvc.annotation.Controller;
|
||||||
import cn.hserver.plugin.web.annotation.Controller;
|
import cn.hserver.mvc.annotation.router.GET;
|
||||||
import cn.hserver.plugin.web.annotation.GET;
|
import cn.hserver.mvc.common.JsonResult;
|
||||||
import com.lktx.center.service.AppCenterService;
|
import com.lktx.center.service.AppCenterService;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|||||||
@ -3,10 +3,9 @@ package com.lktx.center.controller;
|
|||||||
import cn.dev33.satoken.session.SaSession;
|
import cn.dev33.satoken.session.SaSession;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hserver.core.ioc.annotation.Autowired;
|
import cn.hserver.core.ioc.annotation.Autowired;
|
||||||
import cn.hserver.plugin.web.annotation.Controller;
|
import cn.hserver.mvc.annotation.Controller;
|
||||||
import cn.hserver.plugin.web.annotation.GET;
|
import cn.hserver.mvc.annotation.router.GET;
|
||||||
import cn.hserver.plugin.web.interfaces.HttpResponse;
|
import cn.hserver.mvc.response.Response;
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import com.lktx.center.config.Data;
|
import com.lktx.center.config.Data;
|
||||||
import com.lktx.center.config.SsoAuthRequest;
|
import com.lktx.center.config.SsoAuthRequest;
|
||||||
import com.lktx.center.domain.bean.SsoApp;
|
import com.lktx.center.domain.bean.SsoApp;
|
||||||
@ -26,7 +25,7 @@ public class HomeController {
|
|||||||
private SsoAuthRequest authRequest;
|
private SsoAuthRequest authRequest;
|
||||||
|
|
||||||
@GET("/")
|
@GET("/")
|
||||||
public void index(HttpResponse response) {
|
public void index(Response response) {
|
||||||
if (StpUtil.isLogin()){
|
if (StpUtil.isLogin()){
|
||||||
try {
|
try {
|
||||||
SaSession session = StpUtil.getSession();
|
SaSession session = StpUtil.getSession();
|
||||||
|
|||||||
@ -3,12 +3,12 @@ package com.lktx.center.controller;
|
|||||||
import cn.dev33.satoken.session.SaSession;
|
import cn.dev33.satoken.session.SaSession;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hserver.core.ioc.annotation.Autowired;
|
import cn.hserver.core.ioc.annotation.Autowired;
|
||||||
import cn.hserver.core.server.util.JsonResult;
|
import cn.hserver.mvc.annotation.Controller;
|
||||||
import cn.hserver.plugin.web.annotation.Controller;
|
import cn.hserver.mvc.annotation.router.GET;
|
||||||
import cn.hserver.plugin.web.annotation.GET;
|
import cn.hserver.mvc.annotation.router.RequestMapping;
|
||||||
import cn.hserver.plugin.web.annotation.RequestMapping;
|
import cn.hserver.mvc.common.JsonResult;
|
||||||
import cn.hserver.plugin.web.interfaces.HttpRequest;
|
import cn.hserver.mvc.request.Request;
|
||||||
import cn.hserver.plugin.web.interfaces.HttpResponse;
|
import cn.hserver.mvc.response.Response;
|
||||||
import com.lktx.center.config.Data;
|
import com.lktx.center.config.Data;
|
||||||
import com.lktx.center.config.SsoAuthRequest;
|
import com.lktx.center.config.SsoAuthRequest;
|
||||||
import com.lktx.center.domain.vo.LoginInfo;
|
import com.lktx.center.domain.vo.LoginInfo;
|
||||||
@ -27,13 +27,13 @@ public class RestAuthController {
|
|||||||
private SsoAuthRequest authRequest;
|
private SsoAuthRequest authRequest;
|
||||||
|
|
||||||
@RequestMapping("/render")
|
@RequestMapping("/render")
|
||||||
public void renderAuth(HttpResponse response) {
|
public void renderAuth(Response response) {
|
||||||
String authorize = authRequest.authorize(AuthStateUtils.createState());
|
String authorize = authRequest.authorize(AuthStateUtils.createState());
|
||||||
response.redirect(authorize);
|
response.redirect(authorize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/callback")
|
@RequestMapping("/callback")
|
||||||
public JsonResult login(AuthCallback callback, HttpRequest request) {
|
public JsonResult login(AuthCallback callback, Request request) {
|
||||||
try {
|
try {
|
||||||
String rawData = request.getRawData();
|
String rawData = request.getRawData();
|
||||||
System.out.println(rawData);
|
System.out.println(rawData);
|
||||||
|
|||||||
@ -1,22 +1,23 @@
|
|||||||
package com.lktx.center.filter;
|
package com.lktx.center.filter;
|
||||||
|
|
||||||
import cn.hserver.core.ioc.annotation.Bean;
|
import cn.hserver.core.ioc.annotation.Bean;
|
||||||
|
import cn.hserver.core.ioc.annotation.Component;
|
||||||
import cn.hserver.core.ioc.annotation.Order;
|
import cn.hserver.core.ioc.annotation.Order;
|
||||||
import cn.hserver.plugin.web.context.Webkit;
|
import cn.hserver.mvc.constants.HttpMethod;
|
||||||
import cn.hserver.plugin.web.interfaces.FilterAdapter;
|
import cn.hserver.mvc.context.WebContext;
|
||||||
import io.netty.handler.codec.http.HttpMethod;
|
import cn.hserver.mvc.filter.FilterAdapter;
|
||||||
|
|
||||||
@Bean
|
@Component
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public class CorsFilter implements FilterAdapter {
|
public class CorsFilter implements FilterAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(Webkit webkit) throws Exception {
|
public void doFilter(WebContext webkit) throws Exception {
|
||||||
webkit.httpResponse.setHeader("Access-Control-Allow-Origin", "*");
|
webkit.response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
webkit.httpResponse.setHeader("Access-Control-Allow-Methods", "*");
|
webkit.response.addHeader("Access-Control-Allow-Methods", "*");
|
||||||
webkit.httpResponse.setHeader("Access-Control-Allow-Credentials", "*");
|
webkit.response.addHeader("Access-Control-Allow-Credentials", "*");
|
||||||
webkit.httpResponse.setHeader("Access-Control-Allow-Headers", "*");
|
webkit.response.addHeader("Access-Control-Allow-Headers", "*");
|
||||||
if (webkit.httpRequest.getRequestType().equals(HttpMethod.OPTIONS)) {
|
if (webkit.request.getRequestMethod()== HttpMethod.OPTIONS) {
|
||||||
webkit.httpResponse.sendHtml("");
|
webkit.response.sendHtml("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,8 +3,7 @@ package com.lktx.center.service;
|
|||||||
import cn.dev33.satoken.session.SaSession;
|
import cn.dev33.satoken.session.SaSession;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hserver.core.ioc.annotation.Autowired;
|
import cn.hserver.core.ioc.annotation.Autowired;
|
||||||
import cn.hserver.core.ioc.annotation.Bean;
|
import cn.hserver.core.ioc.annotation.Component;
|
||||||
import cn.hserver.core.server.util.JsonResult;
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.lktx.center.config.Data;
|
import com.lktx.center.config.Data;
|
||||||
@ -18,7 +17,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Bean
|
@Component
|
||||||
public class AppCenterService {
|
public class AppCenterService {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
web:
|
||||||
|
port: 8981
|
||||||
oauth:
|
oauth:
|
||||||
client-id: 65013a3d89d14fab8ff3eb2c0f3981a3
|
client-id: 65013a3d89d14fab8ff3eb2c0f3981a3
|
||||||
client-secret: 22b5ce70d67f41b79b27cbedb57c976a
|
client-secret: 22b5ce70d67f41b79b27cbedb57c976a
|
||||||
redirect-uri: http://127.0.0.1:5173/login
|
redirect-uri: http://127.0.0.1:5173/login
|
||||||
url: http://192.168.0.206:8911/21/
|
url: http://127.0.0.1:8888/21/
|
||||||
Loading…
x
Reference in New Issue
Block a user