|
|
@ -1,18 +1,17 @@ |
|
|
|
package com.fr.plugin.decision.url.login.web; |
|
|
|
package com.fr.plugin.decision.url.login.web; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.TemplateUtils; |
|
|
|
import com.fanruan.api.decision.CommonKit; |
|
|
|
|
|
|
|
import com.fanruan.api.decision.login.LoginKit; |
|
|
|
|
|
|
|
import com.fanruan.api.decision.login.OpenLoginRequest; |
|
|
|
|
|
|
|
import com.fanruan.api.decision.login.OpenLoginResponse; |
|
|
|
|
|
|
|
import com.fanruan.api.decision.macro.Constants; |
|
|
|
|
|
|
|
import com.fanruan.api.log.LogKit; |
|
|
|
|
|
|
|
import com.fanruan.api.net.NetworkKit; |
|
|
|
|
|
|
|
import com.fanruan.api.util.RenderKit; |
|
|
|
|
|
|
|
import com.fanruan.api.util.StringKit; |
|
|
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
|
|
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
|
|
|
import com.fr.decision.webservice.bean.authentication.LoginRequestInfoBean; |
|
|
|
|
|
|
|
import com.fr.decision.webservice.bean.authentication.LoginResponseInfoBean; |
|
|
|
|
|
|
|
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
|
|
|
|
|
|
|
import com.fr.decision.webservice.utils.WebServiceUtils; |
|
|
|
|
|
|
|
import com.fr.decision.webservice.v10.login.LoginService; |
|
|
|
|
|
|
|
import com.fr.general.web.ParameterConstants; |
|
|
|
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
|
|
|
import com.fr.plugin.transform.FunctionRecorder; |
|
|
|
import com.fr.plugin.transform.FunctionRecorder; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import com.fr.web.utils.WebUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.Cookie; |
|
|
|
import javax.servlet.http.Cookie; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
@ -46,35 +45,35 @@ public class LoginAction extends BaseHttpHandler { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
String username = WebUtils.getHTTPRequestParameter(request, ParameterConstants.FINE_USERNAME); |
|
|
|
String username = NetworkKit.getHTTPRequestParameter(request, Constants.FINE_USERNAME); |
|
|
|
String password = WebUtils.getHTTPRequestParameter(request, ParameterConstants.FINE_PASSWORD); |
|
|
|
String password = NetworkKit.getHTTPRequestParameter(request, Constants.FINE_PASSWORD); |
|
|
|
int validity = WebUtils.getHTTPRequestIntParameter(request, "validity"); |
|
|
|
int validity = NetworkKit.getHTTPRequestIntParameter(request, "validity"); |
|
|
|
String origin = WebUtils.getHTTPRequestParameter(request, "origin"); |
|
|
|
String origin = NetworkKit.getHTTPRequestParameter(request, "origin"); |
|
|
|
LoginRequestInfoBean requestInfoBean = new LoginRequestInfoBean(); |
|
|
|
OpenLoginRequest requestInfoBean = OpenLoginRequest.create(); |
|
|
|
requestInfoBean.setUsername(username); |
|
|
|
requestInfoBean.setUsername(username); |
|
|
|
requestInfoBean.setOrigin(origin); |
|
|
|
requestInfoBean.setOrigin(origin); |
|
|
|
requestInfoBean.setPassword(password); |
|
|
|
requestInfoBean.setPassword(password); |
|
|
|
requestInfoBean.setValidity(validity); |
|
|
|
requestInfoBean.setValidity(validity); |
|
|
|
requestInfoBean.setSliderToken(""); |
|
|
|
requestInfoBean.setSliderToken(""); |
|
|
|
LoginResponseInfoBean responseInfoBean = LoginService.getInstance().login(request, response, requestInfoBean); |
|
|
|
OpenLoginResponse responseInfoBean = LoginKit.login(request, response, requestInfoBean); |
|
|
|
origin = StringUtils.isEmpty(origin) ? TemplateUtils.render(DecisionServiceConstants.MAIN_PAGE_URL) : WebServiceUtils.getBase64DecodeStr(origin); |
|
|
|
origin = StringKit.isEmpty(origin) ? RenderKit.render(Constants.MAIN_PAGE_URL) : CommonKit.getBase64DecodeStr(origin); |
|
|
|
writeToken2Cookie(response, responseInfoBean.getAccessToken(), responseInfoBean.getValidity()); |
|
|
|
writeToken2Cookie(response, responseInfoBean.getAccessToken(), responseInfoBean.getValidity()); |
|
|
|
response.sendRedirect(origin); |
|
|
|
response.sendRedirect(origin); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void writeToken2Cookie(HttpServletResponse response, String token, int validity) { |
|
|
|
private void writeToken2Cookie(HttpServletResponse response, String token, int validity) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (StringUtils.isNotEmpty(token)) { |
|
|
|
if (StringKit.isNotEmpty(token)) { |
|
|
|
Cookie cookie = new Cookie(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); |
|
|
|
Cookie cookie = new Cookie(Constants.FINE_AUTH_TOKEN_NAME, token); |
|
|
|
long cookieLife = validity == REMEMBER_PASSWORD ? DecisionServiceConstants.REMEMBER_PASSWORD_LIFE : validity; |
|
|
|
long cookieLife = validity == REMEMBER_PASSWORD ? Constants.REMEMBER_PASSWORD_LIFE : validity; |
|
|
|
cookie.setMaxAge((int) cookieLife); |
|
|
|
cookie.setMaxAge((int) cookieLife); |
|
|
|
cookie.setPath("/"); |
|
|
|
cookie.setPath("/"); |
|
|
|
response.addCookie(cookie); |
|
|
|
response.addCookie(cookie); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
FineLoggerFactory.getLogger().error("empty token cannot save."); |
|
|
|
LogKit.error("empty token cannot save."); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |