下面列出了io.jsonwebtoken.lang.Assert#hasText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public JwtBuilder claim(String name, Object value) {
Assert.hasText(name, "Claim property name cannot be null or empty.");
if (this.claims == null) {
if (value != null) {
ensureClaims().put(name, value);
}
} else {
if (value == null) {
this.claims.remove(name);
} else {
this.claims.put(name, value);
}
}
return this;
}
public ForwardedUserFilter(String headerName,
Function<HttpServletRequest, User> userFactory,
Collection<String> requestAttributeNames) {
Assert.hasText(headerName, "headerName cannot be null or empty.");
Assert.notNull(userFactory, "userFactory function cannot be null.");
this.headerName = headerName;
this.userFactory = userFactory;
//always ensure that the fully qualified interface name is accessible:
LinkedHashSet<String> set = new LinkedHashSet<>();
set.add(User.class.getName());
if (!Collections.isEmpty(requestAttributeNames)) {
set.addAll(requestAttributeNames);
}
this.requestAttributeNames = set;
}
@Override
public User apply(HttpServletRequest request) {
String value = request.getHeader(headerName);
Assert.hasText(value, "header value cannot be null or empty.");
User user;
try {
user = headerValueToUser.apply(value);
} catch (Exception e) {
String msg = "Unable to determine request User based on " + headerName + " header value [" + value +
"] when invoking headerValue-to-User conversion function: " + e.getMessage();
throw new IllegalStateException(msg, e);
}
Assert.state(user != null, "User instance returned from headerValue-to-User conversion " +
"function cannot be null.");
return user;
}
@Override
public JwtBuilder claim(String name, Object value) {
Assert.hasText(name, "Claim property name cannot be null or empty.");
if (this.claims == null) {
if (value != null) {
ensureClaims().put(name, value);
}
} else {
if (value == null) {
this.claims.remove(name);
} else {
this.claims.put(name, value);
}
}
return this;
}
@Override
public JwtParser require(String claimName, Object value) {
Assert.hasText(claimName, "claim name cannot be null or empty.");
Assert.notNull(value, "The value cannot be null for claim name: " + claimName);
expectedClaims.put(claimName, value);
return this;
}
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;
}
public ImmutablePhone(String number, String name, String description, boolean verified) {
Assert.hasText(number, "number argument cannot be null or empty.");
this.number = number;
this.digitString = digitsOnly(number);
this.name = name;
this.description = description;
this.verified = verified;
}
private Mono<String> organizationId() {
String org = this.runtimeEnvironmentInfo.getPlatformSpecificInfo().get(CloudFoundryPlatformSpecificInfo.ORG);
Assert.hasText(org,"Missing runtimeEnvironmentInfo : 'org' required.");
ListOrganizationsRequest listOrganizationsRequest = ListOrganizationsRequest.builder()
.name(org).build();
return this.client.organizations().list(listOrganizationsRequest)
.doOnError(logError("Failed to list organizations"))
.map(listOrganizationsResponse -> listOrganizationsResponse.getResources().get(0).getMetadata().getId())
.cache(aValue -> Duration.ofMillis(Long.MAX_VALUE), aValue -> Duration.ZERO, () -> Duration.ZERO);
}
private Mono<String> spaceId() {
String space = this.runtimeEnvironmentInfo.getPlatformSpecificInfo().get(CloudFoundryPlatformSpecificInfo.SPACE);
Assert.hasText(space,"Missing runtimeEnvironmentInfo : 'space' required.");
ListSpacesRequest listSpacesRequest = ListSpacesRequest.builder()
.name(space).build();
return this.client.spaces().list(listSpacesRequest)
.doOnError(logError("Failed to list spaces"))
.map(listSpacesResponse -> listSpacesResponse.getResources().get(0).getMetadata().getId())
.cache(aValue -> Duration.ofMillis(Long.MAX_VALUE), aValue -> Duration.ZERO, () -> Duration.ZERO);
}
@Override
public JwtParser require(String claimName, Object value) {
Assert.hasText(claimName, "claim name cannot be null or empty.");
Assert.notNull(value, "The value cannot be null for claim name: " + claimName);
expectedClaims.put(claimName, value);
return this;
}
private CompressionCodec byName(String name) {
Assert.hasText(name, "'name' must not be empty");
CompressionCodec codec = codecs.get(name.toUpperCase());
if (codec == null) {
throw new CompressionException(String.format(MISSING_COMPRESSION_MESSAGE, name));
}
return codec;
}
@Override
public JwtBuilder signWith(SignatureAlgorithm alg, String base64EncodedSecretKey) throws InvalidKeyException {
Assert.hasText(base64EncodedSecretKey, "base64-encoded secret key cannot be null or empty.");
Assert.isTrue(alg.isHmac(), "Base64-encoded key bytes may only be specified for HMAC signatures. If using RSA or Elliptic Curve, use the signWith(SignatureAlgorithm, Key) method instead.");
byte[] bytes = Decoders.BASE64.decode(base64EncodedSecretKey);
return signWith(alg, bytes);
}
@Override
public JwtParserBuilder require(String claimName, Object value) {
Assert.hasText(claimName, "claim name cannot be null or empty.");
Assert.notNull(value, "The value cannot be null for claim name: " + claimName);
expectedClaims.put(claimName, value);
return this;
}
@Override
public String encode(String data) {
Assert.hasText(data, "String argument to encode cannot be null or empty.");
byte[] bytes = data.getBytes(UTF8);
return encode(bytes);
}
@Override
public JwtParser setSigningKey(String base64EncodedKeyBytes) {
Assert.hasText(base64EncodedKeyBytes, "signing key cannot be null or empty.");
this.keyBytes = TextCodec.BASE64.decode(base64EncodedKeyBytes);
return this;
}
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;
}
public DefaultResource(InputStream is, String name) {
Assert.notNull(is, "InputStream cannot be null.");
Assert.hasText(name, "String name argument cannot be null or empty.");
this.is = is;
this.name = name;
}
@Override
public String encode(String data) {
Assert.hasText(data, "String argument to encode cannot be null or empty.");
byte[] bytes = data.getBytes(UTF8);
return encode(bytes);
}
@Override
public JwtParser setSigningKey(String base64EncodedSecretKey) {
Assert.hasText(base64EncodedSecretKey, "signing key cannot be null or empty.");
this.keyBytes = Decoders.BASE64.decode(base64EncodedSecretKey);
return this;
}
@Override
public JwtParserBuilder setSigningKey(String base64EncodedSecretKey) {
Assert.hasText(base64EncodedSecretKey, "signing key cannot be null or empty.");
this.keyBytes = Decoders.BASE64.decode(base64EncodedSecretKey);
return this;
}