parent
5ad8e86d52
commit
a89d09b8eb
@ -0,0 +1,71 @@
|
||||
package com.ruoyi.jjh.declaration.single.controller;
|
||||
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.jjh.declaration.single.dto.response.ChiefResponse;
|
||||
import com.ruoyi.jjh.declaration.single.service.SingleLoginService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.DigestUtils;
|
||||
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.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 政务端登录
|
||||
* @author du
|
||||
* @since 2024/6/4 9:53
|
||||
*/
|
||||
@Api(tags = "政务端单点登录")
|
||||
@RequestMapping("/system/chief")
|
||||
@RestController
|
||||
public class ChiefController {
|
||||
|
||||
@Value("${appkey}")
|
||||
private String appkey;
|
||||
|
||||
@Value("${zwUrl}")
|
||||
private String zwUrl;
|
||||
|
||||
@Resource
|
||||
private SingleLoginService singleLoginService;
|
||||
|
||||
@ApiOperation("政务端登录")
|
||||
@GetMapping
|
||||
public AjaxResult login(
|
||||
@RequestParam("accountName") String accountName,
|
||||
@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("sign") String sign,
|
||||
@RequestParam("loginType") String loginType
|
||||
) {
|
||||
String md5 = accountName+timestamp;
|
||||
String md5Password = DigestUtils.md5DigestAsHex(md5.getBytes());
|
||||
if(md5Password.equals(sign.toLowerCase())){
|
||||
//政务端获取用户信息
|
||||
String url = zwUrl + "?accountName=" + accountName +"&appkey"+appkey;
|
||||
HttpResponse response = HttpUtil.createGet(url).execute();
|
||||
// 获取响应状态码
|
||||
int statusCode = response.getStatus();
|
||||
if (statusCode == 200) {
|
||||
String responseBody = response.body();
|
||||
JSONObject jsonObj = JSONUtil.parseObj(responseBody);
|
||||
JSONObject dataObj = jsonObj.getJSONObject("data");
|
||||
ChiefResponse req = JSONUtil.toBean(dataObj, ChiefResponse.class);
|
||||
// req.setToken(singleLoginService.singleLogin("1","2",null,"02"));
|
||||
//判断几个政务端用户
|
||||
return AjaxResult.success(req);
|
||||
}
|
||||
}else {
|
||||
//跳转到登录页面
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.ruoyi.jjh.declaration.single.dto.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 政务端用户
|
||||
* @author du
|
||||
* @since 2024/6/4 11:05
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("政务端用户")
|
||||
public class ChiefResponse {
|
||||
@ApiModelProperty("本系统token")
|
||||
private String token;
|
||||
|
||||
private String id;
|
||||
private String mainTopOrganizationId;
|
||||
private String isEnabled;
|
||||
private String isOfficial;
|
||||
private String isUseOA;
|
||||
private String name;
|
||||
private String familyName;
|
||||
private String givenName;
|
||||
private String accountName;
|
||||
private String email;
|
||||
private String mobile;
|
||||
private String sex;
|
||||
private String idNumber;
|
||||
private String birthday;
|
||||
private String workPhone;
|
||||
private String shortPhone;
|
||||
private String workAddress;
|
||||
private String state;
|
||||
private String description;
|
||||
private String secondaryEmail;
|
||||
private String hasDomainAccount;
|
||||
private SettingsResponse settings;
|
||||
private List<OrganizationsResponse> organizations;
|
||||
private String whenCreated;
|
||||
private String whenUpdated;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.ruoyi.jjh.declaration.single.dto.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* organizations其他响应类
|
||||
* @author du
|
||||
* @since 2024/6/4 14:42
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("organizations其他响应类")
|
||||
public class OrganizationsOtherResponse {
|
||||
|
||||
private String id;
|
||||
private String parentId;
|
||||
private String name;
|
||||
private String path;
|
||||
private String displayName;
|
||||
private String description;
|
||||
private String order;
|
||||
private String whenCreated;
|
||||
private String whenUpdated;
|
||||
private String type;
|
||||
private SettingsResponse settings;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.ruoyi.jjh.declaration.single.dto.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* organizations响应类
|
||||
* @author du
|
||||
* @since 2024/6/4 14:40
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("organizations响应类")
|
||||
public class OrganizationsResponse {
|
||||
private String userId;
|
||||
private String isPrimary;
|
||||
private String organizationId;
|
||||
private String userOrder;
|
||||
private String organizationOrder;
|
||||
private String user;
|
||||
private OrganizationsOtherResponse organization;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.ruoyi.jjh.declaration.single.dto.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* settings响应类
|
||||
* @author du
|
||||
* @since 2024/6/4 11:07
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("settings响应类")
|
||||
public class SettingsResponse {
|
||||
private String isContactsHidden;
|
||||
private String isContactsHiddenMobile;
|
||||
private String isContactsHiddenBirthday;
|
||||
private String isContactsHiddenWorkPhone;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.ruoyi.jjh.declaration.single.dto.reqponse;
|
||||
package com.ruoyi.jjh.declaration.single.dto.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
@ -1,4 +1,4 @@
|
||||
package com.ruoyi.jjh.declaration.single.dto.reqponse;
|
||||
package com.ruoyi.jjh.declaration.single.dto.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
@ -0,0 +1,10 @@
|
||||
package com.ruoyi.jjh.declaration.single.service;
|
||||
|
||||
/**
|
||||
* 用户验证
|
||||
* @author du
|
||||
* @since 2024/6/4 15:16
|
||||
*/
|
||||
public interface SingleLoginService {
|
||||
String singleLogin(String userName,String nickName,Long id,String userType);
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package com.ruoyi.jjh.declaration.single.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.manager.AsyncManager;
|
||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
import com.ruoyi.jjh.declaration.single.service.SingleLoginService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author du
|
||||
* @since 2024/6/4 15:17
|
||||
*/
|
||||
@Service
|
||||
public class SingleLoginServiceImpl implements SingleLoginService {
|
||||
|
||||
@Resource
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
@Resource
|
||||
private TokenService tokenService;
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
@Override
|
||||
public String singleLogin(String userName, String nickName, Long id, String userType) {
|
||||
// 用户验证
|
||||
Authentication authentication;
|
||||
try {
|
||||
SysUser user = new SysUser();
|
||||
user.setUserName(userName);
|
||||
user.setNickName(nickName);
|
||||
user.setPassword("admin123");
|
||||
Long[] roles = new Long[1];
|
||||
if("01".equals(userType)){
|
||||
roles[0]=101L;
|
||||
}else if("02".equals(userType)){
|
||||
roles[0]=101L;
|
||||
}
|
||||
user.setRoleIds(roles);
|
||||
user.setStatus("0");
|
||||
user.setUserType(userType);
|
||||
user.setEnterpriseId(id);
|
||||
//如果用户名也就是信用代码没有重复的就新增用户
|
||||
if (userService.checkUserNameUnique(user))
|
||||
{
|
||||
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||
userService.insertUser(user);
|
||||
}
|
||||
//新增user账号密码
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userName, "admin123");
|
||||
AuthenticationContextHolder.setContext(authenticationToken);
|
||||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
||||
authentication = authenticationManager.authenticate(authenticationToken);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof BadCredentialsException) {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||
throw new UserPasswordNotMatchException();
|
||||
} else {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGIN_FAIL, e.getMessage()));
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
} finally {
|
||||
AuthenticationContextHolder.clearContext();
|
||||
}
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
// 生成token
|
||||
Map<String, Object> token = tokenService.createToken(loginUser);
|
||||
return String.valueOf(token.get("access_token"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue