io.jsonwebtoken.lang.Assert#notNull ( )源码实例Demo

下面列出了io.jsonwebtoken.lang.Assert#notNull ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jjwt   文件: EllipticCurveProvider.java
/**
 * Generates a new secure-random key pair of sufficient strength for the specified Elliptic Curve {@link
 * SignatureAlgorithm} (must be one of {@code ES256}, {@code ES384} or {@code ES512}) using the specified {@link
 * SecureRandom} random number generator via the specified JCA provider and algorithm name.
 *
 * @param jcaAlgorithmName the JCA name of the algorithm to use for key pair generation, for example, {@code
 *                         ECDSA}.
 * @param jcaProviderName  the JCA provider name of the algorithm implementation (for example {@code "BC"} for
 *                         BouncyCastle) or {@code null} if the default provider should be used.
 * @param alg              alg the algorithm indicating strength, must be one of {@code ES256}, {@code ES384} or
 *                         {@code ES512}
 * @param random           the SecureRandom generator to use during key generation.
 * @return a new secure-randomly generated key pair of sufficient strength for the specified Elliptic Curve {@link
 * SignatureAlgorithm} (must be one of {@code ES256}, {@code ES384} or {@code ES512}) using the specified {@link
 * SecureRandom} random number generator via the specified JCA provider and algorithm name.
 * @see #generateKeyPair()
 * @see #generateKeyPair(SignatureAlgorithm)
 * @see #generateKeyPair(SignatureAlgorithm, SecureRandom)
 */
public static KeyPair generateKeyPair(String jcaAlgorithmName, String jcaProviderName, SignatureAlgorithm alg,
                                      SecureRandom random) {
    Assert.notNull(alg, "SignatureAlgorithm argument cannot be null.");
    Assert.isTrue(alg.isEllipticCurve(), "SignatureAlgorithm argument must represent an Elliptic Curve algorithm.");
    try {
        KeyPairGenerator g;

        if (Strings.hasText(jcaProviderName)) {
            g = KeyPairGenerator.getInstance(jcaAlgorithmName, jcaProviderName);
        } else {
            g = KeyPairGenerator.getInstance(jcaAlgorithmName);
        }

        String paramSpecCurveName = EC_CURVE_NAMES.get(alg);
        ECGenParameterSpec spec = new ECGenParameterSpec(paramSpecCurveName);
        g.initialize(spec, random);
        return g.generateKeyPair();
    } catch (Exception e) {
        throw new IllegalStateException("Unable to generate Elliptic Curve KeyPair: " + e.getMessage(), e);
    }
}
 
源代码2 项目: jjwt   文件: OrgJsonDeserializer.java
@SuppressWarnings("unchecked")
@Override
public Object deserialize(byte[] bytes) throws DeserializationException {

    Assert.notNull(bytes, "JSON byte array cannot be null");

    if (bytes.length == 0) {
        throw new DeserializationException("Invalid JSON: zero length byte array.");
    }

    try {
        String s = new String(bytes, Strings.UTF_8);
        return parse(s);
    } catch (Exception e) {
        String msg = "Invalid JSON: " + e.getMessage();
        throw new DeserializationException(msg, e);
    }
}
 
源代码3 项目: tutorials   文件: SecretService.java
public void setSecrets(Map<String, String> secrets) {
    Assert.notNull(secrets);
    Assert.hasText(secrets.get(SignatureAlgorithm.HS256.getValue()));
    Assert.hasText(secrets.get(SignatureAlgorithm.HS384.getValue()));
    Assert.hasText(secrets.get(SignatureAlgorithm.HS512.getValue()));

    this.secrets = secrets;
}
 
源代码4 项目: jjwt   文件: DefaultJwtBuilder.java
@Override
public JwtBuilder signWith(Key key, SignatureAlgorithm alg) throws InvalidKeyException {
    Assert.notNull(key, "Key argument cannot be null.");
    Assert.notNull(alg, "SignatureAlgorithm cannot be null.");
    alg.assertValidSigningKey(key); //since 0.10.0 for https://github.com/jwtk/jjwt/issues/334
    this.algorithm = alg;
    this.key = key;
    return this;
}
 
源代码5 项目: jjwt   文件: AbstractCompressionCodec.java
/**
 * Asserts that payload is not null and calls {@link #doCompress(byte[]) doCompress}
 *
 * @param payload bytes to compress
 * @return compressed bytes
 * @throws CompressionException if {@link #doCompress(byte[]) doCompress} throws an IOException
 */
@Override
public final byte[] compress(byte[] payload) {
    Assert.notNull(payload, "payload cannot be null.");

    try {
        return doCompress(payload);
    } catch (IOException e) {
        throw new CompressionException("Unable to compress payload.", e);
    }
}
 
源代码6 项目: jjwt   文件: JacksonSerializer.java
@Override
public byte[] serialize(T t) throws SerializationException {
    Assert.notNull(t, "Object to serialize cannot be null.");
    try {
        return writeValueAsBytes(t);
    } catch (JsonProcessingException e) {
        String msg = "Unable to serialize object: " + e.getMessage();
        throw new SerializationException(msg, e);
    }
}
 
源代码7 项目: juiser   文件: JwsToUserDetailsConverter.java
public JwsToUserDetailsConverter(Function<String, Claims> claimsExtractor,
                                 Function<Claims, User> claimsUserFactory,
                                 Function<Claims, Collection<? extends GrantedAuthority>> authoritiesResolver) {
    Assert.notNull(claimsExtractor, "claimsExtractor cannot be null.");
    Assert.notNull(claimsUserFactory, "claimsUserFactory cannot be null.");
    this.claimsExtractor = claimsExtractor;
    this.claimsUserFactory = claimsUserFactory;
    this.authoritiesResolver = authoritiesResolver;
}
 
源代码8 项目: lams   文件: AbstractCompressionCodec.java
/**
 * Asserts that payload is not null and calls {@link #doCompress(byte[]) doCompress}
 *
 * @param payload bytes to compress
 * @return compressed bytes
 * @throws CompressionException if {@link #doCompress(byte[]) doCompress} throws an IOException
 */
@Override
public final byte[] compress(byte[] payload) {
    Assert.notNull(payload, "payload cannot be null.");

    try {
        return doCompress(payload);
    } catch (IOException e) {
        throw new CompressionException("Unable to compress payload.", e);
    }
}
 
源代码9 项目: lams   文件: DefaultJwtBuilder.java
@Override
public JwtBuilder signWith(SignatureAlgorithm alg, byte[] secretKey) {
    Assert.notNull(alg, "SignatureAlgorithm cannot be null.");
    Assert.notEmpty(secretKey, "secret key byte array cannot be null or empty.");
    Assert.isTrue(alg.isHmac(), "Key bytes may only be specified for HMAC signatures.  If using RSA or Elliptic Curve, use the signWith(SignatureAlgorithm, Key) method instead.");
    this.algorithm = alg;
    this.keyBytes = secretKey;
    return this;
}
 
源代码10 项目: jjwt   文件: DefaultJwtParser.java
@Override
public JwtParser setCompressionCodecResolver(CompressionCodecResolver compressionCodecResolver) {
    Assert.notNull(compressionCodecResolver, "compressionCodecResolver cannot be null.");
    this.compressionCodecResolver = compressionCodecResolver;
    return this;
}
 
源代码11 项目: jjwt   文件: GsonDeserializer.java
private GsonDeserializer(Gson gson, Class<T> returnType) {
    Assert.notNull(gson, "gson cannot be null.");
    Assert.notNull(returnType, "Return type cannot be null.");
    this.gson = gson;
    this.returnType = returnType;
}
 
源代码12 项目: juiser   文件: RequestHeaderUserFactory.java
public RequestHeaderUserFactory(String headerName, Function<String, User> headerValueToUserConverter) {
    Assert.hasText(headerName, "headerName argument cannot be null or empty.");
    Assert.notNull(headerValueToUserConverter, "headerValueToUserConverter function cannot be null.");
    this.headerName = headerName;
    this.headerValueToUser = headerValueToUserConverter;
}
 
源代码13 项目: jjwt   文件: DefaultJwtParserBuilder.java
@Override
public JwtParserBuilder setSigningKeyResolver(SigningKeyResolver signingKeyResolver) {
    Assert.notNull(signingKeyResolver, "SigningKeyResolver cannot be null.");
    this.signingKeyResolver = signingKeyResolver;
    return this;
}
 
源代码14 项目: jjwt   文件: DefaultJwtParserBuilder.java
@Override
public JwtParserBuilder setCompressionCodecResolver(CompressionCodecResolver compressionCodecResolver) {
    Assert.notNull(compressionCodecResolver, "compressionCodecResolver cannot be null.");
    this.compressionCodecResolver = compressionCodecResolver;
    return this;
}
 
源代码15 项目: jjwt   文件: ExceptionPropagatingDecoder.java
ExceptionPropagatingDecoder(Decoder<T, R> decoder) {
    Assert.notNull(decoder, "Decoder cannot be null.");
    this.decoder = decoder;
}
 
源代码16 项目: juiser   文件: ClaimValueResolver.java
public ClaimValueResolver(Function<Claims, ?> delegate, boolean resultRequired) {
    Assert.notNull(delegate, "delegate function cannot be null.");
    this.delegate = delegate;
    this.resultRequired = resultRequired;
}
 
源代码17 项目: lams   文件: DefaultJwtParser.java
@Override
public JwtParser setClock(Clock clock) {
    Assert.notNull(clock, "Clock instance cannot be null.");
    this.clock = clock;
    return this;
}
 
源代码18 项目: lams   文件: DefaultJwtParser.java
@Override
public JwtParser setSigningKeyResolver(SigningKeyResolver signingKeyResolver) {
    Assert.notNull(signingKeyResolver, "SigningKeyResolver cannot be null.");
    this.signingKeyResolver = signingKeyResolver;
    return this;
}
 
源代码19 项目: jjwt   文件: Base64Decoder.java
@Override
public byte[] decode(String s) throws DecodingException {
    Assert.notNull(s, "String argument cannot be null");
    return this.base64.decodeFast(s.toCharArray());
}
 
源代码20 项目: lams   文件: DefaultCompressionCodecResolver.java
private String getAlgorithmFromHeader(Header header) {
    Assert.notNull(header, "header cannot be null.");

    return header.getCompressionAlgorithm();
}