in manager/general/src/main/java/org/apache/doris/stack/service/config/SettingService.java [122:195]
public void initStudio(InitStudioReq initStudioReq) throws Exception {
log.debug("Init studio auth type.");
checkRequestBody(initStudioReq.getAuthType() == null);
// Check whether the authentication method has been configured
SettingEntity entity = settingComponent.readSetting(ConfigConstant.AUTH_TYPE_KEY);
if (entity != null && !StringUtils.isEmpty(entity.getValue())) {
log.error("Auth config type already exists.");
throw new StudioInitException();
}
// Store the cache information and update the cache in batches after writing to the database successfully,
// because the database can be rolled back, but the cache cannot
Map<String, String> configCache = new HashMap<>();
try {
if (initStudioReq.getAuthType() == InitStudioReq.AuthType.ldap) {
log.debug("init ladp config.");
// Check whether the LDAP request information is complete
log.debug("Check LdapSettingReq info.");
LdapSettingReq ldapSettingReq = initStudioReq.getLdapSetting();
checkRequestBody(ldapSettingReq == null);
checkRequestBody(ldapSettingReq.hasEmptyField());
boolean isConnection = ldapComponent.checkLdapConnection(ldapSettingReq);
if (!isConnection) {
throw new LdapConnectionException();
}
log.debug("add new ldap config.");
settingComponent.addNewSetting(ConfigConstant.AUTH_TYPE_KEY, initStudioReq.getAuthType().name(),
configCache);
ldapComponent.addLdapConfig(ldapSettingReq, configCache);
log.debug("add new ldap config success.");
} else if (initStudioReq.getAuthType() == InitStudioReq.AuthType.studio) {
log.debug("init studio config.");
settingComponent.addNewSetting(ConfigConstant.AUTH_TYPE_KEY, initStudioReq.getAuthType().name(),
configCache);
} else if (initStudioReq.getAuthType() == InitStudioReq.AuthType.idaas) {
log.debug("init idaas config.");
// Check whether the idaas request information is complete
log.debug("Check IdaasSettingReq info.");
IdaasSettingReq idaasSettingReq = initStudioReq.getIdaasSetting();
checkRequestBody(idaasSettingReq == null);
checkRequestBody(idaasSettingReq.hasEmptyField());
// Check idaas connectivity
boolean isConnection = idaasComponent.checkIdaasConnection(idaasSettingReq);
if (!isConnection) {
throw new IdaasConnectionException();
}
log.debug("add new idaas config.");
settingComponent.addNewSetting(ConfigConstant.AUTH_TYPE_KEY, initStudioReq.getAuthType().name(), configCache);
idaasComponent.addIdaasConfig(idaasSettingReq, configCache);
log.debug("add new idaas config success.");
} else {
throw new BadRequestException("不支持此认证方式.");
}
} catch (Exception e) {
SettingEntity authTypeSetting = settingComponent.readSetting(ConfigConstant.AUTH_TYPE_KEY);
if (authTypeSetting != null && !StringUtils.isEmpty(authTypeSetting.getValue())) {
log.error("Write auth type config error, delete auth type from database.");
settingComponent.deleteSetting(ConfigConstant.AUTH_TYPE_KEY);
}
throw e;
}
ConfigCache.writeConfigs(configCache);
}