use of org.eclipse.vorto.repository.oauth.OAuthUser in project vorto by eclipse.
the class HomeController method getUser.
@ApiOperation(value = "Returns the currently logged in User")
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 200, message = "OK") })
@RequestMapping(value = { "/user", "/me" }, method = RequestMethod.GET)
public ResponseEntity<Map<String, Object>> getUser(Principal user, final HttpServletRequest request) throws ParseException {
Map<String, Object> map = new LinkedHashMap<>();
if (user == null)
return new ResponseEntity<>(map, HttpStatus.UNAUTHORIZED);
IOAuthProvider provider = registry.getByPrincipal(user);
OAuthUser oauthUser = provider.createUser((OAuth2Authentication) user);
User userAccount = accountService.getUser(oauthUser.getUserId());
Date updateCutoff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(updateDate);
map.put("name", oauthUser.getUserId());
if (Objects.nonNull(userAccount)) {
map.put("subject", userAccount.getSubject());
}
map.put("displayName", oauthUser.getDisplayName());
map.put("isRegistered", Boolean.toString(userAccount != null));
map.put("roles", oauthUser.getRoles());
map.put("needUpdate", Boolean.toString(needUpdate(userAccount, updateCutoff)));
map.put("logOutUrl", provider.getWebflowConfiguration().get().getLogoutUrl(request));
map.put("provider", new OAuthProvider(provider.getId(), provider.getLabel(), provider.getWebflowConfiguration().get()));
map.put("sysadmin", userAccount == null ? false : userRepositoryRoleService.isSysadmin(userAccount));
return new ResponseEntity<>(map, HttpStatus.OK);
}
Aggregations