mirror of
https://github.com/vran-dev/databasir.git
synced 2025-10-18 21:29:19 +08:00
feat: add oauth2 app api
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
package com.databasir.api;
|
||||
|
||||
import com.databasir.common.JsonData;
|
||||
import com.databasir.core.infrastructure.oauth2.OAuthAppService;
|
||||
import com.databasir.core.infrastructure.oauth2.OAuthHandler;
|
||||
import com.databasir.core.infrastructure.oauth2.data.OAuthAppResponse;
|
||||
import com.databasir.core.domain.app.OAuthAppService;
|
||||
import com.databasir.core.domain.app.data.*;
|
||||
import com.databasir.core.domain.app.handler.OAuthHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class OAuth2AppController {
|
||||
@@ -20,6 +25,9 @@ public class OAuth2AppController {
|
||||
|
||||
private final OAuthAppService oAuthAppService;
|
||||
|
||||
/**
|
||||
* 无需授权
|
||||
*/
|
||||
@GetMapping("/oauth2/authorization/{registrationId}")
|
||||
@ResponseBody
|
||||
public JsonData<String> authorization(@PathVariable String registrationId) {
|
||||
@@ -27,10 +35,53 @@ public class OAuth2AppController {
|
||||
return JsonData.ok(authorization);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无需授权
|
||||
*/
|
||||
@GetMapping("/oauth2/apps")
|
||||
@ResponseBody
|
||||
public JsonData<List<OAuthAppResponse>> listApps() {
|
||||
return JsonData.ok(oAuthAppService.listAll());
|
||||
}
|
||||
|
||||
@GetMapping(Routes.OAuth2App.LIST_PAGE)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<Page<OAuthAppPageResponse>> listPage(@PageableDefault(sort = "id", direction = DESC)
|
||||
Pageable page,
|
||||
OAuthAppPageCondition condition) {
|
||||
return JsonData.ok(oAuthAppService.listPage(page, condition));
|
||||
}
|
||||
|
||||
@GetMapping(Routes.OAuth2App.GET_ONE)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<OAuthAppDetailResponse> getOne(@PathVariable Integer id) {
|
||||
return JsonData.ok(oAuthAppService.getOne(id));
|
||||
|
||||
}
|
||||
|
||||
@PostMapping(Routes.OAuth2App.CREATE)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<Integer> create(@RequestBody @Valid OAuthAppCreateRequest request) {
|
||||
Integer id = oAuthAppService.create(request);
|
||||
return JsonData.ok(id);
|
||||
}
|
||||
|
||||
@PatchMapping(Routes.OAuth2App.UPDATE)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<Void> updateById(@RequestBody @Valid OAuthAppUpdateRequest request) {
|
||||
oAuthAppService.updateById(request);
|
||||
return JsonData.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping(Routes.OAuth2App.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
@ResponseBody
|
||||
public JsonData<Void> deleteById(@PathVariable Integer id) {
|
||||
oAuthAppService.deleteById(id);
|
||||
return JsonData.ok();
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -21,6 +22,7 @@ public class OperationLogController {
|
||||
private final OperationLogService operationLogService;
|
||||
|
||||
@GetMapping(Routes.OperationLog.LIST)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||
public JsonData<Page<OperationLogPageResponse>> list(@PageableDefault(sort = "id", direction = Sort.Direction.DESC)
|
||||
Pageable page,
|
||||
OperationLogPageCondition condition) {
|
||||
|
@@ -110,4 +110,18 @@ public interface Routes {
|
||||
interface OperationLog {
|
||||
String LIST = BASE + "/operation_logs";
|
||||
}
|
||||
|
||||
interface OAuth2App {
|
||||
|
||||
String LIST_PAGE = BASE + "/oauth2_apps";
|
||||
|
||||
String CREATE = BASE + "/oauth2_apps";
|
||||
|
||||
String UPDATE = BASE + "/oauth2_apps";
|
||||
|
||||
String DELETE = BASE + "/oauth2_apps/{id}";
|
||||
|
||||
String GET_ONE = BASE + "/oauth2_apps/{id}";
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package com.databasir.api.config.oauth2;
|
||||
|
||||
import com.databasir.api.config.security.DatabasirUserDetailService;
|
||||
import com.databasir.core.domain.user.data.UserDetailResponse;
|
||||
import com.databasir.core.infrastructure.oauth2.OAuthAppService;
|
||||
import com.databasir.core.domain.app.OAuthAppService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.databasir.api.config.security;
|
||||
|
||||
import com.databasir.core.infrastructure.oauth2.exception.DatabasirAuthenticationException;
|
||||
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
||||
import com.databasir.common.JsonData;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
Reference in New Issue
Block a user