Get User Role assignments from REST API

Hi, I would like to get User informations and User Roles from Rest API call.
I have a React front end that need logged in user informations and user roles because i have to modify views depends on user role (admin, administration, techinical…).
Actually i have 2 request:

  1. log-in with username and password and i get Token
  2. get user information from username with where clause and a custom Fetch Plan that include all data that i need but not roles (because i dont know how to get roles)

How can i get also user roles? i had create com.company.app.security.TechRole and associate to user

Thanks

Hi Marco,

I would suggest creating a custom REST endpoint and return the required information.
Role names can be obtained as shown on the example here.

Thanks for your answer… I put what I used to solve the question:

src/main/java/com/company/APPNAME/app/UserController.java

    
@RestController
@RequestMapping("/users")
public class UserController {

  @Autowired
  private DataManager dataManager;
  @Autowired
  private EntitySerialization entitySerialization;
  @Autowired
  private CurrentAuthentication currentAuthentication;

    @PostMapping("/details")
    public String loadAll() {

      UserDetails currentUser = currentAuthentication.getUser();
      User u = dataManager.load(User.class).query("select u from User u where u.username = ?1 ",currentUser.getUsername()).fetchPlan("user-full").one();

      Authentication authentication = currentAuthentication.getAuthentication();
      Locale locale = currentAuthentication.getLocale();
      TimeZone timeZone = currentAuthentication.getTimeZone();

        JSONObject jo = new JSONObject();
        jo.put("User", u);
        jo.put("Authentication", authentication);
        jo.put("Roles", getRoleNames(authentication).split(","));


        return entitySerialization.toJson(jo,
                null,
                EntitySerializationOption.DO_NOT_SERIALIZE_DENIED_PROPERTY);
    }

  private String getRoleNames(Authentication authentication) {

      GrantedAuthority grantedAuthority;

    return authentication.getAuthorities().stream()
            .map(GrantedAuthority::getAuthority)
            .collect(Collectors.joining(","));
  }

}