| | |
| | | <bouncycastle.version>1.72</bouncycastle.version> |
| | | <!-- 离线IPå°åå®ä½åº --> |
| | | <ip2region.version>2.7.0</ip2region.version> |
| | | <justauth.version>1.15.6</justauth.version> |
| | | |
| | | <!-- 临æ¶ä¿®å¤ snakeyaml æ¼æ´ --> |
| | | <snakeyaml.version>1.33</snakeyaml.version> |
| | |
| | | <version>${snakeyaml.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- ç¬¬ä¸æ¹ææç»å½ --> |
| | | <dependency> |
| | | <groupId>me.zhyd.oauth</groupId> |
| | | <artifactId>JustAuth</artifactId> |
| | | <version>${justauth.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- å å¯å
å¼å
¥ --> |
| | | <dependency> |
| | | <groupId>org.bouncycastle</groupId> |
| | |
| | | <artifactId>spring-boot-starter-test</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>me.zhyd.oauth</groupId> |
| | | <artifactId>JustAuth</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.dromara</groupId> |
| | | <artifactId>ruoyi-common-auth</artifactId> |
| | | <version>5.1.0-SNAPSHOT</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.aliyun</groupId> |
| | | <artifactId>credentials-java</artifactId> |
| | | <version>0.2.4</version> |
| | | <scope>compile</scope> |
| | | </dependency> |
| | | |
| | | <!-- skywalking æ´å logback --> |
| | | <!-- <dependency>--> |
| | |
| | | |
| | | import cn.dev33.satoken.annotation.SaIgnore; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import jakarta.validation.constraints.NotBlank; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhyd.oauth.cache.AuthDefaultStateCache; |
| | | import me.zhyd.oauth.cache.AuthStateCache; |
| | | import me.zhyd.oauth.model.AuthCallback; |
| | | import me.zhyd.oauth.model.AuthResponse; |
| | | import me.zhyd.oauth.model.AuthUser; |
| | | import me.zhyd.oauth.request.AuthRequest; |
| | | import me.zhyd.oauth.utils.AuthStateUtils; |
| | | import org.dromara.common.auth.utils.AuthUtils; |
| | | import org.dromara.common.core.domain.R; |
| | | import org.dromara.common.core.domain.model.EmailLoginBody; |
| | | import org.dromara.common.core.domain.model.LoginBody; |
| | |
| | | import org.dromara.common.tenant.helper.TenantHelper; |
| | | import org.dromara.system.domain.bo.SysTenantBo; |
| | | import org.dromara.system.domain.vo.SysTenantVo; |
| | | import org.dromara.system.domain.vo.SysUserVo; |
| | | import org.dromara.system.mapper.SysUserMapper; |
| | | import org.dromara.system.service.ISysConfigService; |
| | | import org.dromara.system.service.ISysTenantService; |
| | | import org.dromara.web.domain.vo.LoginTenantVo; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URL; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * è®¤è¯ |
| | |
| | | @RequestMapping("/auth") |
| | | public class AuthController { |
| | | |
| | | private AuthStateCache authStateCache; |
| | | private final SysLoginService loginService; |
| | | private final SysRegisterService registerService; |
| | | private final ISysConfigService configService; |
| | | private final ISysTenantService tenantService; |
| | | private final SysUserMapper userMapper; |
| | | private final Map<String, String> auths = new HashMap<>(); |
| | | { |
| | | auths.put("gitee", "{\"clientId\":\"38eaaa1b77b5e064313057a2f5745ce3a9f3e7686d9bd302c7df2f308ef6db81\",\"clientSecret\":\"2e633af8780cb9fe002c4c7291b722db944402e271efb99b062811f52d7da1ff\",\"redirectUri\":\"http://127.0.0.1:8888/social-login?source=gitee\"}"); |
| | | auths.put("github", "{\"clientId\":\"Iv1.1be0cdcd71aca63b\",\"clientSecret\":\"0d59d28b43152bc8906011624db37b0fed88d154\",\"redirectUri\":\"http://127.0.0.1:80/social-login?source=github\"}"); |
| | | authStateCache = AuthDefaultStateCache.INSTANCE;// 使ç¨é»è®¤çç¼å |
| | | } |
| | | |
| | | /** |
| | | * ç»å½æ¹æ³ |
| | |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * è®¤è¯ææ |
| | | * @param source |
| | | * @throws IOException |
| | | */ |
| | | @GetMapping("/binding/{source}") |
| | | @ResponseBody |
| | | public R<LoginVo> authBinding(@PathVariable("source") String source, HttpServletRequest request){ |
| | | SysUserVo userLoding = new SysUserVo(); |
| | | if (ObjectUtil.isNull(userLoding)) { |
| | | return R.fail("ææå¤±è´¥ï¼è¯·å
ç»å½åç»å®"); |
| | | } |
| | | if (userMapper.checkAuthUser(userLoding.getUserId(),source) > 0) |
| | | { |
| | | return R.fail(source + "å¹³å°è´¦å·å·²ç»ç»å®"); |
| | | } |
| | | String obj = auths.get(source); |
| | | if (StringUtils.isEmpty(obj)) |
| | | { |
| | | return R.fail(source + "å¹³å°è´¦å·æä¸æ¯æ"); |
| | | } |
| | | JSONObject json = JSONUtil.parseObj(obj); |
| | | AuthRequest authRequest = AuthUtils.getAuthRequest(source, |
| | | json.getStr("clientId"), |
| | | json.getStr("clientSecret"), |
| | | json.getStr("redirectUri"), authStateCache); |
| | | String authorizeUrl = authRequest.authorize(AuthStateUtils.createState()); |
| | | return R.ok(authorizeUrl); |
| | | } |
| | | |
| | | /** |
| | | * @param source |
| | | * @param callback |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | @GetMapping("/social-login/{source}") |
| | | public R<String> socialLogin(@PathVariable("source") String source, AuthCallback callback, HttpServletRequest request) throws IOException { |
| | | String obj = auths.get(source); |
| | | if (StringUtils.isEmpty(obj)) |
| | | { |
| | | return R.fail("ç¬¬ä¸æ¹å¹³å°ç³»ç»ä¸æ¯æææªæä¾æ¥æº"); |
| | | } |
| | | JSONObject json = JSONUtil.parseObj(obj); |
| | | AuthRequest authRequest = AuthUtils.getAuthRequest(source, |
| | | json.getStr("clientId"), |
| | | json.getStr("clientSecret"), |
| | | json.getStr("redirectUri"), authStateCache); |
| | | AuthResponse<AuthUser> response = authRequest.login(callback); |
| | | return loginService.socialLogin(source, response, request); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * éåºç»å½ |
| | | */ |
| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhyd.oauth.model.AuthResponse; |
| | | import me.zhyd.oauth.model.AuthUser; |
| | | import org.dromara.common.core.constant.Constants; |
| | | import org.dromara.common.core.constant.GlobalConstants; |
| | | import org.dromara.common.core.constant.TenantConstants; |
| | | import org.dromara.common.core.domain.R; |
| | | import org.dromara.common.core.domain.dto.RoleDTO; |
| | | import org.dromara.common.core.domain.model.LoginUser; |
| | | import org.dromara.common.core.domain.model.XcxLoginUser; |
| | |
| | | import org.dromara.common.tenant.exception.TenantException; |
| | | import org.dromara.common.tenant.helper.TenantHelper; |
| | | import org.dromara.common.web.config.properties.CaptchaProperties; |
| | | import org.dromara.system.domain.SysAuthUser; |
| | | import org.dromara.system.domain.SysUser; |
| | | import org.dromara.system.domain.vo.SysTenantVo; |
| | | import org.dromara.system.domain.vo.SysUserVo; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | | import java.time.Duration; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | return StpUtil.getTokenValue(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * è®¤è¯ææç»å½ |
| | | * @param source |
| | | * @throws IOException |
| | | */ |
| | | /** |
| | | * 社交ç»å½ |
| | | * @param source ç»å½æ¥æº |
| | | * @param authUser ææååºå®ä½ |
| | | * @param request Http请æ±å¯¹è±¡ |
| | | * @return ç»ä¸ååºå®ä½ |
| | | * @throws IOException |
| | | */ |
| | | public R<String> socialLogin(String source, AuthResponse<AuthUser> authUser, HttpServletRequest request) throws IOException { |
| | | // 夿ææååºæ¯å¦æå |
| | | if (!authUser.ok()) { |
| | | return R.fail("对ä¸èµ·ï¼ææä¿¡æ¯éªè¯ä¸éè¿ï¼è¯·è系管çå"); |
| | | } |
| | | AuthUser authUserData = authUser.getData(); |
| | | // å¤ææ°æ®åºä¸æ¯å¦å·²åå¨è¯¥ç¨æ· |
| | | SysUserVo user = userMapper.selectAuthUserByUuid(source + authUserData.getUuid()); |
| | | if (ObjectUtil.isNotNull(user)) { |
| | | checkTenant(user.getTenantId()); |
| | | SysUserVo dbUser = loadUserByUsername(user.getTenantId(), user.getUserName()); |
| | | // ç»å½ |
| | | LoginHelper.loginByDevice(buildLoginUser(dbUser), DeviceType.auth); |
| | | recordLogininfor(dbUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); |
| | | recordLoginInfo(user.getUserId()); |
| | | return R.ok(StpUtil.getTokenValue()); |
| | | } else { |
| | | if (LoginHelper.getUserId() == null) { |
| | | return R.fail("ææå¤±è´¥ï¼è¯·å
ç»å½åç»å®"); |
| | | } |
| | | // ç»è£
ææç¨æ·ä¿¡æ¯ |
| | | SysAuthUser sysAuthUser = new SysAuthUser(); |
| | | sysAuthUser.setAvatar(authUserData.getAvatar()); |
| | | sysAuthUser.setUuid(source + authUserData.getUuid()); |
| | | sysAuthUser.setUserId(LoginHelper.getUserId()); |
| | | sysAuthUser.setUserName(authUserData.getUsername()); |
| | | sysAuthUser.setNickName(authUserData.getNickname()); |
| | | sysAuthUser.setEmail(authUserData.getEmail()); |
| | | sysAuthUser.setSource(source); |
| | | sysAuthUser.setCreateTime(new Date().toString()); |
| | | // æ°ç¨æ·ï¼ç»å®ç¬¬ä¸æ¹è´¦å· |
| | | userMapper.insertAuthUser(sysAuthUser); |
| | | SysUserVo lodingData = loadUserByUsername(LoginHelper.getTenantId(), LoginHelper.getUsername()); |
| | | checkTenant(lodingData.getTenantId()); |
| | | LoginHelper.loginByDevice(buildLoginUser(lodingData), DeviceType.auth); |
| | | recordLogininfor(lodingData.getTenantId(), sysAuthUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); |
| | | recordLoginInfo(sysAuthUser.getUserId()); |
| | | return R.ok(StpUtil.getTokenValue()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * éåºç»å½ |
| | | */ |
| | |
| | | |
| | | <modules> |
| | | <module>ruoyi-common-bom</module> |
| | | <module>ruoyi-common-auth</module> |
| | | <module>ruoyi-common-core</module> |
| | | <module>ruoyi-common-doc</module> |
| | | <module>ruoyi-common-excel</module> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <parent> |
| | | <groupId>org.dromara</groupId> |
| | | <artifactId>ruoyi-common</artifactId> |
| | | <version>${revision}</version> |
| | | <relativePath>../pom.xml</relativePath> |
| | | </parent> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | <artifactId>ruoyi-common-auth</artifactId> |
| | | <description> |
| | | ruoyi-common-auth è®¤è¯æ¨¡å |
| | | </description> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>me.zhyd.oauth</groupId> |
| | | <artifactId>JustAuth</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.common.auth.utils; |
| | | import me.zhyd.oauth.cache.AuthStateCache; |
| | | import me.zhyd.oauth.config.AuthConfig; |
| | | import me.zhyd.oauth.exception.AuthException; |
| | | import me.zhyd.oauth.request.*; |
| | | |
| | | /** |
| | | * è®¤è¯ææå·¥å
·ç±» |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class AuthUtils { |
| | | public static AuthRequest getAuthRequest(String source, String clientId, String clientSecret, String redirectUri, |
| | | AuthStateCache authStateCache) |
| | | { |
| | | AuthRequest authRequest = null; |
| | | switch (source.toLowerCase()) { |
| | | case "dingtalk" -> |
| | | authRequest = new AuthDingTalkRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "baidu" -> |
| | | authRequest = new AuthBaiduRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "github" -> |
| | | authRequest = new AuthGithubRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "gitee" -> |
| | | authRequest = new AuthGiteeRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "weibo" -> |
| | | authRequest = new AuthWeiboRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "coding" -> |
| | | authRequest = new AuthCodingRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).codingGroupName("").build(), authStateCache); |
| | | case "oschina" -> |
| | | authRequest = new AuthOschinaRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "alipay" -> |
| | | // æ¯ä»å®å¨å建åè°å°åæ¶ï¼ä¸å
许使ç¨localhostæè
127.0.0.1ï¼æä»¥è¿å¿çåè°å°å使ç¨çå±åç½å
çip |
| | | authRequest = new AuthAlipayRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .alipayPublicKey("").redirectUri(redirectUri).build(), authStateCache); |
| | | case "qq" -> |
| | | authRequest = new AuthQqRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "wechat_open" -> authRequest = new AuthWeChatOpenRequest(AuthConfig.builder().clientId(clientId) |
| | | .clientSecret(clientSecret).redirectUri(redirectUri).build(), authStateCache); |
| | | case "csdn" -> |
| | | authRequest = new AuthCsdnRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "taobao" -> |
| | | authRequest = new AuthTaobaoRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "douyin" -> |
| | | authRequest = new AuthDouyinRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "linkedin" -> |
| | | authRequest = new AuthLinkedinRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "microsoft" -> authRequest = new AuthMicrosoftRequest(AuthConfig.builder().clientId(clientId) |
| | | .clientSecret(clientSecret).redirectUri(redirectUri).build(), authStateCache); |
| | | case "mi" -> |
| | | authRequest = new AuthMiRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "toutiao" -> |
| | | authRequest = new AuthToutiaoRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "teambition" -> authRequest = new AuthTeambitionRequest(AuthConfig.builder().clientId(clientId) |
| | | .clientSecret(clientSecret).redirectUri(redirectUri).build(), authStateCache); |
| | | case "pinterest" -> authRequest = new AuthPinterestRequest(AuthConfig.builder().clientId(clientId) |
| | | .clientSecret(clientSecret).redirectUri(redirectUri).build(), authStateCache); |
| | | case "renren" -> |
| | | authRequest = new AuthRenrenRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "stack_overflow" -> authRequest = new AuthStackOverflowRequest(AuthConfig.builder().clientId(clientId) |
| | | .clientSecret(clientSecret).redirectUri(redirectUri).stackOverflowKey("").build(), |
| | | authStateCache); |
| | | case "huawei" -> |
| | | authRequest = new AuthHuaweiRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "wechat_enterprise" -> |
| | | authRequest = new AuthWeChatEnterpriseRequest(AuthConfig.builder().clientId(clientId) |
| | | .clientSecret(clientSecret).redirectUri(redirectUri).agentId("").build(), authStateCache); |
| | | case "kujiale" -> |
| | | authRequest = new AuthKujialeRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "gitlab" -> |
| | | authRequest = new AuthGitlabRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "meituan" -> |
| | | authRequest = new AuthMeituanRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "eleme" -> |
| | | authRequest = new AuthElemeRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build()); |
| | | case "wechat_mp" -> |
| | | authRequest = new AuthWeChatMpRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | case "aliyun" -> |
| | | authRequest = new AuthAliyunRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret) |
| | | .redirectUri(redirectUri).build(), authStateCache); |
| | | default -> { |
| | | } |
| | | } |
| | | if (null == authRequest) |
| | | { |
| | | throw new AuthException("æªè·åå°ææçAuthé
ç½®"); |
| | | } |
| | | return authRequest; |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * å°ç¨åºç«¯ |
| | | */ |
| | | XCX("xcx"); |
| | | XCX("xcx"), |
| | | |
| | | auth("auth"); |
| | | |
| | | private final String device; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.system.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | @TableName("sys_auth_user") |
| | | public class SysAuthUser { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ææID */ |
| | | private Long authId; |
| | | |
| | | /** ç¬¬ä¸æ¹å¹³å°ç¨æ·å¯ä¸ID */ |
| | | private String uuid; |
| | | |
| | | /** ç³»ç»ç¨æ·ID */ |
| | | private Long userId; |
| | | |
| | | /** ç»å½è´¦å· */ |
| | | private String userName; |
| | | |
| | | /** ç¨æ·æµç§° */ |
| | | private String nickName; |
| | | |
| | | /** 头åå°å */ |
| | | private String avatar; |
| | | |
| | | /** ç¨æ·é®ç®± */ |
| | | private String email; |
| | | |
| | | /** ç¨æ·æ¥æº */ |
| | | private String source; |
| | | |
| | | private String createTime; |
| | | |
| | | } |
| | |
| | | import org.dromara.common.mybatis.annotation.DataColumn; |
| | | import org.dromara.common.mybatis.annotation.DataPermission; |
| | | import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; |
| | | import org.dromara.system.domain.SysAuthUser; |
| | | import org.dromara.system.domain.SysUser; |
| | | import org.dromara.system.domain.vo.SysUserVo; |
| | | import org.apache.ibatis.annotations.Param; |
| | |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @DataPermission({ |
| | | @DataColumn(key = "deptName", value = "d.dept_id"), |
| | | @DataColumn(key = "userName", value = "u.user_id") |
| | | @DataColumn(key = "deptName", value = "d.dept_id"),// é¨é¨æé |
| | | @DataColumn(key = "userName", value = "u.user_id")// ç¨æ·æé |
| | | }) |
| | | SysUserVo selectUserById(Long userId); |
| | | |
| | |
| | | }) |
| | | int updateById(@Param(Constants.ENTITY) SysUser user); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·ç¼å·æ¥è¯¢ææå表 |
| | | * |
| | | * @param userId ç¨æ·ç¼å· |
| | | * @return ææå表 |
| | | */ |
| | | public List<SysAuthUser> selectAuthUserListByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®uuidæ¥è¯¢ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param uuid å¯ä¸ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public SysUserVo selectAuthUserByUuid(String uuid); |
| | | |
| | | /** |
| | | * æ ¡éªsource平尿¯å¦ç»å® |
| | | * |
| | | * @param userId ç¨æ·ç¼å· |
| | | * @param source ç»å®å¹³å° |
| | | * @return ç»æ |
| | | */ |
| | | public int checkAuthUser(@Param("userId") Long userId, @Param("source") String source); |
| | | |
| | | /** |
| | | * æ°å¢ç¬¬ä¸æ¹ææä¿¡æ¯ |
| | | * |
| | | * @param authUser ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertAuthUser(SysAuthUser authUser); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¼å·å é¤ç¬¬ä¸æ¹ææä¿¡æ¯ |
| | | * |
| | | * @param authId ææç¼å· |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteAuthUser(Long authId); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="org.dromara.system.mapper.SysUserMapper"> |
| | | |
| | | <resultMap id="SysAuthUserResult" type="org.dromara.system.domain.SysAuthUser"> |
| | | <id property="authId" column="auth_id" /> |
| | | <result property="uuid" column="uuid" /> |
| | | <result property="userId" column="user_id" /> |
| | | <result property="userName" column="user_name" /> |
| | | <result property="nickName" column="nick_name" /> |
| | | <result property="avatar" column="avatar" /> |
| | | <result property="email" column="email" /> |
| | | <result property="source" column="source" /> |
| | | <result property="createTime" column="create_time" /> |
| | | </resultMap> |
| | | |
| | | |
| | | <select id="selectAuthUserByUuid" parameterType="String" resultMap="SysUserResult"> |
| | | select b.user_id as user_id, b.user_name as user_name, b.password as password , a.tenant_id as tenant_id |
| | | from sys_auth_user a left join sys_user b on a.user_id = b.user_id |
| | | where a.uuid = #{uuid} and b.del_flag = '0' |
| | | </select> |
| | | |
| | | <select id="selectAuthUserListByUserId" parameterType="Long" resultMap="SysAuthUserResult"> |
| | | select auth_id, uuid, user_id, user_name, nick_name, avatar, email, source, create_time, tenant_id from sys_auth_user where user_id = #{userId} |
| | | </select> |
| | | |
| | | <select id="checkAuthUser" parameterType="org.dromara.system.domain.SysAuthUser" resultType="int"> |
| | | select count(1) from sys_auth_user where user_id=#{userId} and source=#{source} limit 1 |
| | | </select> |
| | | |
| | | <insert id="insertAuthUser" parameterType="org.dromara.system.domain.SysAuthUser"> |
| | | insert into sys_auth_user( |
| | | <if test="uuid != null and uuid != ''">uuid,</if> |
| | | <if test="userId != null and userId != 0">user_id,</if> |
| | | <if test="userName != null and userName != ''">user_name,</if> |
| | | <if test="nickName != null and nickName != ''">nick_name,</if> |
| | | <if test="avatar != null and avatar != ''">avatar,</if> |
| | | <if test="email != null and email != ''">email,</if> |
| | | <if test="source != null and source != ''">source,</if> |
| | | create_time |
| | | )values( |
| | | <if test="uuid != null and uuid != ''">#{uuid},</if> |
| | | <if test="userId != null and userId != 0">#{userId},</if> |
| | | <if test="userName != null and userName != ''">#{userName},</if> |
| | | <if test="nickName != null and nickName != ''">#{nickName},</if> |
| | | <if test="avatar != null and avatar != ''">#{avatar},</if> |
| | | <if test="email != null and email != ''">#{email},</if> |
| | | <if test="source != null and source != ''">#{source},</if> |
| | | now() |
| | | ) |
| | | </insert> |
| | | |
| | | <delete id="deleteAuthUser" parameterType="Long"> |
| | | delete from sys_auth_user where auth_id = #{authId} |
| | | </delete> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | CREATE TABLE `sys_auth_user` ( |
| | | `auth_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ææID', |
| | | `uuid` varchar(500) NOT NULL COMMENT 'ç¬¬ä¸æ¹å¹³å°ç¨æ·å¯ä¸ID', |
| | | `user_id` bigint(20) unsigned NOT NULL COMMENT 'ç³»ç»ç¨æ·ID', |
| | | `user_name` varchar(30) NOT NULL COMMENT 'ç»å½è´¦å·', |
| | | `nick_name` varchar(30) DEFAULT '' COMMENT 'ç¨æ·æµç§°', |
| | | `avatar` varchar(500) DEFAULT '' COMMENT '头åå°å', |
| | | `email` varchar(255) DEFAULT '' COMMENT 'ç¨æ·é®ç®±', |
| | | `source` varchar(255) DEFAULT '' COMMENT 'ç¨æ·æ¥æº', |
| | | ` tenant_id` varchar(20) DEFAULT '000000' COMMENT 'ç§æ·id', |
| | | `create_time` datetime DEFAULT NULL COMMENT 'å建æ¶é´', |
| | | `tenant_id` varchar(25) NOT NULL DEFAULT '000000', |
| | | PRIMARY KEY (`auth_id`) USING BTREE |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=102 DEFAULT CHARSET=utf8mb4 COMMENT='ç¬¬ä¸æ¹å¹³å°ææç¨æ·ä¿¡æ¯è¡¨'; |