Browse Source

提交到demo

master
richie 6 years ago
parent
commit
3624fec540
  1. 2
      plugin.xml
  2. 46
      src/main/java/com/fr/security/function/signature/SignatureGenerator.java

2
plugin.xml

@ -10,13 +10,11 @@
<vendor>richie</vendor>
<description><![CDATA[限制能够被远程调用的函数。]]></description>
<change-notes><![CDATA[
[2019-01-14]增加数字签名生成函数。<br/>
[2019-01-12]初始化插件。<br/>
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fr.security.function.RemoteEvalLocaleFinder"/>
<FunctionDefendProvider class="com.fr.security.function.RemoteEvalFunctionDefender"/>
<FunctionDefineProvider class="com.fr.security.function.signature.SignatureGenerator" name="SignatureGenerator" description="生成模板路径的数字签名"/>
</extra-core>
<function-recorder class="com.fr.security.function.RemoteEvalFunctionDefender"/>
<lifecycle-monitor class="com.fr.security.function.RemoteEvalInitializeMonitor"/>

46
src/main/java/com/fr/security/function/signature/SignatureGenerator.java

@ -1,46 +0,0 @@
package com.fr.security.function.signature;
import com.fr.cert.token.JwtBuilder;
import com.fr.cert.token.Jwts;
import com.fr.cert.token.SignatureAlgorithm;
import com.fr.general.GeneralUtils;
import com.fr.script.AbstractFunction;
import com.fr.security.function.conf.RemoteEvalConfig;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Primitive;
import java.util.Date;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-01-14
*/
public class SignatureGenerator extends AbstractFunction {
private static final long VALIDATE_TIME = 10 * 60 * 1000;
@Override
public Object run(Object[] args) {
if (ArrayUtils.isEmpty(args)) {
return Primitive.NULL;
}
return createJwt(GeneralUtils.objectToString(args[0]), RemoteEvalConfig.getInstance().getSignatureText());
}
private String createJwt(String subject, String key) {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
Date currentTime = new Date();
Date expirationTime = new Date(currentTime.getTime() + VALIDATE_TIME);
JwtBuilder builder = Jwts.builder()
.setSubject(subject)
.setIssuedAt(currentTime)
.setExpiration(expirationTime)
.signWith(signatureAlgorithm, key);
return builder.compact();
}
public static void main(String... args) {
SignatureGenerator generator = new SignatureGenerator();
System.out.println(generator.createJwt("/习题9.cpt", "GhzUsb4fmGwmSk57d3uBZ9jVFCRgZ9CVMT3WoomMHi4="));
}
}
Loading…
Cancel
Save