From bb385604ea660c15303a0e8485a06d01fa374c8d Mon Sep 17 00:00:00 2001 From: lidongy <1879087903@qq.com> Date: Fri, 25 Oct 2019 10:33:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?KERNEL-1444=20=E5=8A=A0=E5=87=A0=E4=B8=AA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lidongy <1879087903@qq.com> --- .../fanruan/api/decision/AppearanceKit.java | 20 +++++++ .../api/decision/webservice/Response.java | 11 ++++ .../decision/webservice/WebServiceKit.java | 25 +++++++++ .../api/decision/AppearenceKitTest.java | 43 +++++++++++++++ .../api/decision/webservice/ResponseTest.java | 26 +++++++++ .../webservice/WebServiceKitTest.java | 54 +++++++++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 src/main/java/com/fanruan/api/decision/AppearanceKit.java create mode 100644 src/main/java/com/fanruan/api/decision/webservice/Response.java create mode 100644 src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java create mode 100644 src/test/java/com/fanruan/api/decision/AppearenceKitTest.java create mode 100644 src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java create mode 100644 src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java diff --git a/src/main/java/com/fanruan/api/decision/AppearanceKit.java b/src/main/java/com/fanruan/api/decision/AppearanceKit.java new file mode 100644 index 0000000..9e106b1 --- /dev/null +++ b/src/main/java/com/fanruan/api/decision/AppearanceKit.java @@ -0,0 +1,20 @@ +package com.fanruan.api.decision; + +import com.fr.decision.config.AppearanceConfig; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/24 + */ +public class AppearanceKit { + + /** + * 获取选择的登录页插件id + * + * @return id + */ + public static String getLoginPageId() { + return AppearanceConfig.getInstance().getLoginPageId(); + } +} diff --git a/src/main/java/com/fanruan/api/decision/webservice/Response.java b/src/main/java/com/fanruan/api/decision/webservice/Response.java new file mode 100644 index 0000000..6d88acc --- /dev/null +++ b/src/main/java/com/fanruan/api/decision/webservice/Response.java @@ -0,0 +1,11 @@ +package com.fanruan.api.decision.webservice; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/24 + */ +public class Response extends com.fr.decision.webservice.Response { + public Response() { + } +} diff --git a/src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java b/src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java new file mode 100644 index 0000000..c10a93d --- /dev/null +++ b/src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java @@ -0,0 +1,25 @@ +package com.fanruan.api.decision.webservice; + +import com.fr.decision.webservice.v10.login.LoginService; +import com.fr.third.socketio.SocketIOClient; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/24 + */ +public class WebServiceKit { + + /** + * 刷新用户名对应的token,如果非保持登录,会使用tokenTimeout参数设置时长 + * + * @param oldJwt 老的token + * @param socketIOClient socket客户端 + * @param tokenTimeout 设置的超时时长,仅对非保持登录有用,0<= tokenTimeOut <= LoginConfig.LoginTimeOut + * @return 新的token + * @throws Exception 异常 + */ + public static Response refreshToken(String oldJwt, long tokenTimeout, SocketIOClient socketIOClient) throws Exception{ + return (Response) LoginService.getInstance().refreshToken(oldJwt, tokenTimeout, socketIOClient); + } +} diff --git a/src/test/java/com/fanruan/api/decision/AppearenceKitTest.java b/src/test/java/com/fanruan/api/decision/AppearenceKitTest.java new file mode 100644 index 0000000..8a66f3c --- /dev/null +++ b/src/test/java/com/fanruan/api/decision/AppearenceKitTest.java @@ -0,0 +1,43 @@ +package com.fanruan.api.decision; + +import com.fr.config.dao.DaoContext; +import com.fr.config.dao.impl.LocalClassHelperDao; +import com.fr.config.dao.impl.LocalEntityDao; +import com.fr.config.dao.impl.LocalXmlEntityDao; +import com.fr.decision.config.AppearanceConfig; +import com.fr.runtime.FineRuntime; +import com.fr.store.StateHubManager; +import com.fr.store.impl.MemoryLock; +import com.fr.store.impl.MemoryStore; +import com.fr.transaction.Configurations; +import com.fr.transaction.LocalConfigurationHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/24 + */ +public class AppearenceKitTest { + @Before + public void start() { + FineRuntime.start(); + DaoContext.setEntityDao(new LocalEntityDao()); + DaoContext.setClassHelperDao(new LocalClassHelperDao()); + DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + Configurations.setHelper(new LocalConfigurationHelper()); + StateHubManager.setStorage(new MemoryStore()); + StateHubManager.setLock(new MemoryLock()); + } + + @Test + public void TestGetLoginPageId() { + AppearanceConfig.getInstance().setLoginPageId("111"); + Assert.assertEquals(AppearanceKit.getLoginPageId(), "111"); + + AppearanceConfig.getInstance().setLoginPageId("aaa"); + Assert.assertEquals(AppearanceKit.getLoginPageId(), "aaa"); + } +} diff --git a/src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java b/src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java new file mode 100644 index 0000000..214ece9 --- /dev/null +++ b/src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java @@ -0,0 +1,26 @@ +package com.fanruan.api.decision.webservice; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/25 + */ +public class ResponseTest { + @Test + public void testResponse() throws Exception{ + Response response = new Response(); + + response.setData("data"); + response.setErrorCode("404"); + response.setErrorMsg("fail to connect"); + response.setStatus(3); + + Assert.assertEquals(response.getData(), "data"); + Assert.assertEquals(response.getErrorCode(), "404"); + Assert.assertEquals(response.getErrorMsg(), "fail to connect"); + Assert.assertEquals(response.getStatus(), 3); + } +} diff --git a/src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java b/src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java new file mode 100644 index 0000000..56ebbbd --- /dev/null +++ b/src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java @@ -0,0 +1,54 @@ +package com.fanruan.api.decision.webservice; + +import com.fanruan.api.security.JwtKit; +import com.fr.config.dao.DaoContext; +import com.fr.config.dao.impl.LocalClassHelperDao; +import com.fr.config.dao.impl.LocalEntityDao; +import com.fr.config.dao.impl.LocalXmlEntityDao; +import com.fr.decision.webservice.bean.authentication.LoginClientBean; +import com.fr.decision.webservice.exception.login.LoginInfoNotAvailableException; +import com.fr.decision.webservice.utils.DecisionStatusService; +import com.fr.runtime.FineRuntime; +import com.fr.store.StateHubManager; +import com.fr.store.impl.MemoryLock; +import com.fr.store.impl.MemoryStore; +import com.fr.transaction.Configurations; +import com.fr.transaction.LocalConfigurationHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/24 + */ +public class WebServiceKitTest { + + @Before + public void start() { + FineRuntime.start(); + DaoContext.setEntityDao(new LocalEntityDao()); + DaoContext.setClassHelperDao(new LocalClassHelperDao()); + DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + Configurations.setHelper(new LocalConfigurationHelper()); + StateHubManager.setStorage(new MemoryStore()); + StateHubManager.setLock(new MemoryLock()); + } + @Test + public void testRefreshToken() throws Exception{ + String jwtString = JwtKit.createDefaultJWT("123"); + try { + Response response = WebServiceKit.refreshToken(jwtString, 1000 * 60, null); + } catch (Exception e) { + Assert.assertTrue(e instanceof LoginInfoNotAvailableException); + } + LoginClientBean loginClientBean = new LoginClientBean(); + DecisionStatusService.loginStatusService().put(jwtString, loginClientBean); + try { + Response response = WebServiceKit.refreshToken(jwtString, 1000 * 60, null); + } catch (Exception e) { + Assert.assertFalse(e instanceof LoginInfoNotAvailableException); + } + } +} From f2ccbba2aa70029b5f14803923c06f34f580b33b Mon Sep 17 00:00:00 2001 From: lidongy <1879087903@qq.com> Date: Fri, 25 Oct 2019 11:21:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=94=B9=E5=88=B0loginkit=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lidongy <1879087903@qq.com> --- .../fanruan/api/decision/AppearanceKit.java | 20 ------- .../fanruan/api/decision/login/LoginKit.java | 30 +++++++++++ .../api/decision/webservice/Response.java | 11 ---- .../decision/webservice/WebServiceKit.java | 25 --------- .../api/decision/AppearenceKitTest.java | 43 --------------- .../api/decision/webservice/ResponseTest.java | 26 --------- .../webservice/WebServiceKitTest.java | 54 ------------------- 7 files changed, 30 insertions(+), 179 deletions(-) delete mode 100644 src/main/java/com/fanruan/api/decision/AppearanceKit.java delete mode 100644 src/main/java/com/fanruan/api/decision/webservice/Response.java delete mode 100644 src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java delete mode 100644 src/test/java/com/fanruan/api/decision/AppearenceKitTest.java delete mode 100644 src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java delete mode 100644 src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java diff --git a/src/main/java/com/fanruan/api/decision/AppearanceKit.java b/src/main/java/com/fanruan/api/decision/AppearanceKit.java deleted file mode 100644 index 9e106b1..0000000 --- a/src/main/java/com/fanruan/api/decision/AppearanceKit.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fanruan.api.decision; - -import com.fr.decision.config.AppearanceConfig; - -/** - * @author lidongy - * @version 10.0 - * Created by lidongy on 2019/10/24 - */ -public class AppearanceKit { - - /** - * 获取选择的登录页插件id - * - * @return id - */ - public static String getLoginPageId() { - return AppearanceConfig.getInstance().getLoginPageId(); - } -} diff --git a/src/main/java/com/fanruan/api/decision/login/LoginKit.java b/src/main/java/com/fanruan/api/decision/login/LoginKit.java index 96a6954..85f7ce8 100644 --- a/src/main/java/com/fanruan/api/decision/login/LoginKit.java +++ b/src/main/java/com/fanruan/api/decision/login/LoginKit.java @@ -2,8 +2,11 @@ package com.fanruan.api.decision.login; import com.fr.decision.authorize.Passport; import com.fr.decision.authorize.impl.HttpPassport; +import com.fr.decision.config.AppearanceConfig; import com.fr.decision.config.FSConfig; +import com.fr.decision.webservice.Response; import com.fr.decision.webservice.v10.login.LoginService; +import com.fr.third.socketio.SocketIOClient; import org.jetbrains.annotations.Nullable; import javax.servlet.http.HttpServletRequest; @@ -74,4 +77,31 @@ public class LoginKit { public static OpenLoginResponse login(HttpServletRequest req, HttpServletResponse res, OpenLoginRequest loginRequest) throws Exception { return OpenLoginResponse.wrap(LoginService.getInstance().login(req, res, loginRequest.select())); } + + /** + * 刷新用户名对应的token,如果非保持登录,会使用tokenTimeout参数设置时长 + * + * @param oldJwt 老的token + * @param socketIOClient socket客户端 + * @param tokenTimeout 设置的超时时长,仅对非保持登录有用,0<= tokenTimeOut <= LoginConfig.LoginTimeOut + * @return 新的token + * @throws Exception 异常 + */ + public static Object refreshToken(String oldJwt, long tokenTimeout, SocketIOClient socketIOClient, Object responseData, String errorCode, String errorMsg) throws Exception{ + Response response = new Response(); + response = LoginService.getInstance().refreshToken(oldJwt, tokenTimeout, socketIOClient); + responseData = response.getData(); + errorCode = response.getErrorCode(); + errorMsg = response.getErrorMsg(); + return response; + } + + /** + * 获取选择的登录页插件id + * + * @return id + */ + public static String getLoginPageId() { + return AppearanceConfig.getInstance().getLoginPageId(); + } } diff --git a/src/main/java/com/fanruan/api/decision/webservice/Response.java b/src/main/java/com/fanruan/api/decision/webservice/Response.java deleted file mode 100644 index 6d88acc..0000000 --- a/src/main/java/com/fanruan/api/decision/webservice/Response.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.fanruan.api.decision.webservice; - -/** - * @author lidongy - * @version 10.0 - * Created by lidongy on 2019/10/24 - */ -public class Response extends com.fr.decision.webservice.Response { - public Response() { - } -} diff --git a/src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java b/src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java deleted file mode 100644 index c10a93d..0000000 --- a/src/main/java/com/fanruan/api/decision/webservice/WebServiceKit.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.fanruan.api.decision.webservice; - -import com.fr.decision.webservice.v10.login.LoginService; -import com.fr.third.socketio.SocketIOClient; - -/** - * @author lidongy - * @version 10.0 - * Created by lidongy on 2019/10/24 - */ -public class WebServiceKit { - - /** - * 刷新用户名对应的token,如果非保持登录,会使用tokenTimeout参数设置时长 - * - * @param oldJwt 老的token - * @param socketIOClient socket客户端 - * @param tokenTimeout 设置的超时时长,仅对非保持登录有用,0<= tokenTimeOut <= LoginConfig.LoginTimeOut - * @return 新的token - * @throws Exception 异常 - */ - public static Response refreshToken(String oldJwt, long tokenTimeout, SocketIOClient socketIOClient) throws Exception{ - return (Response) LoginService.getInstance().refreshToken(oldJwt, tokenTimeout, socketIOClient); - } -} diff --git a/src/test/java/com/fanruan/api/decision/AppearenceKitTest.java b/src/test/java/com/fanruan/api/decision/AppearenceKitTest.java deleted file mode 100644 index 8a66f3c..0000000 --- a/src/test/java/com/fanruan/api/decision/AppearenceKitTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.fanruan.api.decision; - -import com.fr.config.dao.DaoContext; -import com.fr.config.dao.impl.LocalClassHelperDao; -import com.fr.config.dao.impl.LocalEntityDao; -import com.fr.config.dao.impl.LocalXmlEntityDao; -import com.fr.decision.config.AppearanceConfig; -import com.fr.runtime.FineRuntime; -import com.fr.store.StateHubManager; -import com.fr.store.impl.MemoryLock; -import com.fr.store.impl.MemoryStore; -import com.fr.transaction.Configurations; -import com.fr.transaction.LocalConfigurationHelper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * @author lidongy - * @version 10.0 - * Created by lidongy on 2019/10/24 - */ -public class AppearenceKitTest { - @Before - public void start() { - FineRuntime.start(); - DaoContext.setEntityDao(new LocalEntityDao()); - DaoContext.setClassHelperDao(new LocalClassHelperDao()); - DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); - Configurations.setHelper(new LocalConfigurationHelper()); - StateHubManager.setStorage(new MemoryStore()); - StateHubManager.setLock(new MemoryLock()); - } - - @Test - public void TestGetLoginPageId() { - AppearanceConfig.getInstance().setLoginPageId("111"); - Assert.assertEquals(AppearanceKit.getLoginPageId(), "111"); - - AppearanceConfig.getInstance().setLoginPageId("aaa"); - Assert.assertEquals(AppearanceKit.getLoginPageId(), "aaa"); - } -} diff --git a/src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java b/src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java deleted file mode 100644 index 214ece9..0000000 --- a/src/test/java/com/fanruan/api/decision/webservice/ResponseTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.fanruan.api.decision.webservice; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author lidongy - * @version 10.0 - * Created by lidongy on 2019/10/25 - */ -public class ResponseTest { - @Test - public void testResponse() throws Exception{ - Response response = new Response(); - - response.setData("data"); - response.setErrorCode("404"); - response.setErrorMsg("fail to connect"); - response.setStatus(3); - - Assert.assertEquals(response.getData(), "data"); - Assert.assertEquals(response.getErrorCode(), "404"); - Assert.assertEquals(response.getErrorMsg(), "fail to connect"); - Assert.assertEquals(response.getStatus(), 3); - } -} diff --git a/src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java b/src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java deleted file mode 100644 index 56ebbbd..0000000 --- a/src/test/java/com/fanruan/api/decision/webservice/WebServiceKitTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.fanruan.api.decision.webservice; - -import com.fanruan.api.security.JwtKit; -import com.fr.config.dao.DaoContext; -import com.fr.config.dao.impl.LocalClassHelperDao; -import com.fr.config.dao.impl.LocalEntityDao; -import com.fr.config.dao.impl.LocalXmlEntityDao; -import com.fr.decision.webservice.bean.authentication.LoginClientBean; -import com.fr.decision.webservice.exception.login.LoginInfoNotAvailableException; -import com.fr.decision.webservice.utils.DecisionStatusService; -import com.fr.runtime.FineRuntime; -import com.fr.store.StateHubManager; -import com.fr.store.impl.MemoryLock; -import com.fr.store.impl.MemoryStore; -import com.fr.transaction.Configurations; -import com.fr.transaction.LocalConfigurationHelper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * @author lidongy - * @version 10.0 - * Created by lidongy on 2019/10/24 - */ -public class WebServiceKitTest { - - @Before - public void start() { - FineRuntime.start(); - DaoContext.setEntityDao(new LocalEntityDao()); - DaoContext.setClassHelperDao(new LocalClassHelperDao()); - DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); - Configurations.setHelper(new LocalConfigurationHelper()); - StateHubManager.setStorage(new MemoryStore()); - StateHubManager.setLock(new MemoryLock()); - } - @Test - public void testRefreshToken() throws Exception{ - String jwtString = JwtKit.createDefaultJWT("123"); - try { - Response response = WebServiceKit.refreshToken(jwtString, 1000 * 60, null); - } catch (Exception e) { - Assert.assertTrue(e instanceof LoginInfoNotAvailableException); - } - LoginClientBean loginClientBean = new LoginClientBean(); - DecisionStatusService.loginStatusService().put(jwtString, loginClientBean); - try { - Response response = WebServiceKit.refreshToken(jwtString, 1000 * 60, null); - } catch (Exception e) { - Assert.assertFalse(e instanceof LoginInfoNotAvailableException); - } - } -} From 74400ef6b90294f76e827032cfb84b13f8da5ad7 Mon Sep 17 00:00:00 2001 From: lidongy <1879087903@qq.com> Date: Fri, 25 Oct 2019 11:21:56 +0800 Subject: [PATCH 3/3] test Signed-off-by: lidongy <1879087903@qq.com> --- .../api/decision/login/LoginKitTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/test/java/com/fanruan/api/decision/login/LoginKitTest.java diff --git a/src/test/java/com/fanruan/api/decision/login/LoginKitTest.java b/src/test/java/com/fanruan/api/decision/login/LoginKitTest.java new file mode 100644 index 0000000..76bf3c3 --- /dev/null +++ b/src/test/java/com/fanruan/api/decision/login/LoginKitTest.java @@ -0,0 +1,69 @@ +package com.fanruan.api.decision.login; + +import com.fanruan.api.security.JwtKit; +import com.fr.config.dao.DaoContext; +import com.fr.config.dao.impl.LocalClassHelperDao; +import com.fr.config.dao.impl.LocalEntityDao; +import com.fr.config.dao.impl.LocalXmlEntityDao; +import com.fr.decision.config.AppearanceConfig; +import com.fr.decision.webservice.Response; +import com.fr.decision.webservice.bean.authentication.LoginClientBean; +import com.fr.decision.webservice.exception.login.LoginInfoNotAvailableException; +import com.fr.decision.webservice.utils.DecisionStatusService; +import com.fr.runtime.FineRuntime; +import com.fr.store.StateHubManager; +import com.fr.store.impl.MemoryLock; +import com.fr.store.impl.MemoryStore; +import com.fr.transaction.Configurations; +import com.fr.transaction.LocalConfigurationHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/25 + */ +public class LoginKitTest { + + @Before + public void start() { + FineRuntime.start(); + DaoContext.setEntityDao(new LocalEntityDao()); + DaoContext.setClassHelperDao(new LocalClassHelperDao()); + DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + Configurations.setHelper(new LocalConfigurationHelper()); + StateHubManager.setStorage(new MemoryStore()); + StateHubManager.setLock(new MemoryLock()); + } + + @Test + public void testRefreshToken() throws Exception{ + String jwtString = JwtKit.createDefaultJWT("123"); + Object responseData = new Object(); + String errorCode = ""; + String errorMsg = ""; + try { + Response response = (Response) LoginKit.refreshToken(jwtString, 1000 * 60, null, responseData, errorCode, errorMsg); + } catch (Exception e) { + Assert.assertTrue(e instanceof LoginInfoNotAvailableException); + } + LoginClientBean loginClientBean = new LoginClientBean(); + DecisionStatusService.loginStatusService().put(jwtString, loginClientBean); + try { + Response response = (Response) LoginKit.refreshToken(jwtString, 1000 * 60, null, responseData, errorCode, errorMsg); + } catch (Exception e) { + Assert.assertFalse(e instanceof LoginInfoNotAvailableException); + } + } + + @Test + public void TestGetLoginPageId() { + AppearanceConfig.getInstance().setLoginPageId("111"); + Assert.assertEquals(LoginKit.getLoginPageId(), "111"); + + AppearanceConfig.getInstance().setLoginPageId("aaa"); + Assert.assertEquals(LoginKit.getLoginPageId(), "aaa"); + } +}