private static GrantedAuthority[] getUserAuthorities() {
    if (SecurityContextHolder.getContext() == null) {
      System.out.println("security context is empty, this seems to be a bug/misconfiguration!");
      return new GrantedAuthority[0];
    }
    Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
    if (currentUser == null || currentUser.getAuthorities() == null)
      return new GrantedAuthority[0];
    return currentUser.getAuthorities().toArray(new GrantedAuthority[]{});
  }