|
@@ -3,20 +3,22 @@ package com.dragon.tj.portal.auth.controller;
|
|
|
import com.dragon.tj.portal.auth.model.LoginUser;
|
|
|
import com.dragon.tj.portal.auth.service.TokenService;
|
|
|
import com.dragon.tj.portal.auth.web.entity.SysUser;
|
|
|
+import com.dragon.tj.portal.auth.web.service.SysUserService;
|
|
|
import com.dragon.tj.portal.common.base.R;
|
|
|
import com.dragon.tj.portal.common.enums.message.MessageInfoErrorEnums;
|
|
|
import com.dragon.tj.portal.component.exception.message.MessageInfoException;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
+import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -32,16 +34,21 @@ public class SsoController {
|
|
|
|
|
|
@Autowired
|
|
|
private TokenService tokenService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+
|
|
|
|
|
|
@GetMapping("/login")
|
|
|
- public R login(HttpServletResponse response) {
|
|
|
- SysUser sysUser = new SysUser();
|
|
|
- sysUser.setIdcard("120222197001010002");
|
|
|
- sysUser.setName("李四");
|
|
|
- sysUser.setOrgCode("120000450200");
|
|
|
- sysUser.setOrgName("服务实战值班岛");
|
|
|
- List<String> perms = Arrays.asList("gzt", "yyzx");
|
|
|
+ public R login(@RequestParam(required = false) String idCard, HttpServletRequest request) {
|
|
|
+ if (StringUtils.isBlank(idCard)) {
|
|
|
+ idCard = "120222197001010002";
|
|
|
+ }
|
|
|
+ SysUser sysUser = sysUserService.getUserById(idCard);
|
|
|
+ List<String> perms = Arrays.asList("gzt", "yyzx", "ywzx", "xxgl", "rjxz", "rzcx", "cjwt");
|
|
|
LoginUser loginUser = new LoginUser(sysUser.getIdcard(), sysUser.getOrgCode(), sysUser, new HashSet<>(perms));
|
|
|
+ UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
|
|
|
+ authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
String token = tokenService.createToken(loginUser);
|
|
|
Map<String, String> data = new HashMap<>();
|
|
|
data.put("token", token);
|