add oa单点登录
This commit is contained in:
@@ -120,4 +120,6 @@ public interface ILoginService{
|
||||
* @return
|
||||
*/
|
||||
public Result<JSONObject> srmsByToken(String username);
|
||||
|
||||
Result<JSONObject> loginByUserName(String userName);
|
||||
}
|
||||
|
||||
+21
@@ -729,4 +729,25 @@ public class LoginServiceImpl implements ILoginService {
|
||||
baseCommonService.addLog(USER_NAME + userName + LOGIN_SUCCEED, CommonConstant.LOG_TYPE_1, null,loginUser);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<JSONObject> loginByUserName(String userName) {
|
||||
// 获取用户信息
|
||||
SysUser sysUser = sysUserService.getUserByName(userName);
|
||||
// 校验用户是否有效
|
||||
Result<JSONObject> result = sysUserService.checkUserIsEffective(sysUser);
|
||||
if(!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
if (checkSysPermission(sysUser.getUsername())) {
|
||||
return Result.error("该用户无权限,请联系管理员");
|
||||
}
|
||||
//用户登录信息
|
||||
userInfo(sysUser, result);
|
||||
//update-begin--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(sysUser, loginUser);
|
||||
baseCommonService.addLog(USER_NAME + userName + LOGIN_SUCCEED, CommonConstant.LOG_TYPE_1, null,loginUser);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.jero.modules.docking.oa.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.docking.oa.service.OAService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
/**
|
||||
* @author lijiarao
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/oa")
|
||||
@Slf4j
|
||||
public class OALoginController {
|
||||
@Resource
|
||||
private OAService oaService;
|
||||
|
||||
@ApiOperation("OA单点登录")
|
||||
@PostMapping("/login")
|
||||
public Result<JSONObject> login(@RequestBody JSONObject jsonObject){
|
||||
return oaService.login(jsonObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.jero.modules.docking.oa.service;
|
||||
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.system.service.ILoginService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author liJiaRao
|
||||
* @date 2024-02-26 17:20
|
||||
*/
|
||||
@Service
|
||||
public class OAService {
|
||||
@Resource
|
||||
private ILoginService loginService;
|
||||
|
||||
public static final String TICKET = "ticket";
|
||||
public static final String APP_ID = "appId";
|
||||
public static final String APP_SECRET = "appSecret";
|
||||
public static final String ACCESS_TOKEN = "accessToken";
|
||||
public static final String USER_NAME = "userName";
|
||||
|
||||
@Value("${oa.getAccessTokenUrl}")
|
||||
private String getAccessTokenUrl;
|
||||
@Value("${oa.getTicketInfoUrl}")
|
||||
private String getTicketInfoUrl;
|
||||
@Value("${oa.appId}")
|
||||
private String appId;
|
||||
@Value("${oa.appSecret}")
|
||||
private String appSecret;
|
||||
|
||||
|
||||
public Result<JSONObject> login(JSONObject jsonObject) {
|
||||
String ticket = jsonObject.getString(TICKET);
|
||||
JSONObject body = new JSONObject();
|
||||
body.put(APP_ID, appId);
|
||||
body.put(APP_SECRET, appSecret);
|
||||
|
||||
String post = HttpRequest.post(getAccessTokenUrl)
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(body.toJSONString())
|
||||
.execute().body();
|
||||
JSONObject responseJson = JSONObject.parseObject(post);
|
||||
|
||||
String accessToken = responseJson.getString(ACCESS_TOKEN);
|
||||
JSONObject body1 = new JSONObject();
|
||||
body1.put(ACCESS_TOKEN, accessToken);
|
||||
body1.put(TICKET, ticket);
|
||||
String post1 = HttpRequest.post(getTicketInfoUrl)
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(body1.toJSONString())
|
||||
.execute().body();
|
||||
JSONObject responseJson1 = JSONObject.parseObject(post1);
|
||||
String userName = responseJson1.getString(USER_NAME);
|
||||
|
||||
return loginService.loginByUserName(userName);
|
||||
}
|
||||
}
|
||||
@@ -437,6 +437,13 @@ oauth:
|
||||
# 防止跨站请求伪造(CSRF)标识(暂时不用)
|
||||
state: zhongQi
|
||||
|
||||
oa:
|
||||
url: http://oa
|
||||
getAccessTokenUrl: ${oa.url}/getAccessToken
|
||||
getTicketInfoUrl: ${oa.url}/getTicketInfo
|
||||
appId: SRMS
|
||||
appSecret: 196b2e1f-127f-47d5-8e33-746fb8ad0387
|
||||
|
||||
# 起草部门部门名称
|
||||
draftDepartName: 起草部门
|
||||
|
||||
|
||||
Reference in New Issue
Block a user