|
@@ -12,30 +12,40 @@ import me.zhengjie.annotation.rest.AnonymousGetMapping;
|
|
import me.zhengjie.annotation.rest.AnonymousPostMapping;
|
|
import me.zhengjie.annotation.rest.AnonymousPostMapping;
|
|
import me.zhengjie.base.BaseResponse;
|
|
import me.zhengjie.base.BaseResponse;
|
|
import me.zhengjie.base.QueryPageParams;
|
|
import me.zhengjie.base.QueryPageParams;
|
|
|
|
+import me.zhengjie.exception.BadRequestException;
|
|
import me.zhengjie.modules.dm.user.service.DmUserService;
|
|
import me.zhengjie.modules.dm.user.service.DmUserService;
|
|
import me.zhengjie.modules.dm.user.service.dto.DmUserDto;
|
|
import me.zhengjie.modules.dm.user.service.dto.DmUserDto;
|
|
import me.zhengjie.modules.dm.user.service.dto.DmUserQueryCriteria;
|
|
import me.zhengjie.modules.dm.user.service.dto.DmUserQueryCriteria;
|
|
-import me.zhengjie.modules.system.service.DataService;
|
|
|
|
-import me.zhengjie.modules.system.service.DeptService;
|
|
|
|
-import me.zhengjie.modules.system.service.UserService;
|
|
|
|
-import me.zhengjie.modules.system.service.dto.DeptDto;
|
|
|
|
-import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
|
|
|
|
-import me.zhengjie.modules.system.service.dto.DeptQueryNoAuthCriteria;
|
|
|
|
|
|
+import me.zhengjie.modules.security.config.bean.LoginProperties;
|
|
|
|
+import me.zhengjie.modules.security.config.bean.SecurityProperties;
|
|
|
|
+import me.zhengjie.modules.security.security.TokenProvider;
|
|
|
|
+import me.zhengjie.modules.security.service.OnlineUserService;
|
|
|
|
+import me.zhengjie.modules.security.service.dto.JwtUserDto;
|
|
|
|
+import me.zhengjie.modules.system.service.*;
|
|
|
|
+import me.zhengjie.modules.system.service.dto.*;
|
|
import me.zhengjie.utils.SecurityUtils;
|
|
import me.zhengjie.utils.SecurityUtils;
|
|
|
|
+import me.zhengjie.utils.StringUtils;
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.Criteria;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
|
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -46,8 +56,19 @@ import java.util.Map;
|
|
public class UserApiController {
|
|
public class UserApiController {
|
|
private final DmUserService dmUserService;
|
|
private final DmUserService dmUserService;
|
|
private final UserService userService;
|
|
private final UserService userService;
|
|
- private final DataService dataService;
|
|
|
|
private final DeptService deptService;
|
|
private final DeptService deptService;
|
|
|
|
+ private final JobService jobService;
|
|
|
|
+ private final RoleService roleService;
|
|
|
|
+ private final TokenProvider tokenProvider;
|
|
|
|
+ private final AuthenticationManagerBuilder authenticationManagerBuilder;
|
|
|
|
+ private final OnlineUserService onlineUserService;
|
|
|
|
+ private final SecurityProperties properties;
|
|
|
|
+ @Resource
|
|
|
|
+ private LoginProperties loginProperties;
|
|
|
|
+
|
|
|
|
+ private final PasswordEncoder passwordEncoder;
|
|
|
|
+
|
|
|
|
+ private final String erpapiUrl = "http://222.84.157.37:30170";
|
|
|
|
|
|
@Log("获取ERP用户数据")
|
|
@Log("获取ERP用户数据")
|
|
@ApiOperation("获取ERP用户数据")
|
|
@ApiOperation("获取ERP用户数据")
|
|
@@ -69,10 +90,56 @@ public class UserApiController {
|
|
return new ResponseEntity<>(json, HttpStatus.OK);
|
|
return new ResponseEntity<>(json, HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Log("单点登录")
|
|
|
|
+ @ApiOperation("单点登录")
|
|
|
|
+ @AnonymousGetMapping(value = "/sso")
|
|
|
|
+ public ResponseEntity<Object> sso(HttpServletRequest request) {
|
|
|
|
+ String token = request.getParameter("token");
|
|
|
|
+ String url = request.getParameter("url");
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isBlank(token) || StringUtils.isBlank(url)) {
|
|
|
|
+ throw new BadRequestException("参数错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String res = HttpRequest.get(erpapiUrl + "/api-third-party/busi/comm/authLogin/api/verifyToken?token=" + token).execute().body();
|
|
|
|
+ JSONObject json = JSONObject.parseObject(res);
|
|
|
|
+
|
|
|
|
+ if (json != null) {
|
|
|
|
+ JSONObject data = json.getJSONObject("data");
|
|
|
|
+
|
|
|
|
+ if (data != null) {
|
|
|
|
+
|
|
|
|
+ UserDto userDto = userService.findByName(data.getString("username"));
|
|
|
|
+
|
|
|
|
+ if (userDto != null) {
|
|
|
|
+ UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(data.getString("username"), userDto.getPassword());
|
|
|
|
+ Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
|
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
|
+ // 生成令牌
|
|
|
|
+ String n_token = tokenProvider.createToken(authentication);
|
|
|
|
+ final JwtUserDto jwtUserDto = (JwtUserDto) authentication.getPrincipal();
|
|
|
|
+ // 保存在线信息
|
|
|
|
+ onlineUserService.save(jwtUserDto, n_token, request);
|
|
|
|
+ // 返回 token 与 用户信息
|
|
|
|
+ Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
|
|
|
|
+ put("token", properties.getTokenStartWith() + n_token);
|
|
|
|
+ put("user", jwtUserDto);
|
|
|
|
+ }};
|
|
|
|
+ if (loginProperties.isSingleLogin()) {
|
|
|
|
+ //踢掉之前已经登录的token
|
|
|
|
+ onlineUserService.checkLoginOnUser(data.getString("username"), n_token);
|
|
|
|
+ }
|
|
|
|
+ return ResponseEntity.ok(authInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ throw new BadRequestException("认证失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
@Log("获取用户数据")
|
|
@Log("获取用户数据")
|
|
@ApiOperation("获取用户数据")
|
|
@ApiOperation("获取用户数据")
|
|
@AnonymousPostMapping(value = "/getzkusers")
|
|
@AnonymousPostMapping(value = "/getzkusers")
|
|
- public BaseResponse<Object> getzkusers(@RequestBody QueryPageParams<DmUserQueryCriteria> params, Pageable pageable) {
|
|
|
|
|
|
+ public BaseResponse<Object> getzkusers(@RequestBody QueryPageParams<DmUserQueryCriteria> params, Pageable pageable) {
|
|
SecurityUtils.CheckApiAuth(params);
|
|
SecurityUtils.CheckApiAuth(params);
|
|
Map<String, Object> list = dmUserService.queryAll(params.getQuery(), pageable);
|
|
Map<String, Object> list = dmUserService.queryAll(params.getQuery(), pageable);
|
|
|
|
|
|
@@ -88,4 +155,24 @@ public class UserApiController {
|
|
|
|
|
|
return new BaseResponse<>(list);
|
|
return new BaseResponse<>(list);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Log("获取岗位数据")
|
|
|
|
+ @ApiOperation("获取岗位数据")
|
|
|
|
+ @AnonymousPostMapping(value = "/getzkjobs")
|
|
|
|
+ public BaseResponse<Object> getzkjobs(@RequestBody QueryPageParams<JobQueryCriteria> params, Pageable pageable) {
|
|
|
|
+ SecurityUtils.CheckApiAuth(params);
|
|
|
|
+ Map<String, Object> list = jobService.queryAll(params.getQuery(), pageable);
|
|
|
|
+
|
|
|
|
+ return new BaseResponse<>(list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Log("获取角色数据")
|
|
|
|
+ @ApiOperation("获取角色数据")
|
|
|
|
+ @AnonymousPostMapping(value = "/getzkroles")
|
|
|
|
+ public BaseResponse<Object> getzkroles(@RequestBody QueryPageParams<RoleQueryCriteria> params, Pageable pageable) {
|
|
|
|
+ SecurityUtils.CheckApiAuth(params);
|
|
|
|
+ Map<String, Object> list = roleService.queryAll(params.getQuery(), pageable);
|
|
|
|
+
|
|
|
|
+ return new BaseResponse<>(list);
|
|
|
|
+ }
|
|
}
|
|
}
|