use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CertificateVersionDataService method findActiveWithTransitional.
public List<CredentialVersion> findActiveWithTransitional(String certificateName) {
ArrayList<CredentialVersion> result = new ArrayList<>();
Credential credential = credentialDataService.find(certificateName);
UUID uuid = credential.getUuid();
if (credential == null) {
return null;
} else {
CredentialVersionData active = credentialVersionRepository.findLatestNonTransitionalCertificateVersion(uuid);
if (active != null) {
result.add(credentialFactory.makeCredentialFromEntity(active));
}
CredentialVersionData transitional = credentialVersionRepository.findTransitionalCertificateVersion(uuid);
if (transitional != null) {
result.add(credentialFactory.makeCredentialFromEntity(transitional));
}
return result;
}
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionDataService method getAllowedOperations.
public List<PermissionOperation> getAllowedOperations(String name, String actor) {
List<PermissionOperation> operations = newArrayList();
Credential credential = credentialDataService.find(name);
PermissionData permissionData = permissionRepository.findByCredentialAndActor(credential, actor);
if (permissionData != null) {
if (permissionData.hasReadPermission()) {
operations.add(PermissionOperation.READ);
}
if (permissionData.hasWritePermission()) {
operations.add(PermissionOperation.WRITE);
}
if (permissionData.hasDeletePermission()) {
operations.add(PermissionOperation.DELETE);
}
if (permissionData.hasReadAclPermission()) {
operations.add(PermissionOperation.READ_ACL);
}
if (permissionData.hasWriteAclPermission()) {
operations.add(PermissionOperation.WRITE_ACL);
}
}
return operations;
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionDataService method hasPermission.
public boolean hasPermission(String user, String name, PermissionOperation requiredPermission) {
Credential credential = credentialDataService.find(name);
final PermissionData permissionData = permissionRepository.findByCredentialAndActor(credential, user);
return permissionData != null && permissionData.hasPermission(requiredPermission);
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method getAllByName_returnsCertificateWithMatchingNameIfCurrentUserHasAccess.
@Test
public void getAllByName_returnsCertificateWithMatchingNameIfCurrentUserHasAccess() throws Exception {
Credential myCredential = mock(Credential.class);
when(myCredential.getName()).thenReturn("my-credential");
Credential otherCredential = mock(Credential.class);
when(otherCredential.getName()).thenReturn("other-credential");
UserContext userContext = mock(UserContext.class);
when(userContextHolder.getUserContext()).thenReturn(userContext);
String user = "my-user";
when(userContext.getActor()).thenReturn(user);
when(permissionCheckingService.hasPermission(user, "my-credential", PermissionOperation.READ)).thenReturn(true);
when(permissionCheckingService.hasPermission(user, "other-credential", PermissionOperation.READ)).thenReturn(true);
when(certificateDataService.findByName("my-credential")).thenReturn(myCredential);
final List<Credential> certificates = subject.getByName("my-credential", newArrayList());
assertThat(certificates, equalTo(newArrayList(myCredential)));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method getAll_returnsAllCertificatesTheCurrentUserCanAccess.
@Test
public void getAll_returnsAllCertificatesTheCurrentUserCanAccess() throws Exception {
Credential myCredential = mock(Credential.class);
when(myCredential.getName()).thenReturn("my-credential");
Credential yourCredential = mock(Credential.class);
when(yourCredential.getName()).thenReturn("your-credential");
UserContext userContext = mock(UserContext.class);
when(userContextHolder.getUserContext()).thenReturn(userContext);
String user = "my-user";
when(userContext.getActor()).thenReturn(user);
when(permissionCheckingService.hasPermission(user, "my-credential", PermissionOperation.READ)).thenReturn(true);
when(permissionCheckingService.hasPermission(user, "your-credential", PermissionOperation.READ)).thenReturn(false);
when(certificateDataService.findAll()).thenReturn(newArrayList(myCredential, yourCredential));
final List<Credential> certificates = subject.getAll(newArrayList());
assertThat(certificates, equalTo(newArrayList(myCredential)));
}
Aggregations