Commit fb0c68f6 by levphon

共享数据拦截器

1 parent bd77431b
...@@ -6,6 +6,7 @@ import com.glsx.plat.core.web.R; ...@@ -6,6 +6,7 @@ import com.glsx.plat.core.web.R;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -33,6 +34,14 @@ public interface AuthFeignClient { ...@@ -33,6 +34,14 @@ public interface AuthFeignClient {
R<SyntheticUser> getAuthUser(); R<SyntheticUser> getAuthUser();
/** /**
* 获取userId用户对应资源等权限
*
* @return
*/
@GetMapping(value = "/getAuthUserById", consumes = MediaType.APPLICATION_JSON_VALUE)
R<SyntheticUser> getAuthUserById(@RequestParam("userId") Long userId);
/**
* 获取当前登录用户角色数据权限内的部门id * 获取当前登录用户角色数据权限内的部门id
* *
* @return * @return
......
...@@ -94,14 +94,12 @@ public class DataOnlySharedInterceptor implements Interceptor { ...@@ -94,14 +94,12 @@ public class DataOnlySharedInterceptor implements Interceptor {
} }
//拼装sql //拼装sql
String originSql = OriginSqlHolder.getSql(); //获取到当前需要被执行的原始SQL String originSql = boundSql.getSql(); //获取到当前需要被执行的SQL
String permitSql = boundSql.getSql(); //获取到当前需要被执行的权限SQL
String relativePertSql = assembleLinkOriginSql(permitSql); //相对数据权限过滤组装
String linkPermitSql = assembleLinkPermitSql(originSql, dataAuth, ShieldContextHolder.getUserId()); //绝对数据权限过滤组装 String linkPermitSql = assembleLinkPermitSql(originSql, dataAuth, ShieldContextHolder.getUserId()); //绝对数据权限过滤组装
if (dataAuth.showSql()) { if (dataAuth.showSql()) {
log.info("\nrelativePertSql:{}\nlinkPermitSql:{}", relativePertSql, linkPermitSql); log.info("\noriginSql:{}\nlinkPermitSql:{}", originSql, linkPermitSql);
} }
//复制一份参数 //复制一份参数
...@@ -126,23 +124,6 @@ public class DataOnlySharedInterceptor implements Interceptor { ...@@ -126,23 +124,6 @@ public class DataOnlySharedInterceptor implements Interceptor {
return invocation.proceed(); return invocation.proceed();
} }
private String assembleLinkOriginSql(String sql) throws JSQLParserException {
Select select = (Select) parserManager.parse(new StringReader(sql));
SelectBody selectBody = select.getSelectBody();
PlainSelect plain = (PlainSelect) selectBody;
plain.setOrderByElements(null);
plain.setLimit(null);
String plainStr = plain.toString();
return plainStr;
}
private String assembleLinkPermitSql(String sql, DataOnlyShared dataAuth, Long userId) throws JSQLParserException { private String assembleLinkPermitSql(String sql, DataOnlyShared dataAuth, Long userId) throws JSQLParserException {
Select select = (Select) parserManager.parse(new StringReader(sql)); Select select = (Select) parserManager.parse(new StringReader(sql));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!