use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class DefaultStreamlineAuthorizer method removeAcl.
@Override
public void removeAcl(AuthenticationContext ctx, String targetEntityNamespace, Long targetEntityId) {
validateAuthenticationContext(ctx);
String userName = SecurityUtil.getUserName(ctx);
User user = catalogService.getUser(userName);
if (user == null || user.getId() == null) {
String msg = String.format("No such user '%s'", userName);
LOG.warn(msg);
throw new AuthorizationException(msg);
}
catalogService.listUserAcls(user.getId(), targetEntityNamespace, targetEntityId).forEach(acl -> {
LOG.debug("Removing Acl {}", acl);
catalogService.removeAcl(acl.getId());
});
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class DefaultStreamlineAuthorizer method checkPermissions.
private boolean checkPermissions(AuthenticationContext ctx, String targetEntityNamespace, Long targetEntityId, EnumSet<Permission> permissions) {
validateAuthenticationContext(ctx);
String userName = SecurityUtil.getUserName(ctx);
User user = catalogService.getUser(userName);
if (user == null || user.getId() == null) {
String msg = String.format("No such user '%s'", userName);
LOG.warn(msg);
throw new AuthorizationException(msg);
}
return userHasRole(user, Roles.ROLE_ADMIN) || catalogService.checkUserPermissions(targetEntityNamespace, targetEntityId, user.getId(), permissions);
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class DefaultStreamlineAuthorizer method checkRole.
private boolean checkRole(AuthenticationContext ctx, String role) {
validateAuthenticationContext(ctx);
String userName = SecurityUtil.getUserName(ctx);
User user = catalogService.getUser(userName);
if (user == null) {
String msg = String.format("No such user '%s'", userName);
LOG.warn(msg);
throw new AuthorizationException(msg);
}
return userHasRole(user, Roles.ROLE_ADMIN) || userHasRole(user, role);
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class SecurityCatalogResource method filter.
private Collection<AclEntry> filter(Collection<AclEntry> aclEntries, SecurityContext securityContext) {
User currentUser = getCurrentUser(securityContext);
Set<Role> currentUserRoles = catalogService.getAllUserRoles(currentUser);
boolean isSecurityAdmin = SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
return aclEntries.stream().filter(aclEntry -> isSecurityAdmin || matches(aclEntry, currentUser, currentUserRoles)).collect(Collectors.toSet());
}
use of com.hortonworks.streamline.streams.security.catalog.User 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