use of com.hortonworks.streamline.streams.security.AuthenticationContext in project streamline by hortonworks.
the class SecurityCatalogResource method getCurrentUser.
private User getCurrentUser(SecurityContext securityContext) {
Principal principal = securityContext.getUserPrincipal();
if (principal == null) {
throw EntityNotFoundException.byMessage("No principal in security context");
}
String userName = SecurityUtil.getUserName(principal.getName());
if (userName == null || userName.isEmpty()) {
throw EntityNotFoundException.byMessage("Empty user name for principal " + principal);
}
User user = catalogService.getUser(userName);
if (user == null) {
throw EntityNotFoundException.byMessage("User '" + userName + "' is not in the user database.");
}
AuthenticationContext context = new AuthenticationContext();
context.setPrincipal(principal);
if (authorizer.hasRole(context, Roles.ROLE_ADMIN)) {
user.setAdmin(true);
} else {
user.setAdmin(false);
}
return user;
}
Aggregations