mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-05-31 18:03:52 +08:00
增加swagger3文档说明
This commit is contained in:
@@ -19,6 +19,10 @@ package org.hswebframework.web.authorization.basic.web;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.SneakyThrows;
|
||||
import org.hswebframework.web.authorization.Authentication;
|
||||
import org.hswebframework.web.authorization.ReactiveAuthenticationManager;
|
||||
@@ -34,6 +38,7 @@ import org.hswebframework.web.authorization.simple.PlainTextUsernamePasswordAuth
|
||||
import org.hswebframework.web.logging.AccessLogger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -47,6 +52,7 @@ import java.util.function.Function;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("${hsweb.web.mappings.authorize:authorize}")
|
||||
@Tag(name = "授权接口")
|
||||
public class AuthorizationController {
|
||||
|
||||
|
||||
@@ -58,7 +64,7 @@ public class AuthorizationController {
|
||||
|
||||
@GetMapping("/me")
|
||||
@Authorize
|
||||
@ApiOperation("当前登录用户权限信息")
|
||||
@Operation(summary = "当前登录用户权限信息")
|
||||
public Mono<Authentication> me() {
|
||||
return Authentication.currentReactive()
|
||||
.switchIfEmpty(Mono.error(UnAuthorizedException::new));
|
||||
@@ -68,7 +74,8 @@ public class AuthorizationController {
|
||||
@ApiOperation("用户名密码登录,json方式")
|
||||
@Authorize(ignore = true)
|
||||
@AccessLogger(ignore = true)
|
||||
public Mono<Map<String, Object>> authorizeByJson(@ApiParam(example = "{\"username\":\"admin\",\"password\":\"admin\"}")
|
||||
@Operation(summary = "登录",description = "必要参数:username,password.根据配置不同,其他参数也不同,如:验证码等.")
|
||||
public Mono<Map<String, Object>> authorizeByJson(@Parameter(example = "{\"username\":\"admin\",\"password\":\"admin\"}")
|
||||
@RequestBody Mono<Map<String, Object>> parameter) {
|
||||
return doLogin(parameter);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.hswebframework.web.authorization.basic.web;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.hswebframework.web.authorization.Authentication;
|
||||
import org.hswebframework.web.authorization.ReactiveAuthenticationManager;
|
||||
import org.hswebframework.web.authorization.annotation.Authorize;
|
||||
@@ -24,6 +25,7 @@ import reactor.core.publisher.Mono;
|
||||
@RequestMapping
|
||||
@Authorize
|
||||
@Resource(id = "user-token", name = "用户令牌信息管理")
|
||||
@Tag(name = "用户令牌管理")
|
||||
public class ReactiveUserTokenController {
|
||||
private UserTokenManager userTokenManager;
|
||||
|
||||
@@ -43,7 +45,7 @@ public class ReactiveUserTokenController {
|
||||
|
||||
@GetMapping("/user-token/reset")
|
||||
@Authorize(merge = false)
|
||||
@ApiOperation("重置当前用户的令牌")
|
||||
@Operation(summary = "重置当前用户的令牌")
|
||||
public Mono<Boolean> resetToken() {
|
||||
return ContextUtils.reactiveContext()
|
||||
.map(context -> context.get(ContextKey.of(ParsedToken.class)).orElseThrow(UnAuthorizedException::new))
|
||||
@@ -52,7 +54,7 @@ public class ReactiveUserTokenController {
|
||||
}
|
||||
|
||||
@PutMapping("/user-token/check")
|
||||
@ApiOperation("检查所有已过期的token并移除")
|
||||
@Operation(summary = "检查所有已过期的token并移除")
|
||||
@SaveAction
|
||||
public Mono<Boolean> checkExpiredToken() {
|
||||
return userTokenManager
|
||||
@@ -61,63 +63,63 @@ public class ReactiveUserTokenController {
|
||||
}
|
||||
|
||||
@GetMapping("/user-token/token/{token}")
|
||||
@ApiOperation("根据token获取令牌信息")
|
||||
@Operation(summary = "根据token获取令牌信息")
|
||||
@QueryAction
|
||||
public Mono<UserToken> getByToken(@PathVariable String token) {
|
||||
return userTokenManager.getByToken(token);
|
||||
}
|
||||
|
||||
@GetMapping("/user-token/user/{userId}")
|
||||
@ApiOperation("根据用户ID获取全部令牌信息")
|
||||
@Operation(summary = "根据用户ID获取全部令牌信息")
|
||||
@QueryAction
|
||||
public Flux<UserToken> getByUserId(@PathVariable String userId) {
|
||||
return userTokenManager.getByUserId(userId);
|
||||
}
|
||||
|
||||
@GetMapping("/user-token/user/{userId}/logged")
|
||||
@ApiOperation("根据用户ID判断用户是否已经登录")
|
||||
@Operation(summary = "根据用户ID判断用户是否已经登录")
|
||||
@QueryAction
|
||||
public Mono<Boolean> userIsLoggedIn(@PathVariable String userId) {
|
||||
return userTokenManager.userIsLoggedIn(userId);
|
||||
}
|
||||
|
||||
@GetMapping("/user-token/token/{token}/logged")
|
||||
@ApiOperation("根据令牌判断用户是否已经登录")
|
||||
@Operation(summary = "根据令牌判断用户是否已经登录")
|
||||
@QueryAction
|
||||
public Mono<Boolean> tokenIsLoggedIn(@PathVariable String token) {
|
||||
return userTokenManager.tokenIsLoggedIn(token);
|
||||
}
|
||||
|
||||
@GetMapping("/user-token/user/total")
|
||||
@ApiOperation("获取当前已经登录的用户数量")
|
||||
@Operation(summary = "获取当前已经登录的用户数量")
|
||||
@Authorize(merge = false)
|
||||
public Mono<Integer> totalUser() {
|
||||
return userTokenManager.totalUser();
|
||||
}
|
||||
|
||||
@GetMapping("/user-token/token/total")
|
||||
@ApiOperation("获取当前已经登录的令牌数量")
|
||||
@Operation(summary = "获取当前已经登录的令牌数量")
|
||||
@Authorize(merge = false)
|
||||
public Mono<Integer> totalToken() {
|
||||
return userTokenManager.totalToken();
|
||||
}
|
||||
|
||||
@GetMapping("/user-token")
|
||||
@ApiOperation("获取全部用户令牌信息")
|
||||
@Operation(summary = "获取全部用户令牌信息")
|
||||
@QueryAction
|
||||
public Flux<UserToken> allLoggedUser() {
|
||||
return userTokenManager.allLoggedUser();
|
||||
}
|
||||
|
||||
@DeleteMapping("/user-token/user/{userId}")
|
||||
@ApiOperation("根据用户id将用户踢下线")
|
||||
@Operation(summary = "根据用户id将用户踢下线")
|
||||
@SaveAction
|
||||
public Mono<Void> signOutByUserId(@PathVariable String userId) {
|
||||
return userTokenManager.signOutByUserId(userId);
|
||||
}
|
||||
|
||||
@DeleteMapping("/user-token/token/{token}")
|
||||
@ApiOperation("根据令牌将用户踢下线")
|
||||
@Operation(summary = "根据令牌将用户踢下线")
|
||||
@SaveAction
|
||||
public Mono<Void> signOutByToken(@PathVariable String token) {
|
||||
return userTokenManager.signOutByToken(token);
|
||||
@@ -126,35 +128,35 @@ public class ReactiveUserTokenController {
|
||||
|
||||
@SaveAction
|
||||
@PutMapping("/user-token/user/{userId}/{state}")
|
||||
@ApiOperation("根据用户id更新用户令牌状态")
|
||||
@Operation(summary = "根据用户id更新用户令牌状态")
|
||||
public Mono<Void> changeUserState(@PathVariable String userId, @PathVariable TokenState state) {
|
||||
|
||||
return userTokenManager.changeUserState(userId, state);
|
||||
}
|
||||
|
||||
@PutMapping("/user-token/token/{token}/{state}")
|
||||
@ApiOperation("根据令牌更新用户令牌状态")
|
||||
@Operation(summary = "根据令牌更新用户令牌状态")
|
||||
@SaveAction
|
||||
public Mono<Void> changeTokenState(@PathVariable String token, @PathVariable TokenState state) {
|
||||
return userTokenManager.changeTokenState(token, state);
|
||||
}
|
||||
|
||||
@PostMapping("/user-token/{token}/{type}/{userId}/{maxInactiveInterval}")
|
||||
@ApiOperation("将用户设置为登录")
|
||||
@SaveAction
|
||||
public Mono<UserToken> signIn(@PathVariable String token, @PathVariable String type, @PathVariable String userId, @PathVariable long maxInactiveInterval) {
|
||||
return userTokenManager.signIn(token, type, userId, maxInactiveInterval);
|
||||
}
|
||||
//
|
||||
// @PostMapping("/user-token/{token}/{type}/{userId}/{maxInactiveInterval}")
|
||||
// @Operation(summary = "将用户设置为登录")
|
||||
// @SaveAction
|
||||
// public Mono<UserToken> signIn(@PathVariable String token, @PathVariable String type, @PathVariable String userId, @PathVariable long maxInactiveInterval) {
|
||||
// return userTokenManager.signIn(token, type, userId, maxInactiveInterval);
|
||||
// }
|
||||
|
||||
@GetMapping("/user-token/{token}/touch")
|
||||
@ApiOperation("更新token有效期")
|
||||
@Operation(summary = "更新token有效期")
|
||||
@SaveAction
|
||||
public Mono<Void> touch(@PathVariable String token) {
|
||||
return userTokenManager.touch(token);
|
||||
}
|
||||
|
||||
@GetMapping("/user-auth/{userId}")
|
||||
@ApiOperation("根据用户id获取用户的权限信息")
|
||||
@Operation(summary = "根据用户id获取权限信息")
|
||||
@SaveAction
|
||||
public Mono<Authentication> userAuthInfo(@PathVariable String userId) {
|
||||
return authenticationManager.getByUserId(userId);
|
||||
|
||||
Reference in New Issue
Block a user