mirror of https://github.com/elunez/eladmin
[代码完善](v2.5): v2.5 beta 更新 fastjson 版本,代码优化
parent
b699d32546
commit
3d53a3a0ec
|
@ -19,7 +19,7 @@ public class RsaUtils {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.out.println("\n");
|
System.out.println("\n");
|
||||||
RSAKeyPair keyPair = generateKeyPair();
|
RsaKeyPair keyPair = generateKeyPair();
|
||||||
System.out.println("公钥:" + keyPair.getPublicKey());
|
System.out.println("公钥:" + keyPair.getPublicKey());
|
||||||
System.out.println("私钥:" + keyPair.getPrivateKey());
|
System.out.println("私钥:" + keyPair.getPrivateKey());
|
||||||
System.out.println("\n");
|
System.out.println("\n");
|
||||||
|
@ -32,7 +32,7 @@ public class RsaUtils {
|
||||||
/**
|
/**
|
||||||
* 公钥加密私钥解密
|
* 公钥加密私钥解密
|
||||||
*/
|
*/
|
||||||
private static void test1(RSAKeyPair keyPair) throws Exception {
|
private static void test1(RsaKeyPair keyPair) throws Exception {
|
||||||
System.out.println("***************** 公钥加密私钥解密开始 *****************");
|
System.out.println("***************** 公钥加密私钥解密开始 *****************");
|
||||||
String text1 = encryptByPublicKey(keyPair.getPublicKey(), RsaUtils.SRC);
|
String text1 = encryptByPublicKey(keyPair.getPublicKey(), RsaUtils.SRC);
|
||||||
String text2 = decryptByPrivateKey(keyPair.getPrivateKey(), text1);
|
String text2 = decryptByPrivateKey(keyPair.getPrivateKey(), text1);
|
||||||
|
@ -51,7 +51,7 @@ public class RsaUtils {
|
||||||
* 私钥加密公钥解密
|
* 私钥加密公钥解密
|
||||||
* @throws Exception /
|
* @throws Exception /
|
||||||
*/
|
*/
|
||||||
private static void test2(RSAKeyPair keyPair) throws Exception {
|
private static void test2(RsaKeyPair keyPair) throws Exception {
|
||||||
System.out.println("***************** 私钥加密公钥解密开始 *****************");
|
System.out.println("***************** 私钥加密公钥解密开始 *****************");
|
||||||
String text1 = encryptByPrivateKey(keyPair.getPrivateKey(), RsaUtils.SRC);
|
String text1 = encryptByPrivateKey(keyPair.getPrivateKey(), RsaUtils.SRC);
|
||||||
String text2 = decryptByPublicKey(keyPair.getPublicKey(), text1);
|
String text2 = decryptByPublicKey(keyPair.getPublicKey(), text1);
|
||||||
|
@ -143,7 +143,7 @@ public class RsaUtils {
|
||||||
* @return /
|
* @return /
|
||||||
* @throws NoSuchAlgorithmException /
|
* @throws NoSuchAlgorithmException /
|
||||||
*/
|
*/
|
||||||
public static RSAKeyPair generateKeyPair() throws NoSuchAlgorithmException {
|
public static RsaKeyPair generateKeyPair() throws NoSuchAlgorithmException {
|
||||||
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
|
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
|
||||||
keyPairGenerator.initialize(1024);
|
keyPairGenerator.initialize(1024);
|
||||||
KeyPair keyPair = keyPairGenerator.generateKeyPair();
|
KeyPair keyPair = keyPairGenerator.generateKeyPair();
|
||||||
|
@ -151,19 +151,19 @@ public class RsaUtils {
|
||||||
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
|
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
|
||||||
String publicKeyString = Base64.encodeBase64String(rsaPublicKey.getEncoded());
|
String publicKeyString = Base64.encodeBase64String(rsaPublicKey.getEncoded());
|
||||||
String privateKeyString = Base64.encodeBase64String(rsaPrivateKey.getEncoded());
|
String privateKeyString = Base64.encodeBase64String(rsaPrivateKey.getEncoded());
|
||||||
return new RSAKeyPair(publicKeyString, privateKeyString);
|
return new RsaKeyPair(publicKeyString, privateKeyString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RSA密钥对对象
|
* RSA密钥对对象
|
||||||
*/
|
*/
|
||||||
public static class RSAKeyPair {
|
public static class RsaKeyPair {
|
||||||
|
|
||||||
private final String publicKey;
|
private final String publicKey;
|
||||||
private final String privateKey;
|
private final String privateKey;
|
||||||
|
|
||||||
public RSAKeyPair(String publicKey, String privateKey) {
|
public RsaKeyPair(String publicKey, String privateKey) {
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
this.privateKey = privateKey;
|
this.privateKey = privateKey;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class AuthorizationController {
|
||||||
|
|
||||||
@Value("${loginCode.expiration}")
|
@Value("${loginCode.expiration}")
|
||||||
private Long expiration;
|
private Long expiration;
|
||||||
@Value("${single.login:false}")
|
@Value("${single.login}")
|
||||||
private Boolean singleLogin;
|
private Boolean singleLogin;
|
||||||
private final SecurityProperties properties;
|
private final SecurityProperties properties;
|
||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
|
@ -114,6 +114,7 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色查询
|
* 根据角色查询
|
||||||
|
* @param ids /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
@Query(value = "SELECT count(1) FROM sys_user u, sys_users_roles r WHERE " +
|
@Query(value = "SELECT count(1) FROM sys_user u, sys_users_roles r WHERE " +
|
||||||
|
|
|
@ -78,8 +78,8 @@ public class RoleServiceImpl implements RoleService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
|
||||||
@Cacheable(key = "'id:' + #p0")
|
@Cacheable(key = "'id:' + #p0")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public RoleDto findById(long id) {
|
public RoleDto findById(long id) {
|
||||||
Role role = roleRepository.findById(id).orElseGet(Role::new);
|
Role role = roleRepository.findById(id).orElseGet(Role::new);
|
||||||
ValidationUtil.isNull(role.getId(),"Role","id",id);
|
ValidationUtil.isNull(role.getId(),"Role","id",id);
|
||||||
|
|
|
@ -68,8 +68,8 @@ public class UserServiceImpl implements UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
|
||||||
@Cacheable(key = "'id:' + #p0")
|
@Cacheable(key = "'id:' + #p0")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public UserDto findById(long id) {
|
public UserDto findById(long id) {
|
||||||
User user = userRepository.findById(id).orElseGet(User::new);
|
User user = userRepository.findById(id).orElseGet(User::new);
|
||||||
ValidationUtil.isNull(user.getId(),"User","id",id);
|
ValidationUtil.isNull(user.getId(),"User","id",id);
|
||||||
|
@ -177,7 +177,7 @@ public class UserServiceImpl implements UserService {
|
||||||
FileUtil.del(oldPath);
|
FileUtil.del(oldPath);
|
||||||
}
|
}
|
||||||
redisUtils.del("user::username:" + user.getUsername());
|
redisUtils.del("user::username:" + user.getUsername());
|
||||||
return new HashMap<String,String>(){{put("avatar",file.getName());}};
|
return new HashMap<String,String>(1){{put("avatar",file.getName());}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,6 +43,11 @@ spring:
|
||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
|
||||||
|
# 是否限制单用户登录
|
||||||
|
single:
|
||||||
|
login: false
|
||||||
|
|
||||||
#jwt
|
#jwt
|
||||||
jwt:
|
jwt:
|
||||||
header: Authorization
|
header: Authorization
|
||||||
|
|
|
@ -45,6 +45,11 @@ spring:
|
||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
|
||||||
|
# 是否限制单用户登录
|
||||||
|
single:
|
||||||
|
login: false
|
||||||
|
|
||||||
#jwt
|
#jwt
|
||||||
jwt:
|
jwt:
|
||||||
header: Authorization
|
header: Authorization
|
||||||
|
|
|
@ -27,9 +27,10 @@ public interface EmailService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新邮件配置
|
* 更新邮件配置
|
||||||
* @param emailConfig 邮件配置
|
* @param emailConfig 邮箱配置
|
||||||
* @param old 旧的配置
|
* @param old /
|
||||||
* @return EmailConfig
|
* @return /
|
||||||
|
* @throws Exception /
|
||||||
*/
|
*/
|
||||||
EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception;
|
EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception;
|
||||||
|
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -32,7 +32,7 @@
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<log4jdbc.version>1.16</log4jdbc.version>
|
<log4jdbc.version>1.16</log4jdbc.version>
|
||||||
<swagger.version>2.9.2</swagger.version>
|
<swagger.version>2.9.2</swagger.version>
|
||||||
<fastjson.version>1.2.68</fastjson.version>
|
<fastjson.version>1.2.70</fastjson.version>
|
||||||
<druid.version>1.1.22</druid.version>
|
<druid.version>1.1.22</druid.version>
|
||||||
<commons-pool2.version>2.5.0</commons-pool2.version>
|
<commons-pool2.version>2.5.0</commons-pool2.version>
|
||||||
<mapstruct.version>1.3.1.Final</mapstruct.version>
|
<mapstruct.version>1.3.1.Final</mapstruct.version>
|
||||||
|
|
Loading…
Reference in New Issue