Search in sources :

Example 1 with User

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());
    });
}
Also used : User(com.hortonworks.streamline.streams.security.catalog.User) AuthorizationException(com.hortonworks.streamline.streams.security.AuthorizationException)

Example 2 with User

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);
}
Also used : User(com.hortonworks.streamline.streams.security.catalog.User) AuthorizationException(com.hortonworks.streamline.streams.security.AuthorizationException)

Example 3 with User

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);
}
Also used : User(com.hortonworks.streamline.streams.security.catalog.User) AuthorizationException(com.hortonworks.streamline.streams.security.AuthorizationException)

Example 4 with User

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());
}
Also used : UserRole(com.hortonworks.streamline.streams.security.catalog.UserRole) Role(com.hortonworks.streamline.streams.security.catalog.Role) Roles(com.hortonworks.streamline.streams.security.Roles) Produces(javax.ws.rs.Produces) Date(java.util.Date) BiFunction(java.util.function.BiFunction) QueryParam(com.hortonworks.registries.common.QueryParam) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) NewCookie(javax.ws.rs.core.NewCookie) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) WSUtils(com.hortonworks.streamline.common.util.WSUtils) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) EnumSet(java.util.EnumSet) DELETE(javax.ws.rs.DELETE) SecurityUtil(com.hortonworks.streamline.streams.security.SecurityUtil) WebserviceAuthorizationException(com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException) User(com.hortonworks.streamline.streams.security.catalog.User) Context(javax.ws.rs.core.Context) Permission(com.hortonworks.streamline.streams.security.Permission) OK(javax.ws.rs.core.Response.Status.OK) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Cookie(javax.ws.rs.core.Cookie) Timed(com.codahale.metrics.annotation.Timed) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) List(java.util.List) Principal(java.security.Principal) Response(javax.ws.rs.core.Response) AuthenticationContext(com.hortonworks.streamline.streams.security.AuthenticationContext) UriInfo(javax.ws.rs.core.UriInfo) CREATED(javax.ws.rs.core.Response.Status.CREATED) ROLE_SECURITY_ADMIN(com.hortonworks.streamline.streams.security.Roles.ROLE_SECURITY_ADMIN) PathParam(javax.ws.rs.PathParam) EntityNotFoundException(com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException) GET(javax.ws.rs.GET) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) USER(com.hortonworks.streamline.streams.security.catalog.AclEntry.SidType.USER) UserRole(com.hortonworks.streamline.streams.security.catalog.UserRole) AclEntry(com.hortonworks.streamline.streams.security.catalog.AclEntry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ROLE(com.hortonworks.streamline.streams.security.catalog.AclEntry.SidType.ROLE) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) PUT(javax.ws.rs.PUT) RoleHierarchy(com.hortonworks.streamline.streams.security.catalog.RoleHierarchy) Role(com.hortonworks.streamline.streams.security.catalog.Role) User(com.hortonworks.streamline.streams.security.catalog.User)

Example 5 with User

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;
}
Also used : User(com.hortonworks.streamline.streams.security.catalog.User) AuthenticationContext(com.hortonworks.streamline.streams.security.AuthenticationContext) Principal(java.security.Principal)

Aggregations

User (com.hortonworks.streamline.streams.security.catalog.User)22 Role (com.hortonworks.streamline.streams.security.catalog.Role)10 AclEntry (com.hortonworks.streamline.streams.security.catalog.AclEntry)8 UserRole (com.hortonworks.streamline.streams.security.catalog.UserRole)7 Timed (com.codahale.metrics.annotation.Timed)6 QueryParam (com.hortonworks.registries.common.QueryParam)6 AuthorizationException (com.hortonworks.streamline.streams.security.AuthorizationException)6 Permission (com.hortonworks.streamline.streams.security.Permission)6 Path (javax.ws.rs.Path)6 AuthenticationContext (com.hortonworks.streamline.streams.security.AuthenticationContext)5 Roles (com.hortonworks.streamline.streams.security.Roles)4 SecurityUtil (com.hortonworks.streamline.streams.security.SecurityUtil)4 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)4 Principal (java.security.Principal)4 EnumSet (java.util.EnumSet)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 POST (javax.ws.rs.POST)4 Date (java.util.Date)3 DELETE (javax.ws.rs.DELETE)3