class AcmGrantedAuthoritiesMapper {

    public Collection<AcmGrantedAuthority> mapAuthorities(Collection<? extends GrantedAuthority> grantedAuthorities)
    {
        Predicate<GrantedAuthority> authorityNotBlank = authority -> authority != null &&
                StringUtils.isNotBlank(authority.getAuthority());

        return grantedAuthorities.stream()
                .filter(authorityNotBlank)
                .map(authority -> authority.getAuthority().trim().toUpperCase())
                .peek(groupName -> log.debug(String.format("Incoming group: [%s]", groupName)))
                .filter(groupName -> roleToGroupMapping.getGroupToRolesMap().containsKey(groupName))
                .flatMap(groupName -> roleToGroupMapping.getGroupToRolesMap().get(groupName).stream())
                .map(AcmGrantedAuthority::new)
                .collect(Collectors.toSet());
    }

}