richie
6 years ago
2 changed files with 0 additions and 48 deletions
@ -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…
Reference in new issue