diff --git a/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/pom.xml b/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/pom.xml index 8b09fa0..ec2de47 100644 --- a/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/pom.xml +++ b/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/pom.xml @@ -37,5 +37,11 @@ jc-club-auth-domain 1.0-SNAPSHOT + + + cn.dev33 + sa-token-spring-boot-starter + 1.37.0 + diff --git a/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/main/java/com/landaiqing/App.java b/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/main/java/com/landaiqing/App.java deleted file mode 100644 index e623ea3..0000000 --- a/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/main/java/com/landaiqing/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.landaiqing; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} diff --git a/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/main/java/com/landaiqing/auth/application/controller/UserController.java b/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/main/java/com/landaiqing/auth/application/controller/UserController.java new file mode 100644 index 0000000..331071f --- /dev/null +++ b/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/main/java/com/landaiqing/auth/application/controller/UserController.java @@ -0,0 +1,42 @@ +package com.landaiqing.auth.application.controller; + +import cn.dev33.satoken.stp.SaTokenInfo; +import cn.dev33.satoken.stp.StpUtil; +import cn.dev33.satoken.util.SaResult; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Classname UserController + * @BelongsProject: jc-club + * @BelongsPackage: com.landaiqing.auth.application.controller + * @Author: landaiqing + * @CreateTime: 2024-02-18 14:24 + * @Description: TODO + * @Version: 1.0 + */ +@RestController +@RequestMapping("/user/") +public class UserController { + + // 测试登录,浏览器访问: http://localhost:3001/user/doLogin?username=zhang&password=123456 + @RequestMapping("doLogin") + public SaResult doLogin(String username, String password) { + // 此处仅作模拟示例,真实项目需要从数据库中查询数据进行比对 + if("zhang".equals(username) && "123456".equals(password)) { + StpUtil.login(10001); + SaTokenInfo tokenInfo = StpUtil.getTokenInfo(); + // 第3步,返回给前端 + return SaResult.data(tokenInfo); + } + return SaResult.error("登录失败"); + } + + // 查询登录状态,浏览器访问: http://localhost:3001/user/isLogin + @RequestMapping("isLogin") + public String isLogin() { + return "当前会话是否登录:" + StpUtil.isLogin(); + } + +} + diff --git a/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/test/java/com/landaiqing/AppTest.java b/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/test/java/com/landaiqing/AppTest.java deleted file mode 100644 index 908567a..0000000 --- a/jc-club-auth/jc-club-auth-application/jc-club-auth-application-controller/src/test/java/com/landaiqing/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.landaiqing; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} diff --git a/jc-club-auth/jc-club-auth-starter/src/main/resources/application.yml b/jc-club-auth/jc-club-auth-starter/src/main/resources/application.yml index d1c3570..db69bcf 100644 --- a/jc-club-auth/jc-club-auth-starter/src/main/resources/application.yml +++ b/jc-club-auth/jc-club-auth-starter/src/main/resources/application.yml @@ -35,4 +35,22 @@ logging: # configuration: # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +############## Sa-Token 配置 (文档: https://sa-token.cc) ############## +sa-token: + # token 名称(同时也是 cookie 名称) + token-name: satoken + # token 有效期(单位:秒) 默认30天,-1 代表永久有效 + timeout: 2592000 + # token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结 + active-timeout: -1 + # 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录) + is-concurrent: true + # 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token) + is-share: true + # token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik) + token-style: random-32 + # 是否输出操作日志 + is-log: true + token-prefix: auth + diff --git a/jc-club-auth/jc-club-auth-starter/src/test/java/com/landaiqing/AppTest.java b/jc-club-auth/jc-club-auth-starter/src/test/java/com/landaiqing/AppTest.java deleted file mode 100644 index 908567a..0000000 --- a/jc-club-auth/jc-club-auth-starter/src/test/java/com/landaiqing/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.landaiqing; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} diff --git a/jc-club-oss/pom.xml b/jc-club-oss/pom.xml index b49e121..437bb9a 100644 --- a/jc-club-oss/pom.xml +++ b/jc-club-oss/pom.xml @@ -47,11 +47,6 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config - - - - - org.springframework.boot spring-boot-starter-log4j2 diff --git a/jc-club-oss/src/main/java/com/landaiqing/oss/config/StorageConfig.java b/jc-club-oss/src/main/java/com/landaiqing/oss/config/StorageConfig.java index 2ee77b6..038df68 100644 --- a/jc-club-oss/src/main/java/com/landaiqing/oss/config/StorageConfig.java +++ b/jc-club-oss/src/main/java/com/landaiqing/oss/config/StorageConfig.java @@ -20,13 +20,14 @@ import org.springframework.context.annotation.Configuration; @Configuration @RefreshScope public class StorageConfig { + @Value("${storage.service.type}") private String storageType; @Bean @RefreshScope - public StorageAdapter storageService(){ + public StorageAdapter storageService() { if ("minio".equals(storageType)) { return new MinioStorageAdapter(); } else if ("aliyun".equals(storageType)) { diff --git a/jc-club-oss/src/main/resources/application.yml b/jc-club-oss/src/main/resources/application.yml index 1bb3c6a..359b330 100644 --- a/jc-club-oss/src/main/resources/application.yml +++ b/jc-club-oss/src/main/resources/application.yml @@ -4,5 +4,3 @@ minio: url: http://116.196.80.239:9090/ accessKey: landaiqing secretKey: LDQ20020618xxx - -