use of alien4cloud.rest.model.UserStatus in project alien4cloud by alien4cloud.
the class AuthController method getLoginStatus.
/**
* Get the current user's status (login, roles etc.).
*
* @return The current user's status wrapped in a {@link RestResponse} object.
*/
@ApiOperation(value = "Get the current authentication status and user's roles.", notes = "Return the current user's status and it's roles.")
@RequestMapping(value = "/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<UserStatus> getLoginStatus() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final UserStatus userStatus = new UserStatus();
if (auth == null) {
userStatus.setIsLogged(false);
} else {
userStatus.setIsLogged(auth.isAuthenticated() && !(auth instanceof AnonymousAuthenticationToken));
userStatus.setUsername(auth.getName());
if (auth.getPrincipal() instanceof User) {
userStatus.setGithubUsername(((User) auth.getPrincipal()).getFirstName());
userStatus.setGroups(((User) auth.getPrincipal()).getGroups());
}
for (GrantedAuthority role : auth.getAuthorities()) {
userStatus.getRoles().add(role.getAuthority());
}
}
if (env.acceptsProfiles("github-auth")) {
userStatus.setAuthSystem("github");
} else if (samlEnabled) {
userStatus.setAuthSystem("saml");
} else {
userStatus.setAuthSystem("alien");
}
return RestResponseBuilder.<UserStatus>builder().data(userStatus).build();
}
Aggregations