Search in sources :

Example 36 with UserGroupPermission

use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionsWhenUserGroupRecordIsNotPresentForGivenName.

@Test
public void testGrantUserGroupPermissionsWhenUserGroupRecordIsNotPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
    userGroupPermissions.add(userGroupPermission);
    Role role = Mockito.mock(Role.class);
    Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
    userGroupPermissionService.grantUserGroupPermissions("safeBoxId", userGroupPermissions, "user", OffsetDateTime.MAX);
    Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
Also used : Role(com.nike.cerberus.domain.Role) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 37 with UserGroupPermission

use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionWhenUserGroupRecordIsNotPresentForGivenName.

@Test
public void testGrantUserGroupPermissionWhenUserGroupRecordIsNotPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Role role = Mockito.mock(Role.class);
    Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
    userGroupPermissionService.grantUserGroupPermission("safeBoxId", userGroupPermission, "user", OffsetDateTime.MAX);
    Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
Also used : Role(com.nike.cerberus.domain.Role) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 38 with UserGroupPermission

use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.

the class UserGroupPermissionService method getUserGroupPermissions.

public Set<UserGroupPermission> getUserGroupPermissions(final String safeDepositBoxId) {
    final Set<UserGroupPermission> permissionsSet = Sets.newHashSet();
    final List<UserGroupPermissionRecord> permissionRecords = userGroupDao.getUserGroupPermissions(safeDepositBoxId);
    permissionRecords.forEach(r -> {
        final Optional<UserGroupRecord> userGroupRecord = userGroupDao.getUserGroup(r.getUserGroupId());
        if (userGroupRecord.isPresent()) {
            UserGroupPermission permission = new UserGroupPermission();
            permission.setId(r.getId());
            permission.setRoleId(r.getRoleId());
            permission.setName(userGroupRecord.get().getName());
            permission.setCreatedBy(r.getCreatedBy());
            permission.setCreatedTs(r.getCreatedTs());
            permission.setLastUpdatedBy(r.getLastUpdatedBy());
            permission.setLastUpdatedTs(r.getLastUpdatedTs());
            permissionsSet.add(permission);
        }
    });
    return permissionsSet;
}
Also used : UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission)

Aggregations

UserGroupPermission (com.nike.cerberus.domain.UserGroupPermission)38 Test (org.junit.Test)34 HashSet (java.util.HashSet)17 SafeDepositBoxV2 (com.nike.cerberus.domain.SafeDepositBoxV2)15 UserGroupPermissionRecord (com.nike.cerberus.record.UserGroupPermissionRecord)8 UserGroupRecord (com.nike.cerberus.record.UserGroupRecord)8 IamPrincipalPermission (com.nike.cerberus.domain.IamPrincipalPermission)6 ApiError (com.nike.backstopper.apierror.ApiError)5 ApiException (com.nike.backstopper.exception.ApiException)5 Role (com.nike.cerberus.domain.Role)5 DefaultApiError (com.nike.cerberus.error.DefaultApiError)5 SafeDepositBoxV1 (com.nike.cerberus.domain.SafeDepositBoxV1)4 CerberusPrincipal (com.nike.cerberus.security.CerberusPrincipal)4 OffsetDateTime (java.time.OffsetDateTime)3 IamRolePermission (com.nike.cerberus.domain.IamRolePermission)2 SDBMetadata (com.nike.cerberus.domain.SDBMetadata)2 SafeDepositBoxRecord (com.nike.cerberus.record.SafeDepositBoxRecord)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1