Browse Source

fix 登陆

wenhongquan 3 years ago
parent
commit
f690c3920b

BIN
.gradle/7.2/executionHistory/executionHistory.lock


BIN
.gradle/7.2/fileHashes/fileHashes.lock


BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock


+ 1 - 1
.gradle/buildOutputCleanup/cache.properties

@@ -1,2 +1,2 @@
-#Sat Dec 25 00:51:00 CST 2021
+#Wed Apr 06 16:16:22 CST 2022
 gradle.version=7.3

+ 1 - 0
maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/support/basic/BasicEntryPoint.java

@@ -79,6 +79,7 @@ public class BasicEntryPoint implements   AsyncHandlerInterceptor {
 				 return true;
 			 }
 		 }
+
 		
 		// session not exists,session timeout,recreate new session
 		 if(request.getSession(false) == null) {

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/build.gradle

@@ -22,7 +22,7 @@ jib {
 	to {
 		//https://registry.hub.docker.com/repository/docker/maxkeytop/maxkey
 		image = "${jibToImage}_auth:v1.0"
-		tags = ["${project.version}".toString(), 'latest']
+//		tags = ["${project.version}".toString(), 'latest']
 		allowInsecureRegistries = true
 		auth {
 			username = "${jibToAuthUsername}"

+ 157 - 7
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/interceptor/PermissionAdapter.java

@@ -17,17 +17,28 @@
 
 package org.maxkey.web.interceptor;
 
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import javax.servlet.RequestDispatcher;
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
 
+import com.alibaba.fastjson.JSON;
+import org.maxkey.authn.AbstractAuthenticationProvider;
+import org.maxkey.authn.LoginCredential;
 import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
 import org.maxkey.authn.SigninPrincipal;
 import org.maxkey.authn.online.OnlineTicket;
 import org.maxkey.authn.online.OnlineTicketServices;
 import org.maxkey.configuration.ApplicationConfig;
+import org.maxkey.constants.ConstantsLoginType;
 import org.maxkey.constants.ConstantsPasswordSetType;
+import org.maxkey.constants.ConstantsTimeInterval;
+import org.maxkey.entity.UserInfo;
+import org.maxkey.persistence.redis.RedisConnection;
+import org.maxkey.persistence.redis.RedisConnectionFactory;
 import org.maxkey.web.WebConstants;
 import org.maxkey.web.WebContext;
 import org.slf4j.Logger;
@@ -40,6 +51,9 @@ import org.springframework.security.web.savedrequest.RequestCache;
 import org.springframework.security.web.savedrequest.SavedRequest;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.AsyncHandlerInterceptor;
+import org.springframework.web.servlet.ModelAndView;
+
+import static org.maxkey.web.WebContext.getRequest;
 
 /**
  * 权限Interceptor处理 权限处理需在servlet.xml中配置 mvc:interceptors permission
@@ -55,6 +69,14 @@ public class PermissionAdapter  implements AsyncHandlerInterceptor  {
     @Qualifier("applicationConfig")
     private ApplicationConfig applicationConfig;
 
+    @Autowired
+    @Qualifier("authenticationProvider")
+    AbstractAuthenticationProvider authenticationProvider;
+
+
+    @Autowired
+    RedisConnectionFactory redisConnectionFactory;
+
 
     @Autowired
     @Qualifier("savedRequestSuccessHandler")
@@ -74,14 +96,97 @@ public class PermissionAdapter  implements AsyncHandlerInterceptor  {
      * javax.servlet.http.HttpServletRequest,
      * javax.servlet.http.HttpServletResponse, java.lang.Object)
      */
+
+    @Override
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+        AsyncHandlerInterceptor.super.afterCompletion(request, response, handler, ex);
+
+    }
+
     @Override
     public boolean preHandle(HttpServletRequest request, 
             HttpServletResponse response, Object handler)
             throws Exception {
-        _logger.trace("PermissionAdapter preHandle");
-        _logger.trace("PermissionAdapter " + request.getSession().getId());
+        _logger.error("PermissionAdapter preHandle");
+        _logger.error("PermissionAdapter " + request.getSession().getId());
         Object passwordSetTypeAttribute=WebContext.getSession().getAttribute(WebConstants.CURRENT_USER_PASSWORD_SET_TYPE);
-        
+        ModifyHttpServletRequestWrapper mParametersWrapper = new ModifyHttpServletRequestWrapper(request);
+//        String token = request.getHeader("token");
+//        if (token != null && !"".equals(token)) {
+//            mParametersWrapper.putCookie("JSESSIONID", token);
+//        }
+
+        response.addHeader("P3P", "CP='CAO PSA OUR'");
+
+        _logger.error("-----------------------------");
+        _logger.error(request.getRequestURI());
+        _logger.error("-----------------------------");
+        String s = request.getParameter("sid");
+        if(s!=null){
+
+
+            try{
+                RedisConnection redisConnection = redisConnectionFactory.getConnection();
+                String userInfo1 = (String) redisConnection.get(s);
+                redisConnection.close();
+                _logger.error(userInfo1);
+                UserInfo userInfo = JSON.parseObject(userInfo1,UserInfo.class);
+                LoginCredential loginCredential = new LoginCredential(
+                        userInfo.getUsername(), "", ConstantsLoginType.JWT);
+
+                WebContext.setUserInfo(userInfo);
+                WebContext.setAuthentication(authenticationProvider.authentication(loginCredential, true));
+
+
+                Authentication authentication = WebContext.getAuthentication();
+                _logger.error(JSON.toJSONString(authentication));
+
+//                RequestCache requestCache = new HttpSessionRequestCache();
+//                requestCache.saveRequest(request, response);
+//                SavedRequest  savedRequest =requestCache.getRequest(request, response);
+//                WebContext.setAttribute(WebConstants.FIRST_SAVED_REQUEST_PARAMETER,savedRequest);
+
+
+            }catch (Exception e){
+
+               e.printStackTrace();
+            }
+
+
+
+
+//            mParametersWrapper.putCookie("JSESSIONID", s);
+//            _logger.error("-----------------------------");
+//            _logger.error(JSON.toJSONString(mParametersWrapper.getCookies()));
+//            _logger.error("-----------------------------");
+
+//            Cookie cookie=new Cookie("JSESSIONID",s);
+//            cookie.setPath("/");
+//            cookie.setHttpOnly(true);
+//            cookie.setDomain("wenhq.top");
+//            response.addCookie(cookie);
+//
+//            Cookie cookie1=new Cookie("JSESSIONID",s);
+//            cookie1.setPath("/taihu-auth");cookie1.setHttpOnly(true);
+//            cookie1.setDomain(request.getServerName());
+//            response.addCookie(cookie1);
+//
+//            Cookie cookie2=new Cookie("JSESSIONID",s);
+//            cookie2.setPath("/taihu-auth");
+//            cookie2.setDomain("thauth.xt.wenhq.top");cookie2.setHttpOnly(true);
+//            response.addCookie(cookie2);
+
+//            response.addHeader("Set-Cookie", "JSESSIONID="+s+"; Path=/taihu-auth;");
+
+
+
+
+//            WebContext.setCookie(response,null, "JSESSIONID", s, ConstantsTimeInterval.ONE_WEEK);
+//            WebContext.setCookie(response,"/taihu-auth", "JSESSIONID", s, ConstantsTimeInterval.ONE_WEEK);
+        }
+
+
+
         if(passwordSetTypeAttribute != null) {
             Integer passwordSetType=(Integer)passwordSetTypeAttribute;
             if(passwordSetType==ConstantsPasswordSetType.PASSWORD_EXPIRED||
@@ -91,7 +196,7 @@ public class PermissionAdapter  implements AsyncHandlerInterceptor  {
                     return true;
                 }
                 RequestDispatcher dispatcher = request.getRequestDispatcher("/safe/changeExpiredPassword");
-                dispatcher.forward(request, response);
+                dispatcher.forward(mParametersWrapper, response);
                 return false;
             }else if(passwordSetType==ConstantsPasswordSetType.INITIAL_PASSWORD){
                 _logger.trace("changeInitPassword ... forward to /safe/changeInitPassword");
@@ -99,7 +204,7 @@ public class PermissionAdapter  implements AsyncHandlerInterceptor  {
                     return true;
                 }
                 RequestDispatcher dispatcher = request.getRequestDispatcher("/safe/changeInitPassword");
-                dispatcher.forward(request, response);
+                dispatcher.forward(mParametersWrapper, response);
                 return false;
             }
         }
@@ -124,7 +229,7 @@ public class PermissionAdapter  implements AsyncHandlerInterceptor  {
             
             _logger.trace("No Authentication ... forward to /login");
             RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
-            dispatcher.forward(request, response);
+            dispatcher.forward(mParametersWrapper, response);
             return false;
         }
         
@@ -147,7 +252,7 @@ public class PermissionAdapter  implements AsyncHandlerInterceptor  {
         }catch(Exception e) {
             _logger.debug("Online Ticket timeout ... forward to /login");
         	RequestDispatcher dispatcher = request.getRequestDispatcher("/logout");
-        	dispatcher.forward(request, response); 
+        	dispatcher.forward(mParametersWrapper, response);
         }
         /*
          * boolean preHandler = super.preHandle(request, response, handler);
@@ -162,4 +267,49 @@ public class PermissionAdapter  implements AsyncHandlerInterceptor  {
          */
         return hasAccess;
     }
+
+    private class ModifyHttpServletRequestWrapper extends HttpServletRequestWrapper {
+        private Map<String, String> mapCookies;
+        ModifyHttpServletRequestWrapper(HttpServletRequest request) {
+            super(request);
+            this.mapCookies = new HashMap<>();
+        }
+        void putCookie(String name, String value) {
+            this.mapCookies.put(name, value);
+        }
+        public Cookie[] getCookies() {
+            HttpServletRequest request = (HttpServletRequest) getRequest();
+            Cookie[] cookies = request.getCookies();
+            if (mapCookies == null || mapCookies.isEmpty()) {
+                return cookies;
+            }
+            if (cookies == null || cookies.length == 0) {
+                List<Cookie> cookieList = new LinkedList<>();
+                for (Map.Entry<String, String> entry : mapCookies.entrySet()) {
+                    String key = entry.getKey();
+                    if (key != null && !"".equals(key)) {
+                        cookieList.add(new Cookie(key, entry.getValue()));
+                    }
+                }
+                if (cookieList.isEmpty()) {
+                    return cookies;
+                }
+                return cookieList.toArray(new Cookie[cookieList.size()]);
+            } else {
+                List<Cookie> cookieList = new ArrayList<>(Arrays.asList(cookies));
+                for (Map.Entry<String, String> entry : mapCookies.entrySet()) {
+                    String key = entry.getKey();
+                    if (key != null && !"".equals(key)) {
+                        for (int i = 0; i < cookieList.size(); i++) {
+                            if(cookieList.get(i).getName().equals(key)){
+                                cookieList.remove(i);
+                            }
+                        }
+                        cookieList.add(new Cookie(key, entry.getValue()));
+                    }
+                }
+                return cookieList.toArray(new Cookie[cookieList.size()]);
+            }
+        }
+    }
 }

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

@@ -252,7 +252,7 @@ maxkey.login.httpheader.headername            =header-user
 ############################################################################ 
 #BASIC Login support configuration                                         #
 ############################################################################
-maxkey.login.basic.enable                     =false
+maxkey.login.basic.enable                     =${LOGIN_BASIC_ENABLE:false}
 
 #############################################################################
 #WsFederation Login support configuration

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/src/main/resources/templates/views/authorize/authorize_footer.ftl

@@ -1,6 +1,6 @@
 
     <!-- footer -->
- 	<div class="container" >
+ 	<div class="container" style="display: none">
 	    <div class="row">
 	    	<div class="col-sm-4"></div>
 	    	<div class="col-sm-4">

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/src/main/resources/templates/views/layout/footer.ftl

@@ -1,6 +1,6 @@
 
     <!-- footer -->
- 	<div class="container" >
+ 	<div class="container" style="display: none">
 	    <div class="row">
 	    	<div class="col-sm-4"></div>
 	    	<div class="col-sm-4">

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/src/main/resources/templates/views/layout/nav_primary.ftl

@@ -1,5 +1,5 @@
 
-<div id="nav_primary" >
+<div id="nav_primary"  style="display: none">
 <div  class="container row">
 	<div class="col-sm-8">
 		<ul class="navMenu">

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/src/main/resources/templates/views/layout/top.ftl

@@ -1,5 +1,5 @@
 
-<div id="topBar"  > 
+<div id="topBar" style="display: none" >
     <div class="container row">
     	<div class="col-sm-5">
     		<div>

+ 2 - 2
maxkey-webs/maxkey-web-mgt/src/main/resources/templates/views/layout/footer.ftl

@@ -1,7 +1,7 @@
 
     <!-- footer -->
-    <div class="container">
-       <div class="row footer" style="margin-top: 30px;width:100%;height:100%;">
+    <div class="container" style="display: none">
+       <div class="row footer" style="margin-top: 30px;width:100%;height:100%;display: none">
             <div class="col-sm-4"></div>
             <div class="col-sm-4">
     		    <table cellpadding="2" cellspacing="0" style="border:0;">

+ 1 - 1
maxkey-webs/maxkey-web-resources/src/main/resources/static/css/base.css

@@ -83,7 +83,7 @@ body{
 
 #footer{
 	text-shadow: 0 1px 0 #fff;
-	border-top: 1px solid #e5e5e5;
+	/*border-top: 1px solid #e5e5e5;*/
 	min-width: 100%;
 	height:80px;
 	margin-top: 5px;

+ 1 - 1
maxkey-webs/maxkey-web-resources/src/main/resources/static/css_mgt/base.css

@@ -285,7 +285,7 @@ header .header-container .nav-left>li, .header .header-container .nav-right>li {
 
 #footer{
 	text-shadow: 0 1px 0 #fff;
-	border-top: 1px solid #e5e5e5;
+	/*border-top: 1px solid #e5e5e5;*/
 	min-width: 100%;
 	height:80px;
 	

+ 12 - 1
maxkey-webs/maxkey-web-resources/src/main/resources/static/javascript/login.js

@@ -29,6 +29,17 @@ $(function(){
     $(".doLoginSubmit").on("click",function(){
             doLoginSubmit();
     });
+
+    // window.addEventListener('message', (e) => {
+    //     // console.log(e.data);
+    //     setCookie("JSESSIONID",e.data,20*1000);
+    // }, false);
+
+    // var JSESSIONID = getUrlParamValue("sid");
+    // $.removeCookie("JSESSIONID");
+    // setCookie("JSESSIONID",JSESSIONID,20*1000);
+    // console.error(JSESSIONID);
+    // location.reload();
     var cookieLoginUsername = $.cookie("mxk_login_username");
     if(cookieLoginUsername != undefined && cookieLoginUsername != ""){
         var switch_tab=$.cookie("mxk_login_switch_tab")==undefined ? "normalLogin" : $.cookie("mxk_login_switch_tab");
@@ -50,4 +61,4 @@ $(function(){
         countDownTimer=setInterval("doCountDownTimer()", 1000);
     });
     
-});
+});

+ 35 - 1
maxkey-webs/maxkey-web-resources/src/main/resources/static/javascript/platform.common.js

@@ -13,6 +13,13 @@ function dataGridQueryParams(params) {
 
  //jquery begin
 $(function(){
+
+
+	// var JSESSIONID = getUrlParamValue("sid");
+	// $.removeCookie("JSESSIONID");
+	// setCookie("JSESSIONID",JSESSIONID,20*1000);
+
+
 	$.datetimepicker.setLocale(webLocale.substring(0, 2));
 	$(".datetimepicker").datetimepicker({format:'Y-m-d H:i'});
 	$(".datepicker").datetimepicker({timepicker:false,format:'Y-m-d'});
@@ -727,4 +734,31 @@ $(function(){
 	    		}
 	    	);
 		};//end tree
-});//jquery end
+});//jquery end
+
+
+function setCookie(c_name, value, expiredays) {
+	var exdate = new Date();
+	exdate.setTime(Number(exdate) + expiredays);
+	document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
+}
+
+function getUrlParamValue(name) {
+
+	if (name == null || name == 'undefined') {return null; }
+
+	var searchStr = decodeURI(location.search);
+
+	var infoIndex = searchStr.indexOf(name + "=");
+
+	if (infoIndex == -1) { return null; }
+
+	var searchInfo = searchStr.substring(infoIndex + name.length + 1);
+
+	var tagIndex = searchInfo.indexOf("&");
+
+	if (tagIndex != -1) { searchInfo = searchInfo.substring(0, tagIndex); }
+
+	return searchInfo;
+
+};