class UserCredentials extends BaseIdentifiableObject implements UserDetails {

    public Set<String> getAllAuthorities()
    {
        // cached all authorities can be reset to null by different thread and must be assigned before evaluation
        final Set<String> resultingAuthorities = cachedAllAuthorities;

        if ( resultingAuthorities != null )
        {
            return resultingAuthorities;
        }

        Set<String> authorities = new HashSet<>();

        for ( UserAuthorityGroup group : userAuthorityGroups )
        {
            authorities.addAll( group.getAuthorities() );
        }

        authorities = Collections.unmodifiableSet( authorities );
        cachedAllAuthorities = authorities;

        return authorities;
    }

    public  UserCredentials();

}