yml配置文件
- 此文件只做一小部分演示
- 在
oauth
下 定义data-isolation
(命名都是自定义)
oauth:
data-isolation: #有用户信息时,需要数据隔离
- /act-activity/page
- /oact-open-activity/page
- /activity-calendar/detail
- /activity-calendar/list
- /oact-open-activity/page
- /oact-open-activity/page-date
- /oact-open-activity/page-change-record
- /ach-work/page-work-record
配置类
- 注意@ConfigurationProperties(“xxx”)要对应上方yml文件中的最上级
oauth
(自定义命名) - 属性命名也要和yml配置文件上的一致才可让数据自动赋值
@Data
@Component
@ConfigurationProperties("oauth")
public class OAuthProperties {
/**
* 需要数据隔离(获取教育局id集合/学校id集合)
*/
private Set<String> dataIsolation;
}
代码实现
-
该演示具体业务是在yml配置文件中
data-isolation
下填写需要做业务操作的接口名,然后结合aop动态代理去对这些接口实现业务处理
-
注入上方的配置类
OAuthProperties
,即可获取需要做业务逻辑的接口 -
该演示方法,传参则是对应的接口名,若对应则返回true(可以结合AOP动态代理使用,详情请至AOP动态代理使用)
@Component
public class XkHttpSecurity {
@Autowired
private OAuthProperties oauthProperties;
public boolean isNeedUserInfo(String servletPath) {
Set<String> needUserInfo = this.oauthProperties.getNeedUserInfo();
return CollectionUtil.isEmpty(needUserInfo) ? false : needUserInfo.contains(servletPath);
}