Search in sources :

Example 1 with PermissionData

use of org.cloudfoundry.credhub.entity.PermissionData 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;
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PermissionOperation(org.cloudfoundry.credhub.request.PermissionOperation) PermissionData(org.cloudfoundry.credhub.entity.PermissionData)

Example 2 with PermissionData

use of org.cloudfoundry.credhub.entity.PermissionData 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);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PermissionData(org.cloudfoundry.credhub.entity.PermissionData)

Example 3 with PermissionData

use of org.cloudfoundry.credhub.entity.PermissionData in project credhub by cloudfoundry-incubator.

the class PermissionDataService method upsertPermissions.

private void upsertPermissions(Credential credential, List<PermissionData> accessEntries, String actor, List<PermissionOperation> operations) {
    PermissionData entry = findAccessEntryForActor(accessEntries, actor);
    if (entry == null) {
        entry = new PermissionData(credential, actor);
    }
    entry.enableOperations(operations);
    permissionRepository.saveAndFlush(entry);
}
Also used : PermissionData(org.cloudfoundry.credhub.entity.PermissionData)

Aggregations

PermissionData (org.cloudfoundry.credhub.entity.PermissionData)3 Credential (org.cloudfoundry.credhub.entity.Credential)2 PermissionOperation (org.cloudfoundry.credhub.request.PermissionOperation)1