Search in sources :

Example 6 with DefaultGrantedAuthority

use of eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority in project CzechIdMng by bcvsolutions.

the class JwtAuthenticationMapper method getDtoAuthorities.

/**
 * @param authentication
 * @return
 * @deprecated will be private
 */
@Deprecated
@SuppressWarnings("unchecked")
public List<DefaultGrantedAuthorityDto> getDtoAuthorities(Authentication authentication) {
    Collection<DefaultGrantedAuthority> authorities = (Collection<DefaultGrantedAuthority>) authentication.getAuthorities();
    List<DefaultGrantedAuthorityDto> grantedAuthorities = new ArrayList<>();
    if (authorities != null) {
        for (DefaultGrantedAuthority a : authorities) {
            grantedAuthorities.add(new DefaultGrantedAuthorityDto(a.getAuthority()));
        }
    }
    return grantedAuthorities;
}
Also used : DefaultGrantedAuthorityDto(eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority)

Example 7 with DefaultGrantedAuthority

use of eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority in project CzechIdMng by bcvsolutions.

the class IdmAuthorityUtils method toAuthorities.

/**
 * Returns all authorities from given groupPermissions
 *
 * @param groupPermissions
 * @return
 */
public static List<GrantedAuthority> toAuthorities(GroupPermission... groupPermissions) {
    Assert.notNull(groupPermissions);
    // 
    Set<GrantedAuthority> authorities = new HashSet<>();
    for (GroupPermission groupPermission : groupPermissions) {
        groupPermission.getPermissions().forEach(basePermission -> {
            authorities.add(new DefaultGrantedAuthority(groupPermission, basePermission));
        });
    }
    return new ArrayList<>(authorities);
}
Also used : DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) GroupPermission(eu.bcvsolutions.idm.core.security.api.domain.GroupPermission) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) HashSet(java.util.HashSet)

Example 8 with DefaultGrantedAuthority

use of eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority in project CzechIdMng by bcvsolutions.

the class IdentityRoleDeleteAuthoritiesProcessorTest method checkAssignedAuthorities.

private void checkAssignedAuthorities(IdmIdentityDto i) {
    GrantedAuthority g = new DefaultGrantedAuthority(CoreGroupPermission.IDENTITY, IdmBasePermission.DELETE);
    Collection<GrantedAuthority> authorities = authoritiesFactory.getGrantedAuthoritiesForIdentity(i.getId());
    Assert.assertEquals(1, authorities.size());
    authorities.stream().forEach(a -> Assert.assertEquals(g, a));
}
Also used : DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority)

Example 9 with DefaultGrantedAuthority

use of eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority in project CzechIdMng by bcvsolutions.

the class DefaultGrantedAuthoritiesFactoryTest method testSystemAdmin.

/**
 * System admin have all authorities
 */
@Test
public void testSystemAdmin() {
    IdmRole role = new IdmRole();
    role.setName("role");
    role.setId(UUID.randomUUID());
    IdmIdentityDto identity = new IdmIdentityDto();
    identity.setId(UUID.randomUUID());
    identity.setUsername("admin");
    IdmIdentityContractDto contract = new IdmIdentityContractDto();
    role.setId(UUID.randomUUID());
    contract.setIdentity(identity.getId());
    IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
    identityRole.setIdentityContract(contract.getId());
    identityRole.setRole(role.getId());
    List<IdmIdentityRoleDto> roles = Lists.newArrayList();
    when(moduleService.getAvailablePermissions()).thenReturn(groupPermissions);
    when(identityService.getByUsername(identity.getUsername())).thenReturn(identity);
    when(identityRoleService.findValidRole(identity.getId(), null)).thenReturn(new PageImpl<>(new ArrayList<>(roles)));
    when(roleService.getSubroles(any(UUID.class))).thenReturn(Lists.newArrayList());
    when(authorizationPolicyService.getDefaultAuthorities(any())).thenReturn(Sets.newHashSet(new DefaultGrantedAuthority(IdmGroupPermission.APP, IdmBasePermission.ADMIN), new DefaultGrantedAuthority(CoreGroupPermission.IDENTITY, IdmBasePermission.READ), new DefaultGrantedAuthority(CoreGroupPermission.IDENTITY, IdmBasePermission.ADMIN)));
    List<GrantedAuthority> grantedAuthorities = defaultGrantedAuthoritiesFactory.getGrantedAuthorities(identity.getUsername());
    assertEquals(1, grantedAuthorities.size());
    assertEquals(new DefaultGrantedAuthority(IdmGroupPermission.APP, IdmBasePermission.ADMIN), grantedAuthorities.iterator().next());
}
Also used : DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 10 with DefaultGrantedAuthority

use of eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority in project CzechIdMng by bcvsolutions.

the class IdmAuthorityHieararchyUnitTest method testSimpleRoleAsString.

@Test
public void testSimpleRoleAsString() {
    Mockito.when(moduleService.getAvailablePermissions()).thenReturn(Arrays.asList(CoreGroupPermission.values()));
    // 
    Collection<?> authorities = hierarchy.getReachableGrantedAuthorities(Lists.newArrayList(new DefaultGrantedAuthority("test")));
    Assert.assertEquals(1, authorities.size());
    Assert.assertEquals(new DefaultGrantedAuthority("test"), authorities.iterator().next());
}
Also used : DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

DefaultGrantedAuthority (eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority)10 GrantedAuthority (org.springframework.security.core.GrantedAuthority)7 ArrayList (java.util.ArrayList)5 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)4 Test (org.junit.Test)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 HashSet (java.util.HashSet)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)2 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2 DefaultGrantedAuthorityDto (eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto)2 UUID (java.util.UUID)2 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)1 GroupPermission (eu.bcvsolutions.idm.core.security.api.domain.GroupPermission)1 IdmGroupPermission (eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission)1 IdmJwtAuthentication (eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication)1 Collection (java.util.Collection)1 Transactional (org.springframework.transaction.annotation.Transactional)1