Search in sources :

Example 1 with Roles

use of com.hortonworks.streamline.streams.security.Roles in project streamline by hortonworks.

the class DefaultStreamlineAuthorizer method mayBeAssignAdminRole.

private void mayBeAssignAdminRole() {
    LOG.info("Checking if admin users have admin role");
    Role adminRole = catalogService.getRole(Roles.ROLE_ADMIN).orElseGet(() -> {
        Role admin = new Role();
        admin.setName("ROLE_ADMIN");
        admin.setDisplayName("Admin");
        admin.setDescription("Super user role that has all the system roles and privileges");
        admin.setMetadata("{\"colorCode\":\"#8261be\",\"colorLabel\":\"purple\",\"icon\":\"gears\", \"menu\": [\"schemaRegistry\", \"modelRegistry\", \"udf\", \"dashboard\", \"topology\", \"authorizer\", \"notifier\", \"customprocessor\", \"servicepool\", \"environments\"], \"capabilities\": [{\"Applications\": \"Edit\"}, {\"Service Pool\": \"Edit\"}, {\"Environments\": \"Edit\"}, {\"Users\": \"Edit\"}, {\"Dashboard\": \"Edit\"}]}");
        admin.setSystem(false);
        return catalogService.addRole(admin);
    });
    adminUsers.stream().map(userName -> catalogService.getUser(userName)).filter(user -> {
        if (userHasRole(user, Roles.ROLE_ADMIN)) {
            LOG.info("user '{}' already has '{}'", user, Roles.ROLE_ADMIN);
            return false;
        } else {
            return true;
        }
    }).forEach(user -> catalogService.addUserRole(user.getId(), adminRole.getId()));
}
Also used : Role(com.hortonworks.streamline.streams.security.catalog.Role) DuplicateEntityException(com.hortonworks.streamline.common.exception.DuplicateEntityException) SecurityUtil(com.hortonworks.streamline.streams.security.SecurityUtil) AclEntry(com.hortonworks.streamline.streams.security.catalog.AclEntry) Roles(com.hortonworks.streamline.streams.security.Roles) User(com.hortonworks.streamline.streams.security.catalog.User) Logger(org.slf4j.Logger) Permission(com.hortonworks.streamline.streams.security.Permission) SecurityCatalogService(com.hortonworks.streamline.streams.security.service.SecurityCatalogService) LoggerFactory(org.slf4j.LoggerFactory) AuthorizationException(com.hortonworks.streamline.streams.security.AuthorizationException) Set(java.util.Set) Collectors(java.util.stream.Collectors) Map(java.util.Map) Optional(java.util.Optional) AuthenticationContext(com.hortonworks.streamline.streams.security.AuthenticationContext) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) Role(com.hortonworks.streamline.streams.security.catalog.Role) EnumSet(java.util.EnumSet) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils)

Aggregations

DuplicateEntityException (com.hortonworks.streamline.common.exception.DuplicateEntityException)1 AuthenticationContext (com.hortonworks.streamline.streams.security.AuthenticationContext)1 AuthorizationException (com.hortonworks.streamline.streams.security.AuthorizationException)1 Permission (com.hortonworks.streamline.streams.security.Permission)1 Roles (com.hortonworks.streamline.streams.security.Roles)1 SecurityUtil (com.hortonworks.streamline.streams.security.SecurityUtil)1 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)1 AclEntry (com.hortonworks.streamline.streams.security.catalog.AclEntry)1 Role (com.hortonworks.streamline.streams.security.catalog.Role)1 User (com.hortonworks.streamline.streams.security.catalog.User)1 SecurityCatalogService (com.hortonworks.streamline.streams.security.service.SecurityCatalogService)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1