From d2482cdcc37534bc2a686149e59c45e3a7569661 Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 14 Oct 2019 12:02:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=9B=B8=E5=85=B3=E7=9A=84AP?= =?UTF-8?q?I?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 3 +- .../fanruan/api/decision/login/LoginKit.java | 17 ++++ .../api/decision/login/OpenLoginRequest.java | 93 +++++++++++++++++++ .../api/decision/login/OpenLoginResponse.java | 69 ++++++++++++++ .../fanruan/api/decision/macro/Constants.java | 40 ++++++++ .../java/com/fanruan/api/util/RenderKit.java | 23 +++-- .../com/fanruan/api/util/RenderKitTest.java | 8 ++ 7 files changed, 246 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/fanruan/api/decision/login/OpenLoginRequest.java create mode 100644 src/main/java/com/fanruan/api/decision/login/OpenLoginResponse.java create mode 100644 src/main/java/com/fanruan/api/decision/macro/Constants.java diff --git a/readme.md b/readme.md index 3b0aa77..ad3fa33 100644 --- a/readme.md +++ b/readme.md @@ -94,4 +94,5 @@ mvn javadoc:javadoc |http认证简化插件|https://git.fanruan.com/fanruan/demo-auth-http| |xml导出插件|https://git.fanruan.com/fanruan/demo-export-xml| |echarts图表插件|https://git.fanruan.com/fanruan/demo-chart-pie| -|多sheet懒加载|https://git.fanruan.com/fanruan/plugin-report-lazy-sheet| +|多sheet懒加载插件|https://git.fanruan.com/fanruan/plugin-report-lazy-sheet| +|url直接登录插件|https://git.fanruan.com/fanruan/plugin-decision-url-login| 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 620c2a2..96a6954 100644 --- a/src/main/java/com/fanruan/api/decision/login/LoginKit.java +++ b/src/main/java/com/fanruan/api/decision/login/LoginKit.java @@ -3,8 +3,12 @@ package com.fanruan.api.decision.login; import com.fr.decision.authorize.Passport; import com.fr.decision.authorize.impl.HttpPassport; import com.fr.decision.config.FSConfig; +import com.fr.decision.webservice.v10.login.LoginService; import org.jetbrains.annotations.Nullable; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + /** * @author richie * @version 10.0 @@ -57,4 +61,17 @@ public class LoginKit { } return null; } + + /** + * 登录 + * + * @param req http请求 + * @param res http响应 + * @param loginRequest 登录请求信息 + * @return 登录响应信息 + * @throws Exception 登录过程中发生错误,则抛出此异常 + */ + public static OpenLoginResponse login(HttpServletRequest req, HttpServletResponse res, OpenLoginRequest loginRequest) throws Exception { + return OpenLoginResponse.wrap(LoginService.getInstance().login(req, res, loginRequest.select())); + } } diff --git a/src/main/java/com/fanruan/api/decision/login/OpenLoginRequest.java b/src/main/java/com/fanruan/api/decision/login/OpenLoginRequest.java new file mode 100644 index 0000000..e1a9aed --- /dev/null +++ b/src/main/java/com/fanruan/api/decision/login/OpenLoginRequest.java @@ -0,0 +1,93 @@ +package com.fanruan.api.decision.login; + +import com.fr.decision.webservice.bean.authentication.LoginRequestInfoBean; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/10/14 + */ +public class OpenLoginRequest { + + private LoginRequestInfoBean request; + + public static OpenLoginRequest create() { + return wrap(new LoginRequestInfoBean()); + } + + static OpenLoginRequest wrap(LoginRequestInfoBean request) { + return new OpenLoginRequest(request); + } + + private OpenLoginRequest(LoginRequestInfoBean request) { + this.request = request; + } + + LoginRequestInfoBean select() { + return request; + } + + public String getUsername() { + return request.getUsername(); + } + + public void setUsername(String username) { + request.setUsername(username); + } + + public String getPassword() { + return request.getPassword(); + } + + public void setPassword(String password) { + request.setPassword(password); + } + + public int getValidity() { + return request.getValidity(); + } + + public void setValidity(int validity) { + request.setValidity(validity); + } + + public String getMacAddress() { + return request.getMacAddress(); + } + + public void setMacAddress(String macAddress) { + request.setMacAddress(macAddress); + } + + public String getDeviceName() { + return request.getDeviceName(); + } + + public void setDeviceName(String deviceName) { + request.setDeviceName(deviceName); + } + + public String getOrigin() { + return request.getOrigin(); + } + + public void setOrigin(String origin) { + request.setOrigin(origin); + } + + public String getSliderToken() { + return request.getSliderToken(); + } + + public void setSliderToken(String sliderToken) { + request.setSliderToken(sliderToken); + } + + public boolean isEncrypted() { + return request.isEncrypted(); + } + + public void setEncrypted(boolean encrypted) { + request.setEncrypted(encrypted); + } +} diff --git a/src/main/java/com/fanruan/api/decision/login/OpenLoginResponse.java b/src/main/java/com/fanruan/api/decision/login/OpenLoginResponse.java new file mode 100644 index 0000000..4364994 --- /dev/null +++ b/src/main/java/com/fanruan/api/decision/login/OpenLoginResponse.java @@ -0,0 +1,69 @@ +package com.fanruan.api.decision.login; + +import com.fr.decision.webservice.bean.authentication.LoginResponseInfoBean; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/10/14 + */ +public class OpenLoginResponse { + + private LoginResponseInfoBean response; + + public static OpenLoginResponse create() { + return wrap(new LoginResponseInfoBean()); + } + + static OpenLoginResponse wrap(LoginResponseInfoBean response) { + return new OpenLoginResponse(response); + } + + private OpenLoginResponse(LoginResponseInfoBean response) { + this.response = response; + } + + LoginResponseInfoBean select() { + return response; + } + + public String getAccessToken() { + return response.getAccessToken(); + } + + public void setAccessToken(String accessToken) { + response.setAccessToken(accessToken); + } + + public String getCallback() { + return response.getCallback(); + } + + public void setCallback(String callback) { + response.setCallback(callback); + } + + public String getUsername() { + return response.getUsername(); + } + + public void setUsername(String username) { + response.setUsername(username); + } + + public int getValidity() { + return response.getValidity(); + } + + public void setValidity(int validity) { + response.setValidity(validity); + } + + public String getUrl() { + return response.getUrl(); + } + + public void setUrl(String url) { + response.setUrl(url); + } +} diff --git a/src/main/java/com/fanruan/api/decision/macro/Constants.java b/src/main/java/com/fanruan/api/decision/macro/Constants.java new file mode 100644 index 0000000..ba67dfe --- /dev/null +++ b/src/main/java/com/fanruan/api/decision/macro/Constants.java @@ -0,0 +1,40 @@ +package com.fanruan.api.decision.macro; + +import com.fr.decision.webservice.utils.DecisionServiceConstants; +import com.fr.general.web.ParameterConstants; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/10/14 + * 决策平台常用常量 + */ +public class Constants { + + /** + * 表示用户名参数名的常量 + */ + public static final String FINE_USERNAME = ParameterConstants.FINE_USERNAME; + + /** + * 表示密码参数名的常量 + */ + public static final String FINE_PASSWORD = ParameterConstants.FINE_PASSWORD; + + /** + * 用于表示决策平台主页的常量,需要使用RenderKit#render方法将这个常量生成为实际的url地址 + * + * @see com.fanruan.api.util.RenderKit#render(String) + */ + public static final String MAIN_PAGE_URL = DecisionServiceConstants.MAIN_PAGE_URL; + + /** + * 表示认证票据参数名的常量 + */ + public static final String FINE_AUTH_TOKEN_NAME = DecisionServiceConstants.FINE_AUTH_TOKEN_NAME; + + /** + * 记住密码时的最长时间(服务器重启后记住密码也会失效) + */ + public static final long REMEMBER_PASSWORD_LIFE = DecisionServiceConstants.REMEMBER_PASSWORD_LIFE; +} diff --git a/src/main/java/com/fanruan/api/util/RenderKit.java b/src/main/java/com/fanruan/api/util/RenderKit.java index 65d27f7..a2e2a40 100644 --- a/src/main/java/com/fanruan/api/util/RenderKit.java +++ b/src/main/java/com/fanruan/api/util/RenderKit.java @@ -2,9 +2,7 @@ package com.fanruan.api.util; import com.fr.base.TemplateUtils; import com.fr.script.Calculator; -import com.fr.stable.script.CalculatorProvider; -import java.util.Collections; import java.util.Map; /** @@ -14,8 +12,9 @@ public class RenderKit { /** * 根据参数, 来计算文档字符串 + * * @param text 待渲染的文本模板 - * @param map 参数集合 + * @param map 参数集合 * @return 返回渲染后的文本 * @throws Exception 渲染过程中出现错误则抛出此异常 */ @@ -25,12 +24,24 @@ public class RenderKit { /** * 根据参数, 来计算文档字符串 - * @param s 待渲染的文本模板 + * + * @param text 待渲染的文本模板 * @param c 参数集合 * @return 返回渲染后的文本 * @throws Exception 渲染过程中出现错误则抛出此异常 */ - public static String render(String s, Calculator c) throws Exception { - return TemplateUtils.render(s, c); + public static String render(String text, Calculator c) throws Exception { + return TemplateUtils.render(text, c); + } + + /** + * 根据参数, 来计算文档字符串 + * + * @param text 待渲染的文本模板 + * @return 返回渲染后的文本 + * @throws Exception 渲染过程中出现错误则抛出此异常 + */ + public static String render(String text) throws Exception { + return TemplateUtils.render(text, Calculator.createCalculator()); } } diff --git a/src/test/java/com/fanruan/api/util/RenderKitTest.java b/src/test/java/com/fanruan/api/util/RenderKitTest.java index a705166..94aed9e 100644 --- a/src/test/java/com/fanruan/api/util/RenderKitTest.java +++ b/src/test/java/com/fanruan/api/util/RenderKitTest.java @@ -2,6 +2,7 @@ package com.fanruan.api.util; import com.fanruan.api.Prepare; import com.fr.script.Calculator; +import com.fr.state.SateVariableManager; import org.junit.Assert; import org.junit.Test; import java.util.HashMap; @@ -35,4 +36,11 @@ public class RenderKitTest extends Prepare { Assert.assertEquals("abcxyz", RenderKit.render(s,c)); } + @Test + public void render2() throws Exception { + SateVariableManager.put("fineServletURL", "balala"); + String t = RenderKit.render("${fineServletURL}"); + Assert.assertEquals("balala", t); + } + }