refactor(系统设置): 认证设置接口调整
This commit is contained in:
parent
d249af2c93
commit
251e666e4b
|
@ -10,6 +10,7 @@ import io.metersphere.sdk.util.PageUtils;
|
||||||
import io.metersphere.sdk.util.Pager;
|
import io.metersphere.sdk.util.Pager;
|
||||||
import io.metersphere.system.domain.AuthSource;
|
import io.metersphere.system.domain.AuthSource;
|
||||||
import io.metersphere.system.request.AuthSourceRequest;
|
import io.metersphere.system.request.AuthSourceRequest;
|
||||||
|
import io.metersphere.system.request.AuthSourceStatusRequest;
|
||||||
import io.metersphere.system.service.AuthSourceLogService;
|
import io.metersphere.system.service.AuthSourceLogService;
|
||||||
import io.metersphere.system.service.AuthSourceService;
|
import io.metersphere.system.service.AuthSourceService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
@ -42,16 +43,16 @@ public class AuthSourceController {
|
||||||
@Operation(summary = "新增认证设置")
|
@Operation(summary = "新增认证设置")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_CREAT)
|
@RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_CREAT)
|
||||||
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#authSource)", msClass = AuthSourceLogService.class)
|
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#authSource)", msClass = AuthSourceLogService.class)
|
||||||
public void add(@Validated @RequestBody AuthSourceRequest authSource) {
|
public AuthSource add(@Validated @RequestBody AuthSourceRequest authSource) {
|
||||||
authSourceService.addAuthSource(authSource);
|
return authSourceService.addAuthSource(authSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
@Operation(summary = "更新认证设置")
|
@Operation(summary = "更新认证设置")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE)
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#authSource)", msClass = AuthSourceLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#authSource)", msClass = AuthSourceLogService.class)
|
||||||
public void update(@Validated @RequestBody AuthSourceRequest authSource) {
|
public AuthSourceRequest update(@Validated @RequestBody AuthSourceRequest authSource) {
|
||||||
authSourceService.updateAuthSource(authSource);
|
return authSourceService.updateAuthSource(authSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/get/{id}")
|
@GetMapping("/get/{id}")
|
||||||
|
@ -70,11 +71,11 @@ public class AuthSourceController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/update/{authId}/status/{status}")
|
@PostMapping("/update/status")
|
||||||
@Operation(summary = "更新状态")
|
@Operation(summary = "更新状态")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE)
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#authId)", msClass = AuthSourceLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request.getId())", msClass = AuthSourceLogService.class)
|
||||||
public void updateStatus(@PathVariable(value = "authId") String authId, @PathVariable("status") String status) {
|
public void updateStatus(@Validated @RequestBody AuthSourceStatusRequest request ) {
|
||||||
authSourceService.updateStatus(authId, status);
|
authSourceService.updateStatus(request.getId(), request.getEnable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package io.metersphere.system.request;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class AuthSourceStatusRequest implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Schema(title = "是否禁用")
|
||||||
|
private Boolean enable;
|
||||||
|
|
||||||
|
@Schema(title = "id")
|
||||||
|
private String id;
|
||||||
|
}
|
|
@ -26,10 +26,11 @@ public class AuthSourceService {
|
||||||
return authSourceMapper.selectByExample(example);
|
return authSourceMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAuthSource(AuthSourceRequest authSource) {
|
public AuthSource addAuthSource(AuthSourceRequest authSource) {
|
||||||
checkAuthSource(authSource);
|
checkAuthSource(authSource);
|
||||||
AuthSource source = delRequestToDB(authSource);
|
AuthSource source = delRequestToDB(authSource);
|
||||||
authSourceMapper.insertSelective(source);
|
authSourceMapper.insertSelective(source);
|
||||||
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthSource delRequestToDB(AuthSourceRequest authSource) {
|
private AuthSource delRequestToDB(AuthSourceRequest authSource) {
|
||||||
|
@ -47,9 +48,6 @@ public class AuthSourceService {
|
||||||
|
|
||||||
public void checkAuthSource(AuthSourceRequest authSource) {
|
public void checkAuthSource(AuthSourceRequest authSource) {
|
||||||
String resourcePoolName = authSource.getName();
|
String resourcePoolName = authSource.getName();
|
||||||
if (StringUtils.isBlank(resourcePoolName)) {
|
|
||||||
throw new MSException(Translator.get("authsource_name_is_null"));
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthSourceExample example = new AuthSourceExample();
|
AuthSourceExample example = new AuthSourceExample();
|
||||||
AuthSourceExample.Criteria criteria = example.createCriteria();
|
AuthSourceExample.Criteria criteria = example.createCriteria();
|
||||||
|
@ -74,7 +72,7 @@ public class AuthSourceService {
|
||||||
return authSourceMapper.selectByPrimaryKey(id);
|
return authSourceMapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAuthSource(AuthSourceRequest authSource) {
|
public AuthSourceRequest updateAuthSource(AuthSourceRequest authSource) {
|
||||||
checkAuthSource(authSource);
|
checkAuthSource(authSource);
|
||||||
AuthSource source = authSourceMapper.selectByPrimaryKey(authSource.getId());
|
AuthSource source = authSourceMapper.selectByPrimaryKey(authSource.getId());
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
|
@ -84,13 +82,16 @@ public class AuthSourceService {
|
||||||
source.setUpdateTime(System.currentTimeMillis());
|
source.setUpdateTime(System.currentTimeMillis());
|
||||||
authSourceMapper.updateByPrimaryKeySelective(source);
|
authSourceMapper.updateByPrimaryKeySelective(source);
|
||||||
}
|
}
|
||||||
|
return authSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStatus(String id, String status) {
|
public void updateStatus(String id, Boolean status) {
|
||||||
|
if (status != null) {
|
||||||
AuthSource record = new AuthSource();
|
AuthSource record = new AuthSource();
|
||||||
record.setId(id);
|
record.setId(id);
|
||||||
record.setEnable(Boolean.parseBoolean(status));
|
record.setEnable(status);
|
||||||
record.setUpdateTime(System.currentTimeMillis());
|
record.setUpdateTime(System.currentTimeMillis());
|
||||||
authSourceMapper.updateByPrimaryKeySelective(record);
|
authSourceMapper.updateByPrimaryKeySelective(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Pager;
|
import io.metersphere.sdk.util.Pager;
|
||||||
import io.metersphere.system.domain.AuthSource;
|
import io.metersphere.system.domain.AuthSource;
|
||||||
import io.metersphere.system.request.AuthSourceRequest;
|
import io.metersphere.system.request.AuthSourceRequest;
|
||||||
|
import io.metersphere.system.request.AuthSourceStatusRequest;
|
||||||
import org.junit.jupiter.api.MethodOrderer;
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -21,6 +22,7 @@ import org.springframework.test.web.servlet.ResultMatcher;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
|
@ -44,13 +46,18 @@ public class AuthSourceControllerTests extends BaseTest {
|
||||||
|
|
||||||
private static final ResultMatcher CLIENT_ERROR_MATCHER = status().is4xxClientError();
|
private static final ResultMatcher CLIENT_ERROR_MATCHER = status().is4xxClientError();
|
||||||
|
|
||||||
|
public static final String AUTH_SOURCE_UPDATE_STATUS = "/system/authsource/update/status";
|
||||||
|
|
||||||
|
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public void testAddSource() throws Exception {
|
public void testAddSource() throws Exception {
|
||||||
AuthSourceRequest authSource = new AuthSourceRequest();
|
AuthSourceRequest authSource = new AuthSourceRequest();
|
||||||
authSource.setConfiguration("123");
|
|
||||||
authSource.setName("测试CAS");
|
authSource.setName("测试CAS");
|
||||||
authSource.setType("CAS");
|
authSource.setType("CAS");
|
||||||
|
this.requestPost(AUTH_SOURCE_ADD, authSource,ERROR_REQUEST_MATCHER);
|
||||||
|
authSource.setConfiguration("123");
|
||||||
this.requestPost(AUTH_SOURCE_ADD, authSource);
|
this.requestPost(AUTH_SOURCE_ADD, authSource);
|
||||||
|
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
|
@ -64,6 +71,10 @@ public class AuthSourceControllerTests extends BaseTest {
|
||||||
basePageRequest.setCurrent(1);
|
basePageRequest.setCurrent(1);
|
||||||
basePageRequest.setPageSize(10);
|
basePageRequest.setPageSize(10);
|
||||||
this.requestPost(AUTH_SOURCE_LIST, basePageRequest);
|
this.requestPost(AUTH_SOURCE_LIST, basePageRequest);
|
||||||
|
basePageRequest.setSort(new HashMap<>() {{
|
||||||
|
put("createTime", "desc");
|
||||||
|
}});
|
||||||
|
this.requestPost(AUTH_SOURCE_LIST, basePageRequest);
|
||||||
|
|
||||||
requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ, AUTH_SOURCE_LIST, basePageRequest);
|
requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ, AUTH_SOURCE_LIST, basePageRequest);
|
||||||
}
|
}
|
||||||
|
@ -74,11 +85,12 @@ public class AuthSourceControllerTests extends BaseTest {
|
||||||
public void testUpdateSource() throws Exception {
|
public void testUpdateSource() throws Exception {
|
||||||
List<AuthSourceRequest> authSourceList = this.getAuthSourceList();
|
List<AuthSourceRequest> authSourceList = this.getAuthSourceList();
|
||||||
AuthSourceRequest authSource = new AuthSourceRequest();
|
AuthSourceRequest authSource = new AuthSourceRequest();
|
||||||
authSource.setId(authSourceList.get(0).getId());
|
authSource.setId("authsource_id");
|
||||||
authSource.setConfiguration("123666");
|
authSource.setConfiguration("123666");
|
||||||
authSource.setName("更新");
|
authSource.setName("更新");
|
||||||
authSource.setType("CAS");
|
authSource.setType("CAS");
|
||||||
this.requestPost(AUTH_SOURCE_UPDATE, authSource);
|
this.requestPost(AUTH_SOURCE_UPDATE, authSource);
|
||||||
|
authSource.setId(authSourceList.get(0).getId());
|
||||||
|
|
||||||
requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, AUTH_SOURCE_UPDATE, authSource);
|
requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, AUTH_SOURCE_UPDATE, authSource);
|
||||||
}
|
}
|
||||||
|
@ -86,11 +98,14 @@ public class AuthSourceControllerTests extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void testUpdateStatus() throws Exception {
|
public void testUpdateStatus() throws Exception {
|
||||||
List<AuthSourceRequest> authSourceList = this.getAuthSourceList();
|
|
||||||
String url = AUTH_SOURCE_UPDATE + "/" + authSourceList.get(0).getId() + "/status/false";
|
|
||||||
this.requestGet(url);
|
|
||||||
|
|
||||||
requestGetPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, url);
|
List<AuthSourceRequest> authSourceList = this.getAuthSourceList();
|
||||||
|
AuthSourceStatusRequest request = new AuthSourceStatusRequest();
|
||||||
|
request.setId(authSourceList.get(0).getId());
|
||||||
|
this.requestPost(AUTH_SOURCE_UPDATE_STATUS, request);
|
||||||
|
request.setEnable(false);
|
||||||
|
this.requestPost(AUTH_SOURCE_UPDATE_STATUS, request);
|
||||||
|
requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, AUTH_SOURCE_UPDATE_STATUS, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class OperationLogControllerTests extends BaseTest {
|
||||||
this.requestGetWithOkAndReturn(OPTIONS_LIST);
|
this.requestGetWithOkAndReturn(OPTIONS_LIST);
|
||||||
|
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
//requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPTIONS_LIST);
|
requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPTIONS_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -141,7 +141,7 @@ public class OperationLogControllerTests extends BaseTest {
|
||||||
this.requestGetWithOkAndReturn(USER_LIST);
|
this.requestGetWithOkAndReturn(USER_LIST);
|
||||||
|
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
// requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, USER_LIST);
|
requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, USER_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue