Search in sources :

Example 1 with DefaultGrantedAuthorityDto

use of eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto in project CzechIdMng by bcvsolutions.

the class JwtAuthenticationMapper method fromDto.

/**
 * Converts dto to authentication.
 *
 * @param dto
 * @return
 */
public IdmJwtAuthentication fromDto(IdmJwtAuthenticationDto dto) {
    Assert.notNull(dto);
    // 
    Collection<DefaultGrantedAuthorityDto> authorities = dto.getAuthorities();
    List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
    if (authorities != null) {
        for (DefaultGrantedAuthorityDto a : authorities) {
            grantedAuthorities.add(new DefaultGrantedAuthority(a.getAuthority()));
        }
    }
    IdmJwtAuthentication authentication = new IdmJwtAuthentication(new IdmIdentityDto(dto.getCurrentIdentityId(), dto.getCurrentUsername()), new IdmIdentityDto(dto.getOriginalIdentityId(), dto.getOriginalUsername()), dto.getExpiration(), dto.getIssuedAt(), grantedAuthorities, dto.getFromModule());
    return authentication;
}
Also used : DefaultGrantedAuthorityDto(eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 2 with DefaultGrantedAuthorityDto

use of eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto in project CzechIdMng by bcvsolutions.

the class AuthenticationTestUtils method getAuthDto.

public static IdmJwtAuthenticationDto getAuthDto(IdmIdentityDto user, Collection<GrantedAuthority> authorities) {
    IdmJwtAuthenticationDto d = new IdmJwtAuthenticationDto();
    d.setCurrentUsername(user.getUsername());
    d.setCurrentIdentityId(user.getId());
    d.setIssuedAt(getIat());
    d.setExpiration(getExp());
    d.setAuthorities(new ArrayList<>());
    d.setFromModule("test");
    d.setAuthorities(authorities.stream().map(a -> new DefaultGrantedAuthorityDto(a.toString())).collect(Collectors.toList()));
    return d;
}
Also used : DefaultGrantedAuthorityDto(eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto) IdmJwtAuthenticationDto(eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto)

Example 3 with DefaultGrantedAuthorityDto

use of eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto 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)

Aggregations

DefaultGrantedAuthorityDto (eu.bcvsolutions.idm.core.security.api.dto.DefaultGrantedAuthorityDto)3 DefaultGrantedAuthority (eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority)2 ArrayList (java.util.ArrayList)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmJwtAuthentication (eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication)1 IdmJwtAuthenticationDto (eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto)1 Collection (java.util.Collection)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1