| @@ -0,0 +1,15 @@ | |||||
| package com.ruoyi.system.api; | |||||
| import com.ruoyi.common.core.constant.ServiceNameConstants; | |||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||||
| import com.ruoyi.system.api.factory.RemoteMmpFallbackFactory; | |||||
| import org.springframework.cloud.openfeign.FeignClient; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.RequestParam; | |||||
| @FeignClient(contextId = "remoteMmpService", value = ServiceNameConstants.MANAGEMENT_SERVICE, fallbackFactory = RemoteMmpFallbackFactory.class) | |||||
| public interface RemoteMmpService { | |||||
| @GetMapping("/gitLink/login") | |||||
| public GenericsAjaxResult<String> gitLinkLogin(@RequestParam("ci4sUsername") String ci4sUsername, @RequestParam("username") String username, @RequestParam("password") String password); | |||||
| } | |||||
| @@ -0,0 +1,25 @@ | |||||
| package com.ruoyi.system.api.factory; | |||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||||
| import com.ruoyi.system.api.RemoteMmpService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.cloud.openfeign.FallbackFactory; | |||||
| import org.springframework.stereotype.Component; | |||||
| @Component | |||||
| public class RemoteMmpFallbackFactory implements FallbackFactory<RemoteMmpService> { | |||||
| private static final Logger log = LoggerFactory.getLogger(RemoteMmpFallbackFactory.class); | |||||
| @Override | |||||
| public RemoteMmpService create(Throwable throwable) { | |||||
| log.error("管理平台服务调用失败:{}", throwable.getMessage()); | |||||
| return new RemoteMmpService() { | |||||
| @Override | |||||
| public GenericsAjaxResult<String> gitLinkLogin(String ci4sUsername, String username, String password) { | |||||
| return GenericsAjaxResult.error("刷新gitLink登录信息失败"); | |||||
| } | |||||
| }; | |||||
| } | |||||
| } | |||||
| @@ -1,3 +1,4 @@ | |||||
| com.ruoyi.system.api.factory.RemoteUserFallbackFactory | com.ruoyi.system.api.factory.RemoteUserFallbackFactory | ||||
| com.ruoyi.system.api.factory.RemoteLogFallbackFactory | com.ruoyi.system.api.factory.RemoteLogFallbackFactory | ||||
| com.ruoyi.system.api.factory.RemoteFileFallbackFactory | com.ruoyi.system.api.factory.RemoteFileFallbackFactory | ||||
| com.ruoyi.system.api.factory.RemoteMmpFallbackFactory | |||||
| @@ -1,6 +1,7 @@ | |||||
| package com.ruoyi.auth.service; | package com.ruoyi.auth.service; | ||||
| import com.ruoyi.auth.form.AccessTokenVo; | import com.ruoyi.auth.form.AccessTokenVo; | ||||
| import com.ruoyi.system.api.RemoteMmpService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| import com.ruoyi.common.core.constant.CacheConstants; | import com.ruoyi.common.core.constant.CacheConstants; | ||||
| @@ -39,6 +40,8 @@ public class SysLoginService | |||||
| @Autowired | @Autowired | ||||
| private RedisService redisService; | private RedisService redisService; | ||||
| @Autowired | |||||
| private RemoteMmpService remoteMmpService; | |||||
| /** | /** | ||||
| * 登录 | * 登录 | ||||
| */ | */ | ||||
| @@ -99,6 +102,7 @@ public class SysLoginService | |||||
| } | } | ||||
| passwordService.validate(user, password); | passwordService.validate(user, password); | ||||
| recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); | recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); | ||||
| remoteMmpService.gitLinkLogin(username, user.getGitLinkUsername(),user.getGitLinkPassword()); | |||||
| return userInfo; | return userInfo; | ||||
| } | } | ||||
| @@ -21,4 +21,6 @@ public class ServiceNameConstants | |||||
| * 文件服务的serviceid | * 文件服务的serviceid | ||||
| */ | */ | ||||
| public static final String FILE_SERVICE = "ruoyi-file"; | public static final String FILE_SERVICE = "ruoyi-file"; | ||||
| public static final String MANAGEMENT_SERVICE = "management-platform"; | |||||
| } | } | ||||
| @@ -0,0 +1,28 @@ | |||||
| package com.ruoyi.platform.controller.git; | |||||
| import com.ruoyi.common.core.web.controller.BaseController; | |||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||||
| import com.ruoyi.platform.service.GitService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| 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; | |||||
| @RestController | |||||
| @RequestMapping("gitLink") | |||||
| @Api("gitLink") | |||||
| public class GitLinkController extends BaseController { | |||||
| @Resource | |||||
| private GitService gitService; | |||||
| @GetMapping("/login") | |||||
| @ApiOperation("刷新giotLink用户信息") | |||||
| public GenericsAjaxResult<String> gitLinkLogin(@RequestParam("ci4sUsername") String ci4sUsername, @RequestParam("username") String username, @RequestParam("password") String password) { | |||||
| return genericsSuccess(gitService.login(ci4sUsername, username, password)); | |||||
| } | |||||
| } | |||||
| @@ -8,7 +8,7 @@ import java.util.Map; | |||||
| public interface GitService { | public interface GitService { | ||||
| //登录方法,返回token | //登录方法,返回token | ||||
| String login(String username, String password); | |||||
| String login(String ci4sUsername, String username, String password); | |||||
| String checkoutToken(); | String checkoutToken(); | ||||
| @@ -39,12 +39,12 @@ public class GitServiceImpl implements GitService { | |||||
| private static final Logger log = LoggerFactory.getLogger(GitServiceImpl.class); | private static final Logger log = LoggerFactory.getLogger(GitServiceImpl.class); | ||||
| @Override | @Override | ||||
| public String login(String username, String password) { | |||||
| public String login(String ci4sUsername, String username, String password) { | |||||
| // 构建请求参数 | // 构建请求参数 | ||||
| Map<String, Object> params = new HashMap<>(); | Map<String, Object> params = new HashMap<>(); | ||||
| params.put("grant_type", "password"); | params.put("grant_type", "password"); | ||||
| params.put("username", username); | params.put("username", username); | ||||
| params.put("password", password); | |||||
| params.put("password", decrypt(password)); | |||||
| params.put("client_id", "jEdGwrIJixCUIJM9vj2MwA6zmoTVhUdXxiSAaaCiXwA"); | params.put("client_id", "jEdGwrIJixCUIJM9vj2MwA6zmoTVhUdXxiSAaaCiXwA"); | ||||
| params.put("client_secret", "L3wBKTNnRo-wPen7bxR3F1myCvtVDgpWa6MnpfyWeJE"); | params.put("client_secret", "L3wBKTNnRo-wPen7bxR3F1myCvtVDgpWa6MnpfyWeJE"); | ||||
| try { | try { | ||||
| @@ -65,8 +65,6 @@ public class GitServiceImpl implements GitService { | |||||
| if (StringUtils.isEmpty(userReq)) { | if (StringUtils.isEmpty(userReq)) { | ||||
| throw new RuntimeException("gitlink用户信息出错"); | throw new RuntimeException("gitlink用户信息出错"); | ||||
| } | } | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||||
| String ci4sUsername = loginUser.getUsername(); | |||||
| // 将access_token存入Redis | // 将access_token存入Redis | ||||
| Jedis jedis = new Jedis(redisHost, redisPort); | Jedis jedis = new Jedis(redisHost, redisPort); | ||||
| jedis.set(ci4sUsername + "_gitToken", accessToken); | jedis.set(ci4sUsername + "_gitToken", accessToken); | ||||
| @@ -83,16 +81,16 @@ public class GitServiceImpl implements GitService { | |||||
| String ci4sUsername = loginUser.getUsername(); | String ci4sUsername = loginUser.getUsername(); | ||||
| String token = jedis.get(ci4sUsername + "_gitToken"); | String token = jedis.get(ci4sUsername + "_gitToken"); | ||||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | ||||
| String gitLinkPassword = decrypt(loginUser.getSysUser().getGitLinkPassword()); | |||||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||||
| if (StringUtils.isEmpty(token)) { | if (StringUtils.isEmpty(token)) { | ||||
| login(gitLinkUsername, gitLinkPassword); | |||||
| login(ci4sUsername, gitLinkUsername, gitLinkPassword); | |||||
| token = jedis.get(ci4sUsername + "_gitToken"); | token = jedis.get(ci4sUsername + "_gitToken"); | ||||
| } else { | } else { | ||||
| try { | try { | ||||
| Map userInfo = getUserInfo(token); | Map userInfo = getUserInfo(token); | ||||
| if (userInfo == null || (userInfo.get("status") != null && 401 == (Integer) userInfo.get("status"))) { | if (userInfo == null || (userInfo.get("status") != null && 401 == (Integer) userInfo.get("status"))) { | ||||
| login(gitLinkUsername, gitLinkPassword); | |||||
| login(ci4sUsername, gitLinkUsername, gitLinkPassword); | |||||
| token = jedis.get(ci4sUsername + "_gitToken"); | token = jedis.get(ci4sUsername + "_gitToken"); | ||||
| } | } | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| @@ -561,7 +561,7 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String ci4sUsername = loginUser.getUsername(); | String ci4sUsername = loginUser.getUsername(); | ||||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | ||||
| String gitLinkPassword = decrypt(loginUser.getSysUser().getGitLinkPassword()); | |||||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | ||||
| Integer userId = (Integer) userInfo.get("user_id"); | Integer userId = (Integer) userInfo.get("user_id"); | ||||
| @@ -687,7 +687,7 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String ci4sUsername = loginUser.getUsername(); | String ci4sUsername = loginUser.getUsername(); | ||||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | ||||
| String gitLinkPassword = decrypt(loginUser.getSysUser().getGitLinkPassword()); | |||||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | ||||
| ci4sUsername = Boolean.TRUE.equals(modelsVo.getIsPublic()) ? Constant.Item_Public : loginUser.getUsername(); | ci4sUsername = Boolean.TRUE.equals(modelsVo.getIsPublic()) ? Constant.Item_Public : loginUser.getUsername(); | ||||
| @@ -922,7 +922,7 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String ci4sUsername = loginUser.getUsername(); | String ci4sUsername = loginUser.getUsername(); | ||||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | ||||
| String gitLinkPassword = decrypt(loginUser.getSysUser().getGitLinkPassword()); | |||||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | ||||
| String token = (String) userInfo.get("token"); | String token = (String) userInfo.get("token"); | ||||
| @@ -952,7 +952,7 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String ci4sUsername = loginUser.getUsername(); | String ci4sUsername = loginUser.getUsername(); | ||||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | ||||
| String gitLinkPassword = decrypt(loginUser.getSysUser().getGitLinkPassword()); | |||||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword); | ||||
| String token = (String) userInfo.get("token"); | String token = (String) userInfo.get("token"); | ||||
| @@ -1326,7 +1326,7 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| Jedis jedis = new Jedis(redisHost, redisPort); | Jedis jedis = new Jedis(redisHost, redisPort); | ||||
| String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); | String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); | ||||
| if (userReq == null) { | if (userReq == null) { | ||||
| gitService.login(gitLinkUsername, gitLinkPassword); | |||||
| gitService.login(ci4sUsername, gitLinkUsername, gitLinkPassword); | |||||
| userReq = jedis.get(ci4sUsername + "_gitUserInfo"); | userReq = jedis.get(ci4sUsername + "_gitUserInfo"); | ||||
| } | } | ||||
| Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); | Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); | ||||