Search in sources :

Example 1 with AuthorizationException

use of com.hortonworks.streamline.streams.security.AuthorizationException 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 AuthorizationException

use of com.hortonworks.streamline.streams.security.AuthorizationException 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 AuthorizationException

use of com.hortonworks.streamline.streams.security.AuthorizationException 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 AuthorizationException

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

Aggregations

AuthorizationException (com.hortonworks.streamline.streams.security.AuthorizationException)4 User (com.hortonworks.streamline.streams.security.catalog.User)4 AclEntry (com.hortonworks.streamline.streams.security.catalog.AclEntry)1