org.springframework.credhub.support.SimpleCredentialName Java Examples
The following examples show how to use
org.springframework.credhub.support.SimpleCredentialName.
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: CredhubIntegrationTest.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Before public void setUp() { CredHubCredentialOperations credhubCredentialOperations = Mockito .mock(CredHubCredentialOperations.class); String expectedPath = "/myapp/master/default"; SimpleCredentialName togglesCredentialName = new SimpleCredentialName( expectedPath + "/toggles"); when(credhubCredentialOperations.findByPath(expectedPath)) .thenReturn(singletonList(new CredentialSummary(togglesCredentialName))); JsonCredential credentials = new JsonCredential(); credentials.put("key", "value"); when(credhubCredentialOperations.getByName( new SimpleCredentialName(expectedPath + "/toggles"), JsonCredential.class)) .thenReturn(new CredentialDetails<>("id1", togglesCredentialName, CredentialType.JSON, credentials)); when(this.credHubOperations.credentials()) .thenReturn(credhubCredentialOperations); }
Example #2
Source File: PasswordParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 6 votes |
@Test public void serializeWithParameters() { this.requestBuilder = PasswordParametersRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true).mode(WriteMode.OVERWRITE) .parameters(PasswordParameters.builder().length(20).excludeLower(true).excludeUpper(false) .excludeNumber(true).includeSpecial(false).build()); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "password"); JsonPathAssert.assertThat(json).hasPath("$.parameters.length").isEqualTo(20); JsonPathAssert.assertThat(json).hasPath("$.parameters.exclude_lower").isEqualTo(true); JsonPathAssert.assertThat(json).hasPath("$.parameters.exclude_upper").isEqualTo(false); JsonPathAssert.assertThat(json).hasPath("$.parameters.exclude_number").isEqualTo(true); JsonPathAssert.assertThat(json).hasPath("$.parameters.include_special").isEqualTo(false); }
Example #3
Source File: CredHubCredentialsGeneratorTest.java From spring-cloud-app-broker with Apache License 2.0 | 6 votes |
@Test void generateUser() { given(this.credHubOperations.credentials()) .willReturn(credHubCredentialOperations); CredentialDetails<UserCredential> creds = new CredentialDetails<>("id", new SimpleCredentialName("app-service"), CredentialType.PASSWORD, new UserCredential("username", "password")); given(this.credHubCredentialOperations.generate(any(), eq(UserCredential.class))) .willReturn(Mono.just(creds)); StepVerifier.create(generator.generateUser("foo", "bar", "hello", 12, false, false, false, false)) .assertNext(tuple2 -> { assertThat(tuple2.getT1()).isEqualTo("username"); assertThat(tuple2.getT2()).isEqualTo("password"); }) .verifyComplete(); }
Example #4
Source File: CredHubCredentialsGeneratorTest.java From spring-cloud-app-broker with Apache License 2.0 | 6 votes |
@Test void generateString() { given(this.credHubOperations.credentials()) .willReturn(credHubCredentialOperations); CredentialDetails<PasswordCredential> creds = new CredentialDetails<>("id", new SimpleCredentialName("app-service"), CredentialType.PASSWORD, new PasswordCredential("password")); given(this.credHubCredentialOperations.generate(any(), eq(PasswordCredential.class))) .willReturn(Mono.just(creds)); StepVerifier.create(generator.generateString("foo", "bar", "hello", 12, false, false, false, false)) .assertNext(password -> assertThat(password).isEqualTo("password")) .verifyComplete(); }
Example #5
Source File: CredHubCertificateTemplateUnitTests.java From spring-credhub with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void bulkRegenerate() { Map<String, List<CredentialName>> expectedResponse = Collections.singletonMap( CredHubCertificateTemplate.REGENERATED_CREDENTIALS_RESPONSE_FIELD, Arrays.asList(new SimpleCredentialName("example-certificate1"), new SimpleCredentialName("example-certificate2"))); Map<String, Object> request = new HashMap<String, Object>() { { put(CredHubCertificateTemplate.SIGNED_BY_REQUEST_FIELD, NAME.getName()); } }; given(this.restTemplate.exchange(eq(CredHubCertificateTemplate.BULK_REGENERATE_URL_PATH), eq(HttpMethod.POST), eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))) .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); List<CredentialName> response = this.credHubTemplate.regenerate(NAME); assertThat(response).isNotNull(); assertThat(response) .isEqualTo(expectedResponse.get(CredHubCertificateTemplate.REGENERATED_CREDENTIALS_RESPONSE_FIELD)); }
Example #6
Source File: CertificateParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 6 votes |
@Test public void serializeWithMinimalParameters() { this.requestBuilder = CertificateParametersRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true).mode(WriteMode.NO_OVERWRITE) .parameters(CertificateParameters.builder().commonName("common") .certificateAuthorityCredential("credential").build()); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.NO_OVERWRITE, "/example/credential", "certificate"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.key_length"); JsonPathAssert.assertThat(json).hasPath("$.parameters.common_name").isEqualTo("common"); JsonPathAssert.assertThat(json).hasPath("$.parameters.ca").isEqualTo("credential"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.alternative_names"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.organization"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.organization_unit"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.locality"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.state"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.country"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.duration"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.is_ca"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.self_sign"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.key_usage"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.extended_key_usage"); }
Example #7
Source File: UserParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 6 votes |
@Test public void serializeWithParameters() { this.requestBuilder = UserParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.OVERWRITE).username("user") .parameters(PasswordParameters.builder().length(20).excludeLower(true).excludeUpper(false) .excludeNumber(true).includeSpecial(false).build()); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "user"); JsonPathAssert.assertThat(json).hasPath("$.value.username").isEqualTo("user"); JsonPathAssert.assertThat(json).hasPath("$.parameters.length").isEqualTo(20); JsonPathAssert.assertThat(json).hasPath("$.parameters.exclude_lower").isEqualTo(true); JsonPathAssert.assertThat(json).hasPath("$.parameters.exclude_upper").isEqualTo(false); JsonPathAssert.assertThat(json).hasPath("$.parameters.exclude_number").isEqualTo(true); JsonPathAssert.assertThat(json).hasPath("$.parameters.include_special").isEqualTo(false); }
Example #8
Source File: CredHubDemoController.java From spring-credhub with Apache License 2.0 | 6 votes |
private CredentialDetails<JsonCredential> writeCredentials(SimpleCredentialName name, Map<String, Object> value, Results results) { try { JsonCredentialRequest request = JsonCredentialRequest.builder() .name(name) .value(value) .build(); CredentialDetails<JsonCredential> credentialDetails = credentialOperations.write(request); saveResults(results, "Successfully wrote credentials: ", credentialDetails); return credentialDetails; } catch (Exception e) { saveResults(results, "Error writing credentials: ", e.getMessage()); return null; } }
Example #9
Source File: PasswordCredentialRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithStringValue() { this.requestBuilder = PasswordCredentialRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true).mode(WriteMode.OVERWRITE) .value("secret"); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "password"); JsonPathAssert.assertThat(json).hasPath("$.value").isEqualTo("secret"); assertNoPermissions(json); }
Example #10
Source File: ValueCredentialRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("deprecation") public void serializeWithStringValue() { this.requestBuilder = ValueCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).value("somevalue"); DocumentContext json = toJsonPath(this.requestBuilder); JsonPathAssert.assertThat(json).hasPath("$.overwrite").isEqualTo(true); JsonPathAssert.assertThat(json).hasPath("$.name").isEqualTo("/example/credential"); JsonPathAssert.assertThat(json).hasPath("$.type").isEqualTo("value"); JsonPathAssert.assertThat(json).hasPath("$.value").isEqualTo("somevalue"); assertNoPermissions(json); }
Example #11
Source File: PasswordParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithEmptyParameters() { this.requestBuilder = PasswordParametersRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true).mode(WriteMode.CONVERGE) .parameters(new PasswordParameters()); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.CONVERGE, "/example/credential", "password"); assertParametersNotSet(json); }
Example #12
Source File: PasswordParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithNoParameters() { this.requestBuilder = PasswordParametersRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true).mode(WriteMode.NO_OVERWRITE); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.NO_OVERWRITE, "/example/credential", "password"); assertParametersNotSet(json); }
Example #13
Source File: RsaParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithParameters() { this.requestBuilder = RsaParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.OVERWRITE).parameters(new RsaParameters(KeyLength.LENGTH_4096)); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "rsa"); JsonPathAssert.assertThat(json).hasPath("$.parameters.key_length").isEqualTo(4096); }
Example #14
Source File: RsaParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithNoParameters() { this.requestBuilder = RsaParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.OVERWRITE); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "rsa"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.key_length"); }
Example #15
Source File: UserParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithEmptyParameters() { this.requestBuilder = UserParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.NO_OVERWRITE).parameters(new PasswordParameters()); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.NO_OVERWRITE, "/example/credential", "user"); assertParametersNotSet(json); }
Example #16
Source File: UserParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithNoParameters() { this.requestBuilder = UserParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.CONVERGE); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.CONVERGE, "/example/credential", "user"); assertParametersNotSet(json); }
Example #17
Source File: UserCredentialRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithPassword() { UserCredentialRequestBuilder builder = UserCredentialRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true).mode(WriteMode.OVERWRITE) .value(new UserCredential("secret")); DocumentContext json = toJsonPath(builder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "user"); JsonPathAssert.assertThat(json).hasNoPath("$.value.username"); JsonPathAssert.assertThat(json).hasPath("$.value.password").isEqualTo("secret"); JsonPathAssert.assertThat(json).hasNoPath("$.value.password_hash"); assertNoPermissions(json); }
Example #18
Source File: SshParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithParameters() { this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.OVERWRITE) .parameters(new SshParameters(KeyLength.LENGTH_2048, "ssh comment")); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "ssh"); JsonPathAssert.assertThat(json).hasPath("$.parameters.key_length").isEqualTo(2048); JsonPathAssert.assertThat(json).hasPath("$.parameters.ssh_comment").isEqualTo("ssh comment"); }
Example #19
Source File: SshParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithLengthParameter() { this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.NO_OVERWRITE).parameters(new SshParameters(KeyLength.LENGTH_2048)); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.NO_OVERWRITE, "/example/credential", "ssh"); JsonPathAssert.assertThat(json).hasPath("$.parameters.key_length").isEqualTo(2048); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.ssh_comment"); }
Example #20
Source File: SshParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithCommentParameter() { this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.CONVERGE).parameters(new SshParameters("ssh comment")); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.CONVERGE, "/example/credential", "ssh"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.key_length"); JsonPathAssert.assertThat(json).hasPath("$.parameters.ssh_comment").isEqualTo("ssh comment"); }
Example #21
Source File: SshParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithNoParameters() { this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) .overwrite(true).mode(WriteMode.OVERWRITE); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.OVERWRITE, "/example/credential", "ssh"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.key_length"); JsonPathAssert.assertThat(json).hasNoPath("$.parameters.ssh_comment"); }
Example #22
Source File: CredhubEnvironmentRepository.java From spring-cloud-config with Apache License 2.0 | 5 votes |
private Map<Object, Object> findProperties(String application, String profile, String label) { String path = "/" + application + "/" + profile + "/" + label; return this.credHubOperations.credentials().findByPath(path).stream() .map(credentialSummary -> credentialSummary.getName().getName()) .map(name -> this.credHubOperations.credentials() .getByName(new SimpleCredentialName(name), JsonCredential.class)) .map(CredentialDetails::getValue) .flatMap(jsonCredential -> jsonCredential.entrySet().stream()) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b)); }
Example #23
Source File: CredhubEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
private void stubCredentials(String expectedPath, String name, String key, String value) { SimpleCredentialName credentialsName = new SimpleCredentialName( expectedPath + "/" + name); when(this.credhubCredentialOperations.findByPath(expectedPath)) .thenReturn(singletonList(new CredentialSummary(credentialsName))); JsonCredential credentials = new JsonCredential(); credentials.put(key, value); when(this.credhubCredentialOperations.getByName( new SimpleCredentialName(expectedPath + "/" + name), JsonCredential.class)) .thenReturn(new CredentialDetails<>("id1", credentialsName, CredentialType.JSON, credentials)); }
Example #24
Source File: CredHubCredentialsGenerator.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@Override public Mono<String> generateString(String applicationId, String serviceInstanceId, String descriptor, int length, boolean includeUppercaseAlpha, boolean includeLowercaseAlpha, boolean includeNumeric, boolean includeSpecial) { return credHubOperations.credentials() .generate(PasswordParametersRequest.builder() .name(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor)) .parameters(passwordParameters(length, includeUppercaseAlpha, includeLowercaseAlpha, includeNumeric, includeSpecial)) .build(), PasswordCredential.class) .map(CredentialDetails::getValue) .map(PasswordCredential::getPassword); }
Example #25
Source File: JsonCredentialRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Before public void setUp() { this.requestBuilder = JsonCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) .value(new JsonCredential() { { put("data", "value"); put("test", true); } }).mode(WriteMode.OVERWRITE); }
Example #26
Source File: CertificateParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void serializeWithEmptyParameters() { this.requestBuilder = CertificateParametersRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true) .parameters(CertificateParameters.builder().keyLength(KeyLength.LENGTH_2048).build()); toJsonPath(this.requestBuilder); }
Example #27
Source File: CertificateParametersRequestUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializeWithNoParameters() { this.requestBuilder = CertificateParametersRequest.builder() .name(new SimpleCredentialName("example", "credential")).overwrite(true).mode(WriteMode.CONVERGE); DocumentContext json = toJsonPath(this.requestBuilder); assertCommonRequestFields(json, true, WriteMode.CONVERGE, "/example/credential", "certificate"); assertParametersNotSet(json); }
Example #28
Source File: CredHubCredentialsGeneratorTest.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@Test void deleteUser() { given(this.credHubOperations.credentials()) .willReturn(credHubCredentialOperations); given(this.credHubCredentialOperations.deleteByName(any())) .willReturn(Mono.empty()); StepVerifier.create(generator.deleteUser("foo", "bar", "hello")) .verifyComplete(); verify(credHubCredentialOperations).deleteByName(new SimpleCredentialName("foo", "bar", "hello")); verifyNoMoreInteractions(credHubOperations); verifyNoMoreInteractions(credHubCredentialOperations); }
Example #29
Source File: CredentialPermissionsUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serialize() { CredentialPermissions permissions = new CredentialPermissions( new SimpleCredentialName("example", "credentialName"), Permission.builder().app("appid1").operations(Operation.READ, Operation.WRITE).build()); DocumentContext json = JsonTestUtils.toJsonPath(permissions); JsonPathAssert.assertThat(json).hasPath("$.credential_name").isEqualTo("/example/credentialName"); JsonPathAssert.assertThat(json).hasPath("$.permissions[0].actor").isEqualTo(Actor.app("appid1").getIdentity()); JsonPathAssert.assertThat(json).hasPath("$.permissions[0].operations[0]").isEqualTo("read"); JsonPathAssert.assertThat(json).hasPath("$.permissions[0].operations[1]").isEqualTo("write"); }
Example #30
Source File: CredentialPermissionUnitTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void serializePermission() { CredentialPermission permission = new CredentialPermission( new SimpleCredentialName("example", "credential", "*"), Permission.builder().app("appid1").operations(Operation.READ, Operation.WRITE).build()); DocumentContext json = JsonTestUtils.toJsonPath(permission); JsonPathAssert.assertThat(json).hasPath("$.path").isEqualTo("/example/credential/*"); JsonPathAssert.assertThat(json).hasPath("$.actor").isEqualTo(Actor.app("appid1").getIdentity()); JsonPathAssert.assertThat(json).hasPath("$.operations[0]").isEqualTo("read"); JsonPathAssert.assertThat(json).hasPath("$.operations[1]").isEqualTo("write"); }