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;
}
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);
}
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));
}
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());
}
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());
}
Aggregations