use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class SecurityCatalogService method fillRoles.
private User fillRoles(User user) {
User res = null;
if (user != null) {
User userWithRole = new User(user);
userWithRole.setRoles(Collections.emptySet());
List<QueryParam> qps = QueryParam.params(UserRole.USER_ID, String.valueOf(user.getId()));
listUserRoles(qps).forEach(userRole -> {
userWithRole.addRole(getRole(userRole.getRoleId()).getName());
});
res = userWithRole;
}
return res;
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class SecurityCatalogService method getUser.
public User getUser(Long userId) {
User user = new User();
user.setId(userId);
return fillRoles(this.dao.<User>get(new StorableKey(User.NAMESPACE, user.getPrimaryKey())));
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class SecurityCatalogService method removeUser.
public User removeUser(Long userId) {
User userToRemove = getUser(userId);
if (userToRemove != null) {
if (userToRemove.getRoles() != null) {
userToRemove.getRoles().forEach(roleName -> {
Optional<Role> r = getRole(roleName);
if (r.isPresent()) {
removeUserRole(userId, r.get().getId());
}
});
}
// remove permissions assigned to user
LOG.debug("Removing ACL entries for user {}", userToRemove);
List<QueryParam> qps = QueryParam.params(AclEntry.SID_ID, String.valueOf(userId), AclEntry.SID_TYPE, AclEntry.SidType.USER.toString());
listAcls(qps).forEach(aclEntry -> removeAcl(aclEntry.getId()));
return dao.remove(new StorableKey(User.NAMESPACE, userToRemove.getPrimaryKey()));
}
throw new IllegalArgumentException("No user with id: " + userId);
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class DefaultStreamlineAuthorizer method addAcl.
@Override
public void addAcl(AuthenticationContext ctx, String targetEntityNamespace, Long targetEntityId, boolean owner, boolean grant, 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);
}
AclEntry aclEntry = new AclEntry();
aclEntry.setObjectId(targetEntityId);
aclEntry.setObjectNamespace(targetEntityNamespace);
aclEntry.setSidId(user.getId());
aclEntry.setSidType(AclEntry.SidType.USER);
aclEntry.setOwner(owner);
aclEntry.setGrant(grant);
aclEntry.setPermissions(permissions);
catalogService.addAcl(aclEntry);
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class DefaultStreamlineAuthorizer method mayBeAddAdminUsers.
private void mayBeAddAdminUsers() {
LOG.info("Checking user entries for admin users");
adminUsers.stream().filter(name -> {
User user = catalogService.getUser(name);
if (user != null) {
LOG.info("Entry for user '{}' already exists", name);
return false;
} else {
return true;
}
}).forEach(name -> {
User user = new User();
user.setName(name);
user.setEmail(name + "@auto-generated.com");
user.setMetadata("{\"colorCode\":\"#8261be\",\"colorLabel\":\"purple\",\"icon\":\"gears\"}");
try {
User addedUser = catalogService.addUser(user);
LOG.info("Added admin user entry: {}", addedUser);
} catch (DuplicateEntityException exception) {
// In HA setup the other server may have already added the user.
LOG.info("Caught exception: " + ExceptionUtils.getStackTrace(exception));
LOG.info("Admin user entry: {} already exists.", user);
}
});
}
Aggregations