use of org.eclipse.vorto.repository.oauth.IOAuthProvider in project vorto by eclipse.
the class OAuthProvider method from.
public static OAuthProvider from(IOAuthProvider source) {
OAuthProvider result = new OAuthProvider();
result.setId(source.getId());
result.setLabel(source.getLabel());
if (source.getWebflowConfiguration().isPresent()) {
IOAuthFlowConfiguration config = source.getWebflowConfiguration().get();
result.setLogoHref(config.getLogoHref());
result.setLoginUrl(config.getFilterProcessingUrl());
/*
Assigning the Bosch ID icon to the non-webflow providers, because there will only be the two
Suite OAuth versions in there for now (actually "merged" into one for presentational
purposes).
*/
} else {
if (source.getLabel().equals(BOSCH_SUITE_OAUTH_LABEL)) {
result.setLogoHref("webjars/repository-web/dist/images/bosch-social.png");
}
}
return result;
}
use of org.eclipse.vorto.repository.oauth.IOAuthProvider 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