Java Code Examples for io.jsonwebtoken.lang.Assert#hasText()

The following examples show how to use io.jsonwebtoken.lang.Assert#hasText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultJwtBuilder.java    From jjwt with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: DefaultJwtBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: ForwardedUserFilter.java    From juiser with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: RequestHeaderUserFactory.java    From juiser with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: DefaultJwtParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: DefaultJwtParserBuilder.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: DefaultJwtBuilder.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: DefaultCompressionCodecResolver.java    From jjwt with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: DefaultJwtParser.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: AbstractCloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: AbstractCloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: ImmutablePhone.java    From juiser with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: SecretService.java    From tutorials with MIT License 5 votes vote down vote up
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;
}
 
Example 14
Source File: DefaultResource.java    From juiser with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 15
Source File: AbstractTextCodec.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 16
Source File: DefaultJwtParser.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public JwtParser setSigningKey(String base64EncodedSecretKey) {
    Assert.hasText(base64EncodedSecretKey, "signing key cannot be null or empty.");
    this.keyBytes = Decoders.BASE64.decode(base64EncodedSecretKey);
    return this;
}
 
Example 17
Source File: RequestHeaderUserFactory.java    From juiser with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 18
Source File: DefaultJwtParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JwtParser setSigningKey(String base64EncodedKeyBytes) {
    Assert.hasText(base64EncodedKeyBytes, "signing key cannot be null or empty.");
    this.keyBytes = TextCodec.BASE64.decode(base64EncodedKeyBytes);
    return this;
}
 
Example 19
Source File: AbstractTextCodec.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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);
}
 
Example 20
Source File: DefaultJwtParserBuilder.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public JwtParserBuilder setSigningKey(String base64EncodedSecretKey) {
    Assert.hasText(base64EncodedSecretKey, "signing key cannot be null or empty.");
    this.keyBytes = Decoders.BASE64.decode(base64EncodedSecretKey);
    return this;
}