Search in sources :

Example 1 with DuplicateEntityException

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

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