private static Set<String> parseAuthorities(String grantedRoles) {
    Set<String> parsedAuthorities = new TreeSet<>();
    if (grantedRoles == null || "".equals(grantedRoles.trim())) {
      return parsedAuthorities;
    }

    String[] parsedAuthoritiesArr;
    if (grantedRoles.contains(",")) {
      parsedAuthoritiesArr = grantedRoles.split(",");
    } else {
      parsedAuthoritiesArr = new String[]{grantedRoles};
    }

    // adding authorities to set (could pssible be done better!)
    for (String auth : parsedAuthoritiesArr)
      parsedAuthorities.add(auth.trim());
    return parsedAuthorities;
  }