mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-01-27 20:21:56 +08:00
添加lombok,MyBatis动态SQL和代码生成器
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.auth.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/1
|
||||
*/
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConfigurationProperties(prefix = "special.auth")
|
||||
public class SpecialAuthProperties {
|
||||
|
||||
private Boolean loginEnabled;
|
||||
|
||||
public Boolean getLoginEnabled() {
|
||||
return loginEnabled;
|
||||
}
|
||||
|
||||
public void setLoginEnabled(Boolean loginEnabled) {
|
||||
this.loginEnabled = loginEnabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.auth.controller;
|
||||
|
||||
import com.ruoyi.auth.config.SpecialAuthProperties;
|
||||
import com.ruoyi.auth.form.LoginBody;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 特殊登录控制
|
||||
*
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/1
|
||||
*/
|
||||
@RequestMapping("/specialAuth")
|
||||
@RestController
|
||||
public class SpecialAuthController {
|
||||
|
||||
@Resource
|
||||
private TokenController tokenController;
|
||||
@Resource
|
||||
private SpecialAuthProperties specialAuthProperties;
|
||||
|
||||
/**
|
||||
* 不需要验证码的登录(哪怕开启了验证码功能)
|
||||
*/
|
||||
@PostMapping("login")
|
||||
public R<?> login(@RequestBody LoginBody form) {
|
||||
if (specialAuthProperties.getLoginEnabled() == null || !specialAuthProperties.getLoginEnabled()) {
|
||||
return R.fail("Special login is not enabled.");
|
||||
} else {
|
||||
return tokenController.login(form);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
43
ruoyi-auth/src/test/java/ryas/test/TokenTest.java
Normal file
43
ruoyi-auth/src/test/java/ryas/test/TokenTest.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package ryas.test;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.utils.JwtUtils;
|
||||
import com.ruoyi.common.core.utils.uuid.IdUtils;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/1
|
||||
*/
|
||||
public class TokenTest {
|
||||
|
||||
@Test
|
||||
public void createToken() {
|
||||
int userId = 1;
|
||||
String userName = "管理员";
|
||||
|
||||
String userKey = IdUtils.fastUUID();
|
||||
Map<String, Object> claimsMap = new HashMap<>();
|
||||
claimsMap.put(SecurityConstants.USER_KEY, userKey);
|
||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||
|
||||
String token = JwtUtils.createToken(claimsMap);
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseToken() {
|
||||
String token = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjhkZDc5ZDcxLTg3MGYtNDliMy1hNGVkLTQxNzI5OTdmNTcxNCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.b5230z65JXGzz-JpIa_1fSkDs_gct4nbuQ0wexW78POxixTzyeBAksh1pUUU9hEPW2_cIpK1MSF6ypi9RhxtxQ";
|
||||
|
||||
Claims claims = JwtUtils.parseToken(token);
|
||||
for (Map.Entry<String, Object> entry : claims.entrySet()) {
|
||||
System.out.println(entry.getKey() + ": " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user