@Override public void filter(ContainerRequestContext requestContext) throws IOException { // we cache in the local filter as we want to avoid expensive lookups. This means if we delete all data, we'll actually misreport has any user. if(hasAnyUser.get()){ return; } if(userService.hasAnyUser()){ hasAnyUser.set(true); return; } handle(requestContext); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { if(!userService.get().hasAnyUser()) { NoUserFilter.handle(requestContext); } } }
/** * Utility method that creates default first user and home folder for the default user. First user is an ADMIN user. * * @param userService {@link UserService} instance * @param namespaceService {@link NamespaceService} instance without the user context. */ public static void addDefaultFirstUser(final UserService userService, final NamespaceService namespaceService) throws Exception { if (!userService.hasAnyUser()) { createUserIfNotExists( userService, namespaceService, DEFAULT_USER_NAME, PASSWORD, DEFAULT_USER_FIRSTNAME, DEFAULT_USER_LASTNAME); // Special case for regression until we move away from views as physical files. // View expansion requires the user who wrote the file on the filesystem // to be present in the usergroup db if (ADD_PROCESS_USER) { createUserIfNotExists( userService, namespaceService, ImpersonationUtil.getProcessUserName(), PASSWORD, DEFAULT_USER_FIRSTNAME, DEFAULT_USER_LASTNAME); } } }
@PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("firstuser") public UserUI createUser(UserForm userForm) throws IOException, IllegalArgumentException, NamespaceException, DACUnauthorizedException, UserNotFoundException { synchronized (this) { if (dContext.getUserService().hasAnyUser()) { throw UserException.validationError().message(ERROR_MSG).build(logger); } final UserName userName = new UserName(userForm.getUserConfig().getUserName()); User newUser = SimpleUser.newBuilder(userForm.getUserConfig()).setCreatedAt(System.currentTimeMillis()).build(); newUser = userService.createUser(newUser, userForm.getPassword()); dContext.getNamespaceService(SystemUser.SYSTEM_USERNAME) .addOrUpdateHome( new HomePath(HomeName.getUserHomePath(userName.getName())).toNamespaceKey(), new HomeConfig().setCtime(System.currentTimeMillis()).setOwner(userName.getName()) ); return new UserUI(new UserResourcePath(userName), userName, newUser); } } }