cn.herodotus.stirrup.rest.servlet.upms.controller.security.SysUserController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-module-servlet-upms Show documentation
Show all versions of rest-module-servlet-upms Show documentation
Herodotus 软件生态组件库 UPMS 功能 Servlet 环境 REST 接口模块
The newest version!
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2020-2030 郑庚伟 ZHENGGENGWEI (码匠君), Licensed under the AGPL License
*
* This file is part of Herodotus Stirrup.
*
* Herodotus Stirrup is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Herodotus Stirrup is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package cn.herodotus.stirrup.rest.servlet.upms.controller.security;
import cn.herodotus.stirrup.core.definition.domain.Result;
import cn.herodotus.stirrup.data.crud.service.JpaWriteableService;
import cn.herodotus.stirrup.logic.upms.entity.security.SysUser;
import cn.herodotus.stirrup.logic.upms.service.security.SysUserService;
import cn.herodotus.stirrup.web.api.servlet.AbstractJpaWriteableController;
import cn.herodotus.stirrup.web.core.annotation.Crypto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.springframework.web.bind.annotation.*;
/**
* Description: 系统用户接口
*
* @author : gengwei.zheng
* @date : 2019/11/25 10:55
*/
@RestController
@RequestMapping("/security/user")
@Tags({
@Tag(name = "用户安全管理接口"),
@Tag(name = "系统用户管理接口")
})
public class SysUserController extends AbstractJpaWriteableController {
private final SysUserService sysUserService;
public SysUserController(SysUserService sysUserService) {
this.sysUserService = sysUserService;
}
@Override
public JpaWriteableService getWriteableService() {
return this.sysUserService;
}
/**
* 给用户分配角色
*
* @param userId 用户Id
* @param roles 角色Id数组
* @return {@link Result}
*/
@Operation(summary = "给用户分配角色", description = "给用户分配角色",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(mediaType = "application/x-www-form-urlencoded")),
responses = {@ApiResponse(description = "已分配角色的用户数据", content = @Content(mediaType = "application/json"))})
@Parameters({
@Parameter(name = "userId", required = true, description = "userId"),
@Parameter(name = "roles[]", required = true, description = "角色对象组成的数组")
})
@PutMapping
public Result assign(@RequestParam(name = "userId") String userId, @RequestParam(name = "roles[]") String[] roles) {
SysUser sysUser = sysUserService.assign(userId, roles);
return result(sysUser);
}
@Operation(summary = "修改密码", description = "修改用户使用密码,默认使用加密请求传输",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(mediaType = "application/x-www-form-urlencoded")),
responses = {@ApiResponse(description = "修改密码后的用户信息", content = @Content(mediaType = "application/json"))})
@Parameters({
@Parameter(name = "userId", required = true, description = "userId"),
@Parameter(name = "password", required = true, description = "角色对象组成的数组")
})
@Crypto(responseEncrypt = false)
@PutMapping("/change-password")
public Result changePassword(@RequestParam(name = "userId") String userId, @RequestParam(name = "password") String password) {
SysUser sysUser = sysUserService.changePassword(userId, password);
return result(sysUser);
}
@Operation(summary = "根据用户名查询系统用户", description = "通过username查询系统用户数据",
responses = {
@ApiResponse(description = "查询到的用户", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SysUser.class))),
@ApiResponse(responseCode = "204", description = "查询成功,未查到数据"),
@ApiResponse(responseCode = "500", description = "查询失败")
}
)
@Parameters({
@Parameter(name = "username", required = true, in = ParameterIn.PATH, description = "用户名"),
})
@GetMapping("/sign-in/{username}")
public Result findByUsername(@PathVariable("username") String username) {
SysUser sysUser = sysUserService.findByUsername(username);
return result(sysUser);
}
}