use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method set.
public CertificateCredentialVersion set(UUID certificateUuid, CertificateCredentialValue value, List<EventAuditRecordParameters> auditRecordParameters) {
Credential credential = findCertificateCredential(certificateUuid);
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_UPDATE, credential.getName());
auditRecordParameters.add(eventAuditRecordParameters);
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credential.getName(), PermissionOperation.WRITE)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
if (value.isTransitional()) {
validateNoTransitionalVersionsAlreadyExist(credential.getName(), auditRecordParameters);
}
CertificateCredentialVersion certificateCredentialVersion = certificateCredentialFactory.makeNewCredentialVersion(credential, value);
return credentialVersionDataService.save(certificateCredentialVersion);
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method getVersions.
public List<CredentialVersion> getVersions(UUID uuid, boolean current, List<EventAuditRecordParameters> auditRecordParameters) {
List<CredentialVersion> list;
String name;
try {
if (current) {
Credential credential = findCertificateCredential(uuid);
name = credential.getName();
list = certificateVersionDataService.findActiveWithTransitional(name);
} else {
list = certificateVersionDataService.findAllVersions(uuid);
name = !list.isEmpty() ? list.get(0).getName() : null;
}
} catch (IllegalArgumentException e) {
auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, null));
throw new InvalidQueryParameterException("error.bad_request", "uuid");
}
auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, name));
if (list.isEmpty() || !permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), name, PermissionOperation.READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return list;
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCredentialService method findByUuid.
public Credential findByUuid(UUID credentialUUID, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS);
auditRecordParameters.add(eventAuditRecordParameters);
Credential credential = credentialDataService.findByUUID(credentialUUID);
if (credential == null) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
eventAuditRecordParameters.setCredentialName(credential.getName());
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credential.getName(), READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return credential;
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class EncryptionKeyRotatorTest method rotation_canRotatePasswordCredentials.
@Test
public void rotation_canRotatePasswordCredentials() throws Exception {
String passwordName = name + "-password";
MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + " \"name\": \"" + passwordName + "\"," + " \"type\": \"password\"" + "}");
String content = this.mockMvc.perform(post).andDo(print()).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
String originalPassword = parse(content).get("value").textValue();
Credential credential = credentialDataService.find(passwordName);
final PasswordCredentialVersionData firstEncryption = (PasswordCredentialVersionData) credentialVersionRepository.findAllByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid()).get(0);
final byte[] firstEncryptedValue = firstEncryption.getEncryptedValueData().getEncryptedValue();
final byte[] firstEncryptedGenParams = firstEncryption.getEncryptedGenerationParameters().getEncryptedValue();
setActiveKey(1);
encryptionKeyRotator.rotate();
final PasswordCredentialVersionData secondEncryption = (PasswordCredentialVersionData) credentialVersionRepository.findAllByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid()).get(0);
assertThat(firstEncryptedValue, not(equalTo(secondEncryption.getEncryptedValueData().getEncryptedValue())));
assertThat(firstEncryptedGenParams, not(equalTo(secondEncryption.getEncryptedGenerationParameters())));
final MockHttpServletRequestBuilder get = get("/api/v1/data?name=" + passwordName).header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
this.mockMvc.perform(get).andExpect(status().isOk()).andExpect(jsonPath(".data[0].value").value(originalPassword));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionServiceTest method beforeEach.
@Before
public void beforeEach() {
userContext = mock(UserContext.class);
when(userContext.getActor()).thenReturn(USER_NAME);
expectedCredential = new Credential(CREDENTIAL_NAME);
expectedCredentialVersion = new PasswordCredentialVersion(CREDENTIAL_NAME);
permissionDataService = mock(PermissionDataService.class);
permissionCheckingService = mock(PermissionCheckingService.class);
when(permissionCheckingService.hasPermission(anyString(), anyString(), any(PermissionOperation.class))).thenReturn(true);
auditRecordParameters = newArrayList();
UserContextHolder userContextHolder = new UserContextHolder();
userContextHolder.setUserContext(userContext);
subject = new PermissionService(permissionDataService, permissionCheckingService, userContextHolder);
}
Aggregations