升级4.0

This commit is contained in:
黑小马 2025-08-26 16:25:14 +08:00
parent 4946911f1c
commit 1c7e608778
11 changed files with 61 additions and 56 deletions

View File

@ -17,14 +17,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 核心依赖-->
<dependency>
<artifactId>hserver</artifactId>
<groupId>cn.hserver</groupId>
</dependency>
<!-- web框架 -->
<dependency>
<artifactId>hserver-plugin-web</artifactId>
<artifactId>hserver-web-starter</artifactId>
<groupId>cn.hserver</groupId>
</dependency>
@ -43,7 +38,12 @@
<artifactId>JustAuth</artifactId>
<version>1.16.7</version>
</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>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -68,7 +68,7 @@
<build>
<plugins>
<plugin>
<artifactId>hserver-plugin-maven</artifactId>
<artifactId>hserver-maven</artifactId>
<groupId>cn.hserver</groupId>
</plugin>
</plugins>

View File

@ -1,12 +1,13 @@
package com.lktx.center;
import cn.hserver.HServerApplication;
import cn.hserver.core.ioc.annotation.HServerBoot;
import cn.hserver.core.boot.HServerApplication;
import cn.hserver.core.boot.annotation.HServerBoot;
import cn.hserver.mvc.constants.WebConstConfig;
@HServerBoot
public class Main {
public static void main(String[] args) {
HServerApplication.run(Main.class,8981, args);
HServerApplication.run(Main.class, args);
}
}

View File

@ -2,16 +2,19 @@ package com.lktx.center.config;
import cn.dev33.satoken.exception.NotLoginException;
import cn.hserver.core.ioc.annotation.Bean;
import cn.hserver.core.server.util.JsonResult;
import cn.hserver.plugin.web.context.Webkit;
import cn.hserver.plugin.web.interfaces.GlobalException;
import cn.hserver.core.ioc.annotation.Component;
import cn.hserver.mvc.common.JsonResult;
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
public void handler(Throwable throwable, int httpStatusCode, String errorDescription, Webkit webkit) {
if (throwable.getCause() instanceof NotLoginException){
webkit.httpResponse.sendJson(JsonResult.error(-2, errorDescription));
public void handlerException(Throwable throwable, WebContext webContext) {
NotLoginException exception = getException(throwable, NotLoginException.class);
if (exception!=null ){
webContext.response.sendJson(JsonResult.error(-2, exception.getMessage()));
}
}
}

View File

@ -1,8 +1,8 @@
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.Configuration;
import cn.hserver.core.ioc.annotation.Value;
import me.zhyd.oauth.config.AuthConfig;
import java.util.List;
@ -10,13 +10,13 @@ import java.util.List;
@Configuration
public class AuthRequestConfig {
@Value("oauth.clientId")
@Value("oauth.client-id")
private String clientId;
@Value("oauth.clientSecret")
@Value("oauth.client-secret")
private String clientSecret;
@Value("oauth.redirectUri")
@Value("oauth.redirect-uri")
private String redirectUri;
@Value("oauth.url")

View File

@ -2,9 +2,9 @@ package com.lktx.center.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.server.util.JsonResult;
import cn.hserver.plugin.web.annotation.Controller;
import cn.hserver.plugin.web.annotation.GET;
import cn.hserver.mvc.annotation.Controller;
import cn.hserver.mvc.annotation.router.GET;
import cn.hserver.mvc.common.JsonResult;
import com.lktx.center.service.AppCenterService;
import java.util.Map;

View File

@ -3,10 +3,9 @@ package com.lktx.center.controller;
import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.plugin.web.annotation.Controller;
import cn.hserver.plugin.web.annotation.GET;
import cn.hserver.plugin.web.interfaces.HttpResponse;
import cn.hutool.json.JSONUtil;
import cn.hserver.mvc.annotation.Controller;
import cn.hserver.mvc.annotation.router.GET;
import cn.hserver.mvc.response.Response;
import com.lktx.center.config.Data;
import com.lktx.center.config.SsoAuthRequest;
import com.lktx.center.domain.bean.SsoApp;
@ -26,7 +25,7 @@ public class HomeController {
private SsoAuthRequest authRequest;
@GET("/")
public void index(HttpResponse response) {
public void index(Response response) {
if (StpUtil.isLogin()){
try {
SaSession session = StpUtil.getSession();

View File

@ -3,12 +3,12 @@ package com.lktx.center.controller;
import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.server.util.JsonResult;
import cn.hserver.plugin.web.annotation.Controller;
import cn.hserver.plugin.web.annotation.GET;
import cn.hserver.plugin.web.annotation.RequestMapping;
import cn.hserver.plugin.web.interfaces.HttpRequest;
import cn.hserver.plugin.web.interfaces.HttpResponse;
import cn.hserver.mvc.annotation.Controller;
import cn.hserver.mvc.annotation.router.GET;
import cn.hserver.mvc.annotation.router.RequestMapping;
import cn.hserver.mvc.common.JsonResult;
import cn.hserver.mvc.request.Request;
import cn.hserver.mvc.response.Response;
import com.lktx.center.config.Data;
import com.lktx.center.config.SsoAuthRequest;
import com.lktx.center.domain.vo.LoginInfo;
@ -27,13 +27,13 @@ public class RestAuthController {
private SsoAuthRequest authRequest;
@RequestMapping("/render")
public void renderAuth(HttpResponse response) {
public void renderAuth(Response response) {
String authorize = authRequest.authorize(AuthStateUtils.createState());
response.redirect(authorize);
}
@RequestMapping("/callback")
public JsonResult login(AuthCallback callback, HttpRequest request) {
public JsonResult login(AuthCallback callback, Request request) {
try {
String rawData = request.getRawData();
System.out.println(rawData);

View File

@ -1,22 +1,23 @@
package com.lktx.center.filter;
import cn.hserver.core.ioc.annotation.Bean;
import cn.hserver.core.ioc.annotation.Component;
import cn.hserver.core.ioc.annotation.Order;
import cn.hserver.plugin.web.context.Webkit;
import cn.hserver.plugin.web.interfaces.FilterAdapter;
import io.netty.handler.codec.http.HttpMethod;
import cn.hserver.mvc.constants.HttpMethod;
import cn.hserver.mvc.context.WebContext;
import cn.hserver.mvc.filter.FilterAdapter;
@Bean
@Component
@Order(1)
public class CorsFilter implements FilterAdapter {
@Override
public void doFilter(Webkit webkit) throws Exception {
webkit.httpResponse.setHeader("Access-Control-Allow-Origin", "*");
webkit.httpResponse.setHeader("Access-Control-Allow-Methods", "*");
webkit.httpResponse.setHeader("Access-Control-Allow-Credentials", "*");
webkit.httpResponse.setHeader("Access-Control-Allow-Headers", "*");
if (webkit.httpRequest.getRequestType().equals(HttpMethod.OPTIONS)) {
webkit.httpResponse.sendHtml("");
public void doFilter(WebContext webkit) throws Exception {
webkit.response.addHeader("Access-Control-Allow-Origin", "*");
webkit.response.addHeader("Access-Control-Allow-Methods", "*");
webkit.response.addHeader("Access-Control-Allow-Credentials", "*");
webkit.response.addHeader("Access-Control-Allow-Headers", "*");
if (webkit.request.getRequestMethod()== HttpMethod.OPTIONS) {
webkit.response.sendHtml("");
}
}
}

View File

@ -3,8 +3,7 @@ package com.lktx.center.service;
import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.ioc.annotation.Bean;
import cn.hserver.core.server.util.JsonResult;
import cn.hserver.core.ioc.annotation.Component;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.lktx.center.config.Data;
@ -18,7 +17,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Bean
@Component
public class AppCenterService {

View File

@ -1,5 +1,7 @@
web:
port: 8981
oauth:
client-id: 65013a3d89d14fab8ff3eb2c0f3981a3
client-secret: 22b5ce70d67f41b79b27cbedb57c976a
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/

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>hserver-parent</artifactId>
<groupId>cn.hserver</groupId>
<version>3.7.0</version>
<version>4.0.0-beta.5</version>
</parent>
<properties>