|
@@ -16,14 +16,17 @@ import org.maxkey.authn.support.jwt.JwtLoginService;
|
|
|
import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
|
|
|
import org.maxkey.authn.support.socialsignon.service.SocialsAssociateService;
|
|
|
import org.maxkey.authz.cas.endpoint.ticket.generator.DefaultUniqueTicketIdGenerator;
|
|
|
-import org.maxkey.entity.Organizations;
|
|
|
-import org.maxkey.entity.SocialsProvider;
|
|
|
-import org.maxkey.entity.UserInfo;
|
|
|
+import org.maxkey.constants.ConstantsLoginType;
|
|
|
+import org.maxkey.entity.*;
|
|
|
+import org.maxkey.persistence.db.LoginHistoryService;
|
|
|
import org.maxkey.persistence.redis.RedisConnection;
|
|
|
import org.maxkey.persistence.redis.RedisConnectionFactory;
|
|
|
+import org.maxkey.persistence.service.HistorySystemLogsService;
|
|
|
import org.maxkey.persistence.service.OrganizationsService;
|
|
|
import org.maxkey.persistence.service.UserInfoService;
|
|
|
+import org.maxkey.util.JsonUtils;
|
|
|
import org.maxkey.util.RetCode;
|
|
|
+import org.maxkey.web.WebContext;
|
|
|
import org.maxkey.web.component.TreeNode;
|
|
|
import org.maxkey.web.component.TreeNodeList;
|
|
|
import org.maxkey.web.endpoint.LoginEndpoint;
|
|
@@ -79,6 +82,9 @@ public class ThirdLoginController
|
|
|
@Autowired
|
|
|
RedisConnectionFactory redisConnectionFactory;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ LoginHistoryService loginHistoryService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* init login
|
|
@@ -87,7 +93,7 @@ public class ThirdLoginController
|
|
|
*/
|
|
|
@ApiOperation(value = "登录接口", notes = "用户登录地址", httpMethod = "GET")
|
|
|
@RequestMapping(value = {"/login"})
|
|
|
- public RetResult login(@RequestParam("username") String username, @RequestParam("password") String password)
|
|
|
+ public RetResult login(@RequestParam("username") String username, @RequestParam("password") String password, HttpServletRequest request)
|
|
|
{
|
|
|
RetResult result = new RetResult();
|
|
|
Map<String, Object> data = new HashMap<String, Object>();
|
|
@@ -118,6 +124,9 @@ public class ThirdLoginController
|
|
|
_logger.debug("token >>>" + token);
|
|
|
result.setData(data);
|
|
|
result.setCode(RetCode.SUCCESS);
|
|
|
+ // 登录
|
|
|
+ loginHistoryService.login(userInfo, WebContext.genId(), ConstantsLoginType.JWT, "", "", "", "", "", 1);
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -145,13 +154,15 @@ public class ThirdLoginController
|
|
|
// 1天
|
|
|
RedisConnection redisConnection = redisConnectionFactory.getConnection();
|
|
|
String userInfo = redisConnection.get(token);
|
|
|
+ if (StringUtils.isEmpty(userInfo))
|
|
|
+ {
|
|
|
+ return new RetResult().setMsg("请求失败,token无效").setData(null).setCode(RetCode.SUCCESS);
|
|
|
+ }
|
|
|
Jackson2JsonRedisSerializer<UserInfo> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<UserInfo>(UserInfo.class);
|
|
|
UserInfo user = JSONObject.parseObject(userInfo, UserInfo.class);
|
|
|
result.put("token", token);
|
|
|
result.put("userInfo", user);
|
|
|
- if(user==null){
|
|
|
- return new RetResult().setMsg("请求失败,token无效").setData(null).setCode(RetCode.SUCCESS);
|
|
|
- }
|
|
|
+
|
|
|
redisConnection.setex(ticket, 60 * 60 * 24 * 1, result.toString());
|
|
|
redisConnection.close();
|
|
|
result = new JSONObject();
|
|
@@ -179,6 +190,7 @@ public class ThirdLoginController
|
|
|
JSONObject userObject = JSONObject.parseObject(userInfo);
|
|
|
result.put("userInfo", JSONObject.toJSONString(userObject.get("userInfo")));
|
|
|
result.put("token", userObject.getString("token"));
|
|
|
+ result.put("sessionId", request.getSession().getId());
|
|
|
redisConnection.close();
|
|
|
return new RetResult().setMsg("请求成功").setData(result).setCode(RetCode.SUCCESS);
|
|
|
}
|