feat: auth develop
This commit is contained in:
@@ -37,5 +37,11 @@
|
|||||||
<artifactId>jc-club-auth-domain</artifactId>
|
<artifactId>jc-club-auth-domain</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||||
|
<version>1.37.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
package com.landaiqing;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hello world!
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class App
|
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
System.out.println( "Hello World!" );
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -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 );
|
|
||||||
}
|
|
||||||
}
|
|
@@ -35,4 +35,22 @@ logging:
|
|||||||
# configuration:
|
# configuration:
|
||||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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 );
|
|
||||||
}
|
|
||||||
}
|
|
@@ -47,11 +47,6 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.alibaba.boot</groupId>-->
|
|
||||||
<!-- <artifactId>nacos-config-spring-boot-starter</artifactId>-->
|
|
||||||
<!-- <version>0.2.11</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||||
|
@@ -20,13 +20,14 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
public class StorageConfig {
|
public class StorageConfig {
|
||||||
|
|
||||||
@Value("${storage.service.type}")
|
@Value("${storage.service.type}")
|
||||||
private String storageType;
|
private String storageType;
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
public StorageAdapter storageService(){
|
public StorageAdapter storageService() {
|
||||||
if ("minio".equals(storageType)) {
|
if ("minio".equals(storageType)) {
|
||||||
return new MinioStorageAdapter();
|
return new MinioStorageAdapter();
|
||||||
} else if ("aliyun".equals(storageType)) {
|
} else if ("aliyun".equals(storageType)) {
|
||||||
|
@@ -4,5 +4,3 @@ minio:
|
|||||||
url: http://116.196.80.239:9090/
|
url: http://116.196.80.239:9090/
|
||||||
accessKey: landaiqing
|
accessKey: landaiqing
|
||||||
secretKey: LDQ20020618xxx
|
secretKey: LDQ20020618xxx
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user