Java Code Examples for org.springframework.vault.support.VaultToken#of()

The following examples show how to use org.springframework.vault.support.VaultToken#of() . 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: CubbyholeAuthentication.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
private static VaultToken getToken(CubbyholeAuthenticationOptions options, VaultResponse response, String url) {

		if (options.isWrappedToken()) {

			VaultResponse responseToUse = options.getUnwrappingEndpoints().unwrap(response);

			Assert.state(responseToUse.getAuth() != null, "Auth field must not be null");

			return LoginTokenUtil.from(responseToUse.getAuth());
		}

		Map<String, Object> data = response.getData();
		if (data == null || data.isEmpty()) {
			throw new VaultLoginException(
					String.format("Cannot retrieve Token from Cubbyhole: Response at %s does not contain a token",
							options.getPath()));
		}

		if (data.size() == 1) {
			String token = (String) data.get(data.keySet().iterator().next());
			return VaultToken.of(token);
		}

		throw new VaultLoginException(String
				.format("Cannot retrieve Token from Cubbyhole: Response at %s does not contain an unique token", url));
	}
 
Example 2
Source File: SpringVaultClientConfiguration.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public VaultToken login() throws VaultException {
	String token = tokenProvider.getToken();
	if (!StringUtils.hasLength(token)) {
		throw new IllegalArgumentException(
				"A Vault token must be supplied by a token provider");
	}
	return VaultToken.of(token);
}
 
Example 3
Source File: VaultSysTemplate.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
public VaultToken getRootToken() {
	return VaultToken.of(this.rootToken);
}
 
Example 4
Source File: Settings.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
/**
 * @return the token to use during tests.
 */
public static VaultToken token() {
	return VaultToken.of(System.getProperty("vault.token", "00000000-0000-0000-0000-000000000000").toCharArray());
}
 
Example 5
Source File: Settings.java    From spring-cloud-vault with Apache License 2.0 4 votes vote down vote up
/**
 * @return the token to use during tests.
 */
public static VaultToken token() {
	return VaultToken.of(System.getProperty("vault.token",
			"00000000-0000-0000-0000-000000000000"));
}
 
Example 6
Source File: TokenAuthentication.java    From spring-vault with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new {@link TokenAuthentication} with a static {@code token}.
 * @param token the Vault token, must not be empty or {@literal null}.
 */
public TokenAuthentication(String token) {

	Assert.hasText(token, "Token must not be empty");

	this.token = VaultToken.of(token);
}