當前位置: 首頁>>代碼示例>>Java>>正文


Java VaultResponse類代碼示例

本文整理匯總了Java中org.springframework.vault.support.VaultResponse的典型用法代碼示例。如果您正苦於以下問題:Java VaultResponse類的具體用法?Java VaultResponse怎麽用?Java VaultResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VaultResponse類屬於org.springframework.vault.support包,在下文中一共展示了VaultResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTokenUsingTlsCertAuthentication

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
private VaultToken createTokenUsingTlsCertAuthentication(String path) {

		try {
			VaultResponse response = restOperations.postForObject("auth/{mount}/login",
					Collections.emptyMap(), VaultResponse.class, path);

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

			logger.debug("Login successful using TLS certificates");

			return LoginTokenUtil.from(response.getAuth());
		}
		catch (HttpStatusCodeException e) {
			throw new VaultException(String.format(
					"Cannot login using TLS certificates: %s",
					VaultResponses.getError(e.getResponseBodyAsString())));
		}
	}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:19,代碼來源:ClientCertificateAuthentication.java

示例2: lookupSelf

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
private static Mono<Map<String, Object>> lookupSelf(WebClient webClient,
		VaultToken token) {

	return webClient
			.get()
			.uri("auth/token/lookup-self")
			.headers(httpHeaders -> httpHeaders.putAll(VaultHttpHeaders.from(token)))
			.retrieve()
			.bodyToMono(VaultResponse.class)
			.map(it -> {

				Assert.state(it.getData() != null, "Token response is null");
				return it.getRequiredData();
			})
			.onErrorMap(
					WebClientResponseException.class,
					e -> {
						return new VaultTokenLookupException(String.format(
								"Token self-lookup failed: %s %s", e.getStatusCode(),
								VaultResponses.getError(e.getResponseBodyAsString())));
					});
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:23,代碼來源:ReactiveLifecycleAwareSessionManager.java

示例3: createTokenUsingAppId

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
private VaultToken createTokenUsingAppId() {

		Map<String, String> login = getAppIdLogin(options.getAppId(), options
				.getUserIdMechanism().createUserId());

		try {
			VaultResponse response = restOperations.postForObject("auth/{mount}/login",
					login, VaultResponse.class, options.getPath());

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

			logger.debug("Login successful using AppId authentication");

			return LoginTokenUtil.from(response.getAuth());
		}
		catch (HttpStatusCodeException e) {
			throw new VaultException(String.format("Cannot login using app-id: %s",
					VaultResponses.getError(e.getResponseBodyAsString())));
		}
	}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:22,代碼來源:AppIdAuthentication.java

示例4: lookupToken

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Nullable
private Map<String, Object> lookupToken() {

	try {

		ResponseEntity<VaultResponse> entity = restOperations.exchange(
				options.getPath(), HttpMethod.GET,
				new HttpEntity<>(VaultHttpHeaders.from(options.getInitialToken())),
				VaultResponse.class);

		Assert.state(entity.getBody() != null, "Auth response must not be null");

		return entity.getBody().getData();
	}
	catch (HttpStatusCodeException e) {
		throw new VaultException(String.format(
				"Cannot retrieve Token from Cubbyhole: %s %s", e.getStatusCode(),
				VaultResponses.getError(e.getResponseBodyAsString())));
	}
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:21,代碼來源:CubbyholeAuthentication.java

示例5: createAuthenticationSteps

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
/**
 * Creates a {@link AuthenticationSteps} for token authentication given
 * {@link VaultToken}.
 *
 * @param token must not be {@literal null}.
 * @param selfLookup {@literal true} to perform a self-lookup using the given
 * {@link VaultToken}. Self-lookup will create a {@link LoginToken} and provide
 * renewability and TTL.
 * @return {@link AuthenticationSteps} for token authentication.
 * @since 2.0
 */
public static AuthenticationSteps createAuthenticationSteps(VaultToken token,
		boolean selfLookup) {

	Assert.notNull(token, "VaultToken must not be null");

	if (selfLookup) {

		HttpRequest<VaultResponse> httpRequest = get("auth/token/lookup-self").with(
				VaultHttpHeaders.from(token)).as(VaultResponse.class);

		return AuthenticationSteps.fromHttpRequest(httpRequest).login(
				response -> LoginTokenUtil.from(token.toCharArray(),
						response.getRequiredData()));
	}

	return AuthenticationSteps.just(token);
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:29,代碼來源:TokenAuthentication.java

示例6: lookupSelf

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
private static Map<String, Object> lookupSelf(RestOperations restOperations,
		VaultToken token) {

	try {
		ResponseEntity<VaultResponse> entity = restOperations.exchange(
				"auth/token/lookup-self", HttpMethod.GET, new HttpEntity<>(
						VaultHttpHeaders.from(token)), VaultResponse.class);

		Assert.state(entity.getBody() != null && entity.getBody().getData() != null,
				"Token response is null");

		return entity.getBody().getData();
	}
	catch (HttpStatusCodeException e) {
		throw new VaultTokenLookupException(String.format(
				"Token self-lookup failed: %s %s", e.getStatusCode(),
				VaultResponses.getError(e.getResponseBodyAsString())));
	}
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:20,代碼來源:LoginTokenAdapter.java

示例7: createTokenUsingAppRole

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
private VaultToken createTokenUsingAppRole() {

		Map<String, String> login = getAppRoleLoginBody(options.getRoleId(),
				options.getSecretId());

		try {
			VaultResponse response = restOperations.postForObject("auth/{mount}/login",
					login, VaultResponse.class, options.getPath());

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

			logger.debug("Login successful using AppRole authentication");

			return LoginTokenUtil.from(response.getAuth());
		}
		catch (HttpStatusCodeException e) {
			throw new VaultException(String.format("Cannot login using AppRole: %s",
					VaultResponses.getError(e.getResponseBodyAsString())));
		}
	}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:22,代碼來源:AppRoleAuthentication.java

示例8: createOrUpdatePolicy

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Override
public void createOrUpdatePolicy(String name, Policy policy) throws VaultException {

	Assert.hasText(name, "Name must not be null or empty");
	Assert.notNull(policy, "Policy must not be null");

	String rules;

	try {
		rules = OBJECT_MAPPER.writeValueAsString(policy);
	}
	catch (IOException e) {
		throw new VaultException("Cannot serialize policy to JSON", e);
	}

	vaultOperations.doWithSession(restOperations -> {

		restOperations.exchange("sys/policy/{name}", HttpMethod.PUT,
				new HttpEntity<>(Collections.singletonMap("rules", rules)),
				VaultResponse.class, name);

		return null;
	});
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:25,代碼來源:VaultSysTemplate.java

示例9: doGetProperties

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
/**
 * Hook method to obtain properties from Vault.
 *
 * @param path the path, must not be empty or {@literal null}.
 * @return the resulting {@link Map} or {@literal null} if properties were not found.
 * @throws VaultException on problems retrieving properties
 */
@Nullable
protected Map<String, Object> doGetProperties(String path) throws VaultException {

	VaultResponse vaultResponse = this.source.read(path);

	if (vaultResponse == null || vaultResponse.getData() == null) {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format("No properties found at %s", path));
		}

		return null;
	}

	return flattenMap(vaultResponse.getData());
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:23,代碼來源:VaultPropertySource.java

示例10: authenticationStepsShouldAuthenticatePushModeWithProvidedSecretId

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Test
public void authenticationStepsShouldAuthenticatePushModeWithProvidedSecretId() {

	String roleId = getRoleId("with-secret-id");
	String secretId = "hello_world_two";

	VaultResponse customSecretIdResponse = getVaultOperations().write(
			"auth/approle/role/with-secret-id/custom-secret-id",
			Collections.singletonMap("secret_id", secretId));

	AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
			.roleId(roleId).secretId(secretId).build();

	AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(
			AppRoleAuthentication.createAuthenticationSteps(options), prepare()
					.getRestTemplate());

	assertThat(executor.login()).isNotNull();

	getVaultOperations().write(
			"auth/approle/role/with-secret-id/secret-id-accessor/destroy",
			customSecretIdResponse.getData());
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:24,代碼來源:AppRoleAuthenticationStepsIntegrationTests.java

示例11: justLoginRequestShouldLogin

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Test
public void justLoginRequestShouldLogin() {

	mockRest.expect(requestTo("/auth/cert/login"))
			.andExpect(method(HttpMethod.POST))
			.andRespond(
					withSuccess()
							.contentType(MediaType.APPLICATION_JSON)
							.body("{"
									+ "\"auth\":{\"client_token\":\"my-token\", \"renewable\": true, \"lease_duration\": 10}"
									+ "}"));

	AuthenticationSteps steps = AuthenticationSteps.just(post("/auth/{path}/login",
			"cert").as(VaultResponse.class));

	assertThat(login(steps)).isEqualTo(VaultToken.of("my-token"));
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:18,代碼來源:AuthenticationStepsExecutorUnitTests.java

示例12: shouldAuthenticatePushModeWithProvidedSecretId

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Test
public void shouldAuthenticatePushModeWithProvidedSecretId() {

	String roleId = getRoleId("with-secret-id");
	String secretId = "hello_world";

	VaultResponse customSecretIdResponse = getVaultOperations().write(
			"auth/approle/role/with-secret-id/custom-secret-id",
			Collections.singletonMap("secret_id", secretId));

	AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
			.roleId(roleId).secretId(secretId).build();
	AppRoleAuthentication authentication = new AppRoleAuthentication(options,
			prepare().getRestTemplate());

	assertThat(authentication.login()).isNotNull();

	getVaultOperations().write(
			"auth/approle/role/with-secret-id/secret-id-accessor/destroy",
			customSecretIdResponse.getData());
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:22,代碼來源:AppRoleAuthenticationIntegrationTests.java

示例13: justLoginRequestShouldLogin

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Test
public void justLoginRequestShouldLogin() {

	ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST,
			"/auth/cert/login");
	MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
	response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
	response.setBody("{"
			+ "\"auth\":{\"client_token\":\"my-token\", \"renewable\": true, \"lease_duration\": 10}"
			+ "}");
	ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(
			Mono.just(response));

	WebClient webClient = WebClient.builder().clientConnector(connector).build();

	AuthenticationSteps steps = AuthenticationSteps.just(post("/auth/{path}/login",
			"cert").as(VaultResponse.class));

	StepVerifier.create(login(steps, webClient))
			.expectNext(VaultToken.of("my-token")).verifyComplete();
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:22,代碼來源:AuthenticationStepsOperatorUnitTests.java

示例14: justLoginShouldFail

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Test
public void justLoginShouldFail() {

	ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST,
			"/auth/cert/login");
	MockClientHttpResponse response = new MockClientHttpResponse(
			HttpStatus.BAD_REQUEST);
	ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(
			Mono.just(response));

	WebClient webClient = WebClient.builder().clientConnector(connector).build();

	AuthenticationSteps steps = AuthenticationSteps.just(post("/auth/{path}/login",
			"cert").as(VaultResponse.class));

	StepVerifier.create(login(steps, webClient)).expectError().verify();
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:18,代碼來源:AuthenticationStepsOperatorUnitTests.java

示例15: shouldSelfLookupToken

import org.springframework.vault.support.VaultResponse; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void shouldSelfLookupToken() {

	VaultResponse vaultResponse = new VaultResponse();
	vaultResponse.setData(Collections.singletonMap("ttl", 100));

	when(clientAuthentication.login()).thenReturn(VaultToken.of("login"));

	when(
			restOperations.exchange(anyString(), any(), any(),
					ArgumentMatchers.<Class> any())).thenReturn(
			new ResponseEntity<>(vaultResponse, HttpStatus.OK));

	LoginToken sessionToken = (LoginToken) sessionManager.getSessionToken();
	assertThat(sessionToken.getLeaseDuration()).isEqualTo(Duration.ofSeconds(100));

	verify(restOperations).exchange(eq("auth/token/lookup-self"), eq(HttpMethod.GET),
			eq(new HttpEntity<>(VaultHttpHeaders.from(LoginToken.of("login")))),
			any(Class.class));
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:22,代碼來源:LifecycleAwareSessionManagerUnitTests.java


注:本文中的org.springframework.vault.support.VaultResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。