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; import javax.servlet.http.HttpServletResponse; /** * @author richie * @version 10.0 * Created by richie on 2019-08-16 */ public class LoginKit { /** * 获取决策平台设置的认证类型 * * @return 认证对象 */ public static Passport getCurrentPassport() { return FSConfig.getInstance().getPassport(); } /** * 获取指定类型的通行证,如果不存在,就返回null * * @param type 通行证类型 * @param 类型 * @return 通行证 */ public static T getPassport(Class type) { return FSConfig.getInstance().getPassport(type); } /** * 获取http认证的地址 * * @return http认证地址 */ public static @Nullable String getHttpPassportUrl() { Passport passport = getCurrentPassport(); if (passport instanceof HttpPassport) { return ((HttpPassport) passport).getUrl(); } return null; } /** * 获取http认证的秘钥 * * @return http认证地址 */ public static @Nullable String getHttpPassportKey() { Passport passport = getCurrentPassport(); if (passport instanceof HttpPassport) { return ((HttpPassport) passport).getPublicKey(); } 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())); } /** * 刷新用户名对应的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(); } }