提交 626ceb22 编写于 作者: sq3536's avatar sq3536

钉钉免密

上级 a6bae625
......@@ -103,6 +103,13 @@
<artifactId>spring-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<properties>
......
......@@ -9,6 +9,7 @@ import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.security.AuthTokenUtil;
import cn.ibizlab.util.security.AuthenticationInfo;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.AuthenticationUserService;
import cn.ibizlab.util.service.IBZUSERService;
......@@ -18,10 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.UUID;
......@@ -46,15 +44,16 @@ public class UserDingtalkRegisterResource {
/**
* 获取钉钉开放平台创建的网站应用appid
*/
@GetMapping(value = "/uaa/getDingtalkAppId")
public ResponseEntity<JSONObject> getDingtalkAppId() {
@GetMapping(value = {"/uaa/getDingtalkAppId","/uaa/open/dingtalk/access_token","/uaa/open/dingtalk/appid"})
public ResponseEntity<JSONObject> getDingtalkAppId(@RequestParam(value = "id",required = false) String id) {
JSONObject obj = new JSONObject();
SysOpenAccess openAccess = openAccessService.getById("dingtalk");
SysOpenAccess openAccess = userDingtalkRegisterService.getOpenAccess(id);
if (openAccess==null || (openAccess.getDisabled()!=null && openAccess.getDisabled()==1))
return ResponseEntity.ok(obj);
String appId = openAccess.getAccessKey();// qq互联appid
String appId = openAccess.getAccessKey();
if (!StringUtils.isEmpty(appId)) {
obj.put("appid", appId);
obj.put("access_token",openAccess.getAccessToken());
}
return ResponseEntity.ok(obj);
......@@ -68,15 +67,17 @@ public class UserDingtalkRegisterResource {
* @return
*/
@PostMapping(value = "/uaa/queryDingtalkUserByCode")
public ResponseEntity<JSONObject> queryDingtalkUserByCode(@RequestBody JSONObject param) {
public ResponseEntity<JSONObject> queryDingtalkUserByCode(@RequestParam(value = "id",required = false) String id,@RequestParam(value = "code",required = false) String tmpcode,@RequestBody JSONObject param) {
JSONObject object = new JSONObject();
// 空校验
String code = param.getString("code");
if (StringUtils.isEmpty(code))
code = tmpcode;
if (StringUtils.isEmpty(code))
throw new BadRequestAlertException("code为空", "UserDingtalkRegisterResource", "");
// 从数据库中获取钉钉授权应用信息
SysOpenAccess openAccess = openAccessService.getById("dingtalk");
SysOpenAccess openAccess = userDingtalkRegisterService.getOpenAccess(id);
if (openAccess==null || (openAccess.getDisabled()!=null && openAccess.getDisabled()==1))
throw new BadRequestAlertException("未找到配置", "UserDingtalkRegisterResource", "");
String appId = openAccess.getAccessKey();// 个人应用开发过程中的唯一性标识AppId
......@@ -95,7 +96,7 @@ public class UserDingtalkRegisterResource {
}
// 根据openid查用户授权信息
SysUserAuth userAuth = sysUserAuthService.getOne(Wrappers.<SysUserAuth>query().eq("identifier", openid));
SysUserAuth userAuth = sysUserAuthService.getOne(Wrappers.<SysUserAuth>lambdaQuery().eq(SysUserAuth::getIdentityType,"dingtalk").eq(SysUserAuth::getIdentifier, openid));
// 该钉钉用户注册过账号,登录系统
if (!StringUtils.isEmpty(userAuth)) {
IBZUSER ibzuser = ibzuserService.getById(userAuth.getUserid());
......@@ -182,4 +183,21 @@ public class UserDingtalkRegisterResource {
}
@GetMapping(value = {"/uaa/open/dingtalk/auth/{code}"})
public ResponseEntity<AuthenticationInfo> getUserByToken(@PathVariable(value = "code") String code, @RequestParam(value = "id",required = false) String id) {
AuthenticationUser user=userDingtalkRegisterService.getUserByToken(id,code);
final String token = jwtTokenUtil.generateToken(user);
AuthenticationUser user2=new AuthenticationUser();
CachedBeanCopier.copy(user,user2);
user2.setAuthorities(null);
user2.setPermissionList(null);
// 返回 token
return ResponseEntity.ok().body(new AuthenticationInfo(token,user2));
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册