You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.3 KiB
74 lines
2.3 KiB
3 years ago
|
package com.fr.plugin.xxx.xxx.sso;
|
||
|
|
||
|
import com.fr.plugin.context.PluginContexts;
|
||
|
import com.fr.plugin.xxx.xxx.sso.util.CommonUtils;
|
||
|
import com.fr.plugin.xxx.xxx.sso.util.HttpUtil;
|
||
|
import com.fr.plugin.xxx.xxx.sso.util.LogUtils;
|
||
|
import com.fr.plugin.transform.FunctionRecorder;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.stable.fun.Authorize;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
|
||
|
import javax.servlet.FilterChain;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
||
|
/**
|
||
|
* @Author xxx
|
||
|
* @Date 2022/3/3
|
||
|
* @Description
|
||
|
**/
|
||
|
@FunctionRecorder
|
||
|
@Authorize(callSignKey = PluginConstants.PLUGIN_ID)
|
||
|
public class SsoFilter extends LoginFilter {
|
||
|
@Override
|
||
|
public String filterName() {
|
||
|
return "xxx";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String[] urlPatterns() {
|
||
|
if (PluginContexts.currentContext().isAvailable()) {
|
||
|
return new String[]{
|
||
|
"/decision",
|
||
|
"/decision/view/report",
|
||
|
"/decision/view/form",
|
||
|
};
|
||
|
} else {
|
||
|
return new String[]{"/qqqqq"};
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
|
||
|
xxxConfig config = xxxConfig.getInstance();
|
||
|
if (CommonUtils.isLogin(req) || !config.isConfiged()) {
|
||
|
CommonUtils.next(req, res, filterChain);
|
||
|
return;
|
||
|
}
|
||
|
String code = WebUtils.getHTTPRequestParameter(req, "code");
|
||
|
if (StringUtils.isNotBlank(code)) {
|
||
|
String username = HttpUtil.getUsername(config.getAccessUrl(), config.getProfileUrl()
|
||
|
, config.getClientId(), config.getClientSecret()
|
||
|
, config.getGrantType(), config.getRedirectUrl(), code);
|
||
|
LogUtils.debug4plugin("code {} get username is {}",username);
|
||
|
try {
|
||
|
CommonUtils.login(username,req,res);
|
||
|
String origin = CommonUtils.getOrigin(req);
|
||
|
if (StringUtils.isNotBlank(origin)) {
|
||
|
res.sendRedirect(origin);
|
||
|
return;
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
CommonUtils.setError(res,"用户不存在");
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
CommonUtils.next(req, res, filterChain);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|