mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add methods
This commit is contained in:
parent
63fc4d175b
commit
7dc5873d9e
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.0 (2021-06-11)
|
||||
# 5.7.0 (2021-06-12)
|
||||
|
||||
### 🐣新特性
|
||||
* 【jwt 】 添加JWT模块,实现了JWT的创建、解析和验证
|
||||
@ -11,7 +11,8 @@
|
||||
* 【crypto 】 MacEngine增加接口update,doFinal,reset等接口
|
||||
* 【core 】 StrSpliter更名为StrSplitter
|
||||
* 【core 】 NumberUtil的decimalFormat增加数字检查
|
||||
* 【http 】 HttpBase的httpVersion方法设置为无效(issue#1644)
|
||||
* 【http 】 HttpBase的httpVersion方法设置为无效(issue#1644@Github)
|
||||
* 【extra 】 Sftp增加download重载(issue#I3VBSL@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
|
||||
|
@ -302,6 +302,24 @@ public class BeanUtilTest {
|
||||
Assert.assertTrue(p3.getSlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyPropertiesIgnoreNullTest() {
|
||||
SubPerson p1 = new SubPerson();
|
||||
p1.setSlow(true);
|
||||
p1.setName(null);
|
||||
|
||||
SubPerson2 p2 = new SubPerson2();
|
||||
p2.setName("oldName");
|
||||
|
||||
// null值不覆盖目标属性
|
||||
BeanUtil.copyProperties(p1, p2, CopyOptions.create().ignoreNullValue());
|
||||
Assert.assertEquals("oldName", p2.getName());
|
||||
|
||||
// null覆盖目标属性
|
||||
BeanUtil.copyProperties(p1, p2);
|
||||
Assert.assertNull(p2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyPropertiesBeanToMapTest() {
|
||||
// 测试BeanToMap
|
||||
|
@ -16,6 +16,7 @@ import com.jcraft.jsch.SftpException;
|
||||
import com.jcraft.jsch.SftpProgressMonitor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -172,12 +173,12 @@ public class Sftp extends AbstractFtp {
|
||||
|
||||
@Override
|
||||
public Sftp reconnectIfTimeout() {
|
||||
if(StrUtil.isBlank(this.ftpConfig.getHost())){
|
||||
if (StrUtil.isBlank(this.ftpConfig.getHost())) {
|
||||
throw new FtpException("Host is blank!");
|
||||
}
|
||||
try{
|
||||
try {
|
||||
this.cd(StrUtil.SLASH);
|
||||
} catch (FtpException e){
|
||||
} catch (FtpException e) {
|
||||
close();
|
||||
init();
|
||||
}
|
||||
@ -333,7 +334,7 @@ public class Sftp extends AbstractFtp {
|
||||
* @throws FtpException 进入目录失败异常
|
||||
*/
|
||||
@Override
|
||||
synchronized public boolean cd(String directory) throws FtpException{
|
||||
synchronized public boolean cd(String directory) throws FtpException {
|
||||
if (StrUtil.isBlank(directory)) {
|
||||
// 当前目录
|
||||
return true;
|
||||
@ -459,6 +460,17 @@ public class Sftp extends AbstractFtp {
|
||||
get(src, FileUtil.getAbsolutePath(destFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件到{@link OutputStream}中
|
||||
*
|
||||
* @param src 源文件路径,包括文件名
|
||||
* @param out 目标流
|
||||
* @see #get(String, OutputStream)
|
||||
*/
|
||||
public void download(String src, OutputStream out) {
|
||||
get(src, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归下载FTP服务器上文件到本地(文件目录和服务器同步)
|
||||
*
|
||||
@ -506,6 +518,23 @@ public class Sftp extends AbstractFtp {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程文件
|
||||
*
|
||||
* @param src 远程文件路径
|
||||
* @param out 目标流
|
||||
* @return this
|
||||
* @since 5.7.0
|
||||
*/
|
||||
public Sftp get(String src, OutputStream out) {
|
||||
try {
|
||||
channel.get(src, out);
|
||||
} catch (SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
JschUtil.close(this.channel);
|
||||
|
@ -67,8 +67,8 @@ public class Claims implements Serializable {
|
||||
*
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public String getClaimsJson() {
|
||||
return this.claimJSON.toString();
|
||||
public JSONObject getClaimsJson() {
|
||||
return this.claimJSON;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,4 +80,9 @@ public class Claims implements Serializable {
|
||||
public void parse(String tokenPart, Charset charset) {
|
||||
this.claimJSON = JSONUtil.parseObj(Base64.decodeStr(tokenPart, charset));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.claimJSON.toString();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.jwt.signers.AlgorithmUtil;
|
||||
import cn.hutool.jwt.signers.JWTSigner;
|
||||
import cn.hutool.jwt.signers.JWTSignerUtil;
|
||||
@ -103,7 +104,7 @@ public class JWT {
|
||||
/**
|
||||
* 设置密钥,默认算法是:HS256(HmacSHA256)
|
||||
*
|
||||
* @param key 密钥
|
||||
* @param key 密钥
|
||||
* @return this
|
||||
*/
|
||||
public JWT setKey(byte[] key) {
|
||||
@ -132,6 +133,15 @@ public class JWT {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有头信息
|
||||
*
|
||||
* @return 头信息
|
||||
*/
|
||||
public JSONObject getHeaders() {
|
||||
return this.header.getClaimsJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取头信息
|
||||
*
|
||||
@ -142,6 +152,16 @@ public class JWT {
|
||||
return this.header.getClaim(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取算法ID(alg)头信息
|
||||
*
|
||||
* @return 算法头信息
|
||||
* @see JWTHeader#ALGORITHM
|
||||
*/
|
||||
public String getAlgorithm() {
|
||||
return (String) this.header.getClaim(JWTHeader.ALGORITHM);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置JWT头信息
|
||||
*
|
||||
@ -161,10 +181,19 @@ public class JWT {
|
||||
* @return this
|
||||
*/
|
||||
public JWT addHeaders(Map<String, ?> headers) {
|
||||
this.header.addHeaders(headers);
|
||||
this.header.addHeaders(headers);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有载荷信息
|
||||
*
|
||||
* @return 载荷信息
|
||||
*/
|
||||
public JSONObject getPayloads() {
|
||||
return this.payload.getClaimsJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取载荷信息
|
||||
*
|
||||
@ -223,8 +252,8 @@ public class JWT {
|
||||
AlgorithmUtil.getId(signer.getAlgorithm()));
|
||||
}
|
||||
|
||||
final String headerBase64 = Base64.encodeUrlSafe(this.header.getClaimsJson(), charset);
|
||||
final String payloadBase64 = Base64.encodeUrlSafe(this.payload.getClaimsJson(), charset);
|
||||
final String headerBase64 = Base64.encodeUrlSafe(this.header.toString(), charset);
|
||||
final String payloadBase64 = Base64.encodeUrlSafe(this.payload.toString(), charset);
|
||||
final String sign = signer.sign(headerBase64, payloadBase64);
|
||||
|
||||
return StrUtil.format("{}.{}.{}", headerBase64, payloadBase64, sign);
|
||||
@ -249,7 +278,7 @@ public class JWT {
|
||||
Assert.notNull(signer, () -> new JWTException("No Signer provided!"));
|
||||
|
||||
final List<String> tokens = this.tokens;
|
||||
if(CollUtil.isEmpty(tokens)){
|
||||
if (CollUtil.isEmpty(tokens)) {
|
||||
throw new JWTException("No token to verify!");
|
||||
}
|
||||
return signer.verify(tokens.get(0), tokens.get(1), tokens.get(2));
|
||||
|
Loading…
x
Reference in New Issue
Block a user