refactor(系统设置): 认证设置同一种类型的认证,只能开启一个
This commit is contained in:
parent
e7e546aab4
commit
858996778b
|
@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS auth_source
|
|||
(
|
||||
`id` VARCHAR(50) NOT NULL COMMENT '认证源ID',
|
||||
`configuration` BLOB NOT NULL COMMENT '认证源配置',
|
||||
`enable` BIT NOT NULL DEFAULT 1 COMMENT '是否启用',
|
||||
`enable` BIT NOT NULL DEFAULT 0 COMMENT '是否启用',
|
||||
`create_time` BIGINT NOT NULL COMMENT '创建时间',
|
||||
`update_time` BIGINT NOT NULL COMMENT '更新时间',
|
||||
`description` VARCHAR(500) COMMENT '描述',
|
||||
|
|
|
@ -2,15 +2,16 @@ package io.metersphere.system.service;
|
|||
|
||||
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.AuthSource;
|
||||
import io.metersphere.system.domain.AuthSourceExample;
|
||||
import io.metersphere.system.dto.AuthSourceDTO;
|
||||
import io.metersphere.system.mapper.AuthSourceMapper;
|
||||
import io.metersphere.system.dto.request.AuthSourceRequest;
|
||||
import io.metersphere.system.mapper.AuthSourceMapper;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -95,9 +96,20 @@ public class AuthSourceService {
|
|||
}
|
||||
|
||||
public AuthSource updateStatus(String id, Boolean status) {
|
||||
if (BooleanUtils.isTrue(status)) {
|
||||
AuthSource authSource = authSourceMapper.selectByPrimaryKey(id);
|
||||
AuthSourceExample example = new AuthSourceExample();
|
||||
example.createCriteria().andIdNotEqualTo(id).andTypeEqualTo(authSource.getType()).andEnableEqualTo(true);
|
||||
List<AuthSource> authSources = authSourceMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(authSources)) {
|
||||
AuthSource source = authSources.get(0);
|
||||
source.setEnable(false);
|
||||
authSourceMapper.updateByPrimaryKeySelective(source);
|
||||
}
|
||||
}
|
||||
AuthSource record = new AuthSource();
|
||||
record.setId(id);
|
||||
record.setEnable(BooleanUtils.toBooleanDefaultIfNull(status,false));
|
||||
record.setEnable(BooleanUtils.toBooleanDefaultIfNull(status, false));
|
||||
record.setUpdateTime(System.currentTimeMillis());
|
||||
authSourceMapper.updateByPrimaryKeySelective(record);
|
||||
return record;
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlConfig;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
@ -114,6 +116,7 @@ public class AuthSourceControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(4)
|
||||
@Sql(scripts = {"/dml/init_auth_source_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testUpdateStatus() throws Exception {
|
||||
|
||||
List<AuthSourceRequest> authSourceList = this.getAuthSourceList();
|
||||
|
@ -123,6 +126,12 @@ public class AuthSourceControllerTests extends BaseTest {
|
|||
request.setEnable(false);
|
||||
this.requestPost(AUTH_SOURCE_UPDATE_STATUS, request);
|
||||
requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, AUTH_SOURCE_UPDATE_STATUS, request);
|
||||
request.setEnable(true);
|
||||
this.requestPost(AUTH_SOURCE_UPDATE_STATUS, request);
|
||||
|
||||
request.setId("wx_test_1");
|
||||
request.setEnable(true);
|
||||
this.requestPost(AUTH_SOURCE_UPDATE_STATUS, request);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
INSERT INTO auth_source(`id`, `configuration`, `enable`, `create_time`, `update_time`, `description`, `name`, `type`)
|
||||
VALUES
|
||||
('wx_test', 123412213, b'1', 1706522490360, 1706522490360, '', '测试一下吧', 'CAS'),
|
||||
('wx_test_1', 123412213, b'1', 1706522490360, 1706522490360, '', '测试两下吧', 'LDAP');
|
Loading…
Reference in New Issue