Browse Source

Merge pull request #38 in TC/finekit from ~LIDONGY/finekit:master to master

* commit '74400ef6b90294f76e827032cfb84b13f8da5ad7':
  test
  改到loginkit里面了
  KERNEL-1444 加几个接口
pull/1/head
superman 5 years ago
parent
commit
0295a21fad
  1. 30
      src/main/java/com/fanruan/api/decision/login/LoginKit.java
  2. 69
      src/test/java/com/fanruan/api/decision/login/LoginKitTest.java

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

69
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");
}
}
Loading…
Cancel
Save