Merge remote-tracking branch 'origin/leng_dev' into lisb_dev

This commit is contained in:
lishangbu committed 2021-12-31 14:24:46 +08:00
commit 1afff76e4d
5 files changed
+98 -6

No files matched your search

@@ -61,7 +61,12 @@ public enum LoginTypeEnum {
/**
* 开源中国登录
*/
OSC("OSC", "开源中国登录");
OSC("OSC", "开源中国登录"),
/**
* CAS 登录
*/
CAS("CAS", "CAS 登录");
/**
* 类型
+6 -4
View File
@@ -33,10 +33,6 @@
<description>pigx 通用用户权限管理系统业务处理模块</description>
<dependencies>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-idempotent</artifactId>
</dependency>
<!-- 数据库驱动 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
@@ -111,6 +107,12 @@
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<!-- cas sdk -->
<dependency>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
<version>${cas.sdk.version}</version>
</dependency>
<!--web 模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.admin.handler;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails;
import com.pig4cloud.pigx.admin.api.entity.SysUser;
import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper;
import com.pig4cloud.pigx.admin.service.SysUserService;
import com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.jasig.cas.client.validation.Assertion;
import org.jasig.cas.client.validation.Cas30ProxyTicketValidator;
import org.springframework.stereotype.Component;
/**
* @author lengleng
* @date 2018/11/18
*/
@Slf4j
@Component("CAS")
@AllArgsConstructor
public class CasLoginHandler extends AbstractLoginHandler {
private final SysSocialDetailsMapper sysSocialDetailsMapper;
private final SysUserService sysUserService;
/**
* cas 回到的ticket
* <p>
* 通过ticket 调用CAS获取唯一标识
* @param ticket
* @return
*/
@Override
@SneakyThrows
public String identify(String ticket) {
SysSocialDetails condition = new SysSocialDetails();
condition.setType(LoginTypeEnum.CAS.getType());
SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
Cas30ProxyTicketValidator cas30ProxyTicketValidator = new Cas30ProxyTicketValidator(socialDetails.getRemark());
Assertion validate = cas30ProxyTicketValidator.validate(ticket, socialDetails.getRedirectUrl());
return validate.getPrincipal().getName();
}
/**
* openId 获取用户信息
* @param openId
* @return
*/
@Override
public UserInfo info(String username) {
SysUser user = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getUsername, username));
if (user == null) {
log.info("CAS 不存在用户:{}", username);
return null;
}
return sysUserService.findUserInfo(user);
}
}
@@ -62,6 +62,8 @@ public interface LoginHandler {
* @param identify 渠道返回唯一标识
* @return
*/
Boolean bind(SysUser user, String identify);
default Boolean bind(SysUser user, String identify) {
return false;
}
}
+1
View File
@@ -45,6 +45,7 @@
<spring-boot-admin.version>2.5.5</spring-boot-admin.version>
<hutool.version>5.7.18</hutool.version>
<captcha.version>1.2.7</captcha.version>
<cas.sdk.version>3.6.4</cas.sdk.version>
<swagger.fox.version>3.0.0</swagger.fox.version>
<knife4j.version>2.0.9</knife4j.version>
<velocity.version>1.7</velocity.version>