Browse Source

登录相关的API

pull/28/head
richie 5 years ago
parent
commit
d2482cdcc3
  1. 3
      readme.md
  2. 17
      src/main/java/com/fanruan/api/decision/login/LoginKit.java
  3. 93
      src/main/java/com/fanruan/api/decision/login/OpenLoginRequest.java
  4. 69
      src/main/java/com/fanruan/api/decision/login/OpenLoginResponse.java
  5. 40
      src/main/java/com/fanruan/api/decision/macro/Constants.java
  6. 21
      src/main/java/com/fanruan/api/util/RenderKit.java
  7. 8
      src/test/java/com/fanruan/api/util/RenderKitTest.java

3
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|

17
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()));
}
}

93
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);
}
}

69
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);
}
}

40
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;
}

21
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,6 +12,7 @@ public class RenderKit {
/**
* 根据参数, 来计算文档字符串
*
* @param text 待渲染的文本模板
* @param map 参数集合
* @return 返回渲染后的文本
@ -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());
}
}

8
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);
}
}

Loading…
Cancel
Save