Jelajahi Sumber

钉钉登录和用户名密码登录返回sessionid

vincent 3 tahun lalu
induk
melakukan
785053aeb5

+ 4 - 3
maxkey-authentications/maxkey-authentication-social/src/main/java/org/maxkey/authn/support/socialsignon/SocialSignOnEndpoint.java

@@ -295,7 +295,8 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint
             socialsAssociate.setProvider(provider);
             socialsAssociate.setSocialUserId(this.accountId);
 
-
+            //设定是登录
+            WebContext.setAttribute(SOCIALSIGNON_TYPE_SESSION,"socialsignon_type_logon");
             //for login
             String socialSignOnType =
                     (WebContext.getAttribute(SOCIALSIGNON_TYPE_SESSION) != null) ?
@@ -359,10 +360,10 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint
                 redisConnection.setex(ticket, 60 * 60 * 24 * 1, result.toJSONString());
                 redisConnection.close();
                 _logger.debug("token >>>" + token);
-
+                 // 拼接 sessionid
                 loginHistoryService.login(userInfo,WebContext.genId(), ConstantsLoginType.JWT,"","",provider,"","",1);
                 // TODO  整合前端的地址
-                return WebContext.redirect(curl + ticket);
+                return WebContext.redirect(curl + ticket + "&sessionId="+ WebContext.getSession().getId());
             } else
             {
                 socialBind(socialsAssociate);

+ 10 - 2
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ThirdLoginController.java

@@ -11,6 +11,7 @@ import com.nimbusds.jwt.SignedJWT;
 import com.taobao.api.ApiException;
 import io.swagger.annotations.ApiOperation;
 import org.maxkey.authn.AbstractAuthenticationProvider;
+import org.maxkey.authn.LoginCredential;
 import org.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
 import org.maxkey.authn.support.jwt.JwtLoginService;
 import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
@@ -26,6 +27,7 @@ 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.WebConstants;
 import org.maxkey.web.WebContext;
 import org.maxkey.web.component.TreeNode;
 import org.maxkey.web.component.TreeNodeList;
@@ -123,11 +125,17 @@ public class ThirdLoginController
             redisConnection.setex(token, 60 * 60 * 24 * 7, JSON.toJSONString(userInfo));
             redisConnection.close();
             _logger.debug("token >>>" + token);
-            result.setData(data);
-            result.setCode(RetCode.SUCCESS);
+
             // 登录
+            // 认证信息
+            LoginCredential loginCredential = new LoginCredential(
+                    userInfo.getUsername(), "", ConstantsLoginType.SOCIALSIGNON);
+            authenticationProvider.authentication(loginCredential, true);
+            data.put("sessionId", request.getSession().getId());
             loginHistoryService.login(userInfo, WebContext.genId(), ConstantsLoginType.JWT, "success", "", "", "", "", 1);
 
+            result.setData(data);
+            result.setCode(RetCode.SUCCESS);
             return result;
         }
 

+ 2 - 2
maxkey-webs/maxkey-web-maxkey/src/main/resources/application-http.properties

@@ -122,8 +122,8 @@ mybatis.table-column-case                       =lowercase
 ############################################################################
 #redis server  configuration                                               #
 ############################################################################
-spring.redis.host                               =${REDIS_HOST:61.132.52.38}
-spring.redis.port                               =${REDIS_PORT:20003}
+spring.redis.host                               =${REDIS_HOST:127.0.0.1}
+spring.redis.port                               =${REDIS_PORT:6379}
 spring.redis.password                           =${REDIS_PWD:password}
 spring.redis.timeout                            =10000
 spring.redis.jedis.pool.max-wait                =1000