public String addAdminUser()

in manager/general/src/main/java/org/apache/doris/stack/service/config/SettingService.java [319:394]


    public String addAdminUser(NewUserAddReq addReq) throws Exception {
        // check whether system has been init
        SettingEntity entity = settingComponent.readSetting(ConfigConstant.AUTH_TYPE_KEY);

        if (entity == null) {
            log.error("auth type need to be set");
            throw new StudioInitException();
        }

        SettingEntity initStep = settingComponent.readSetting(ConfigConstant.INIT_STEP_KEY);

        if (entity.getValue().equals("ldap")) {
            // no password
            checkRequestBody(addReq.checkNameEmpty());
        } else {
            checkRequestBody(addReq.hasEmptyField());
            if (!StringUtils.isEmpty(addReq.getEmail())) {
                // Check whether the mailbox format meets the specification
                utilService.emailCheck(addReq.getEmail());
            }
        }

        CoreUserEntity userEntity;
        Map<String, String> configCache = new HashMap<>();
        if (ldapComponent.enabled()) {
            log.debug("add ldap init admin user");
            if (!initStep.getValue().equals("2")) {
                log.error("the second step ldap config not completed");
                throw new StudioInitException();
            }
            if (initStep.getValue().equals("3")) {
                log.error("ldap config has completed");
                throw new StudioInitException();
            }

            // password does not sync to studio
            // validate ldap user password by ldap search
//            LdapUser ldapUser = ldapComponent.authenticateInitAdminUser(addReq);
//            if (ldapUser == null) {
//                throw new BadRequestException("input Ldap user or password error");
//            } else if (addReq.getEmail() != null) {
//                if (!ldapUser.getEmail().equals(addReq.getEmail())) {
//                    throw new BadRequestException("input Ldap email error");
//                }
//            }
            userEntity = userRepository.getByFirstName(addReq.getName()).get(0);

            settingComponent.addNewSetting(ConfigConstant.INIT_STEP_KEY, "3", configCache);
        } else {
            if (initStep.getValue().equals("2")) {
                log.error("studio config has completed");
                throw new StudioInitException();
            }
            userEntity = new CoreUserEntity(addReq);
            utilService.newPasswordCheck(addReq.getPassword());

            utilService.setPassword(userEntity, addReq.getPassword());
            settingComponent.addNewSetting(ConfigConstant.INIT_STEP_KEY, "2", configCache);
        }
        ConfigCache.writeConfigs(configCache);
        userEntity.setSuperuser(true);
        userEntity.setLastLogin(new Timestamp(System.currentTimeMillis()));
        userEntity.setDateJoined(new Timestamp(System.currentTimeMillis()));

        CoreUserEntity saveUserEntity = userRepository.save(userEntity);
        log.debug("save new user {} success.", saveUserEntity.getId());

        // add login session
        String sessionId = UuidUtil.newUuid();
        CoreSessionEntity sessionEntity = new CoreSessionEntity(sessionId, saveUserEntity.getId(),
                new Timestamp(System.currentTimeMillis()), null);
        sessionRepository.save(sessionEntity);
        log.debug("Add session for user {}", saveUserEntity.getId());
        return sessionId;

    }