JSD-7472 jwt单点
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.

76 lines
2.5 KiB

package com.fr.plugin.sso.filter;
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider;
import com.fr.plugin.sso.utils.FRUtils;
import com.fr.plugin.sso.utils.ResponseUtils;
import com.fr.plugin.sso.utils.Utils;
import com.fr.plugin.transform.FunctionRecorder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.Key;
@FunctionRecorder
public class SSOFilter2 extends AbstractEmbedRequestFilterProvider {
@Override
public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
String url = FRUtils.getAllUrl(httpServletRequest);
if(!url.contains("viewlet")){
return ;
}
String reft = httpServletRequest.getParameter("ref_t");
//如果是远程设计则放行
if(url.contains("remote") || (Utils.isNotNullStr(reft)&&reft.equals("design"))){
return;
}
//没有登录参数则放行
String token = httpServletRequest.getParameter("token");
//登录名
String username = httpServletRequest.getParameter("username");
FRUtils.FRLogInfo("token:"+token+";username:"+username);
if(Utils.isNullStr(token) && Utils.isNullStr(username)){
ResponseUtils.failedResponse(httpServletResponse,"您没有报表访问权限,请联系管理员!");
return;
}
Key otherKey = Keys.hmacShaKeyFor(
Decoders.BASE64.decode("xxxx")
);
try {
io.jsonwebtoken.Jws<io.jsonwebtoken.Claims> aa = Jwts.parserBuilder().setSigningKey(otherKey).build().parseClaimsJws(token);
//未登录,用用户名登录
//已登录,退出重新登录
//相同用户名,跳过
boolean isLogin = FRUtils.isLogin(httpServletRequest);
if(isLogin){
String currentUser = FRUtils.getCurrentUserName(httpServletRequest);
if(currentUser.equals(username)){
return;
}
FRUtils.logout(httpServletRequest,httpServletResponse);
}
FRUtils.login(httpServletRequest,httpServletResponse,username,"");
} catch (Exception e) {
FRUtils.FRLogInfo("token校验失败:"+e.getMessage());
ResponseUtils.failedResponse(httpServletResponse,"token校验失败");
return ;
}
}
}