增加全功能spring-cloud-gateway,优化部分公共模块适配webFlux
This commit is contained in:
-25
@@ -2,12 +2,8 @@ package com.central.gateway.config;
|
||||
|
||||
import com.central.common.config.DefaultPasswordConfig;
|
||||
import com.central.oauth2.common.config.DefaultResourceServerConf;
|
||||
import com.central.oauth2.common.properties.SecurityProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
||||
@@ -17,29 +13,8 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.E
|
||||
*/
|
||||
@Configuration
|
||||
@EnableResourceServer
|
||||
@EnableConfigurationProperties(SecurityProperties.class)
|
||||
@Import({DefaultPasswordConfig.class})
|
||||
public class ResourceServerConfiguration extends DefaultResourceServerConf {
|
||||
@Autowired
|
||||
private SecurityProperties securityProperties;
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl = setHttp(http)
|
||||
.authorizeRequests()
|
||||
.antMatchers(securityProperties.getAuth().getHttpUrls()).authenticated()
|
||||
.antMatchers(securityProperties.getIgnore().getUrls()).permitAll()
|
||||
.antMatchers(HttpMethod.OPTIONS).permitAll()
|
||||
.anyRequest();
|
||||
setAuthenticate(authorizedUrl);
|
||||
//允许使用iframe 嵌套,避免swagger-ui 不被加载的问题
|
||||
http.headers()
|
||||
.frameOptions()
|
||||
.disable()
|
||||
.and()
|
||||
.csrf().disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpSecurity setAuthenticate(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl) {
|
||||
return authorizedUrl.access("@permissionService.hasPermission(request, authentication)").and();
|
||||
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.central.gateway.filter.pre;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.constant.ConfigConstants;
|
||||
import com.central.common.context.LbIsolationContextHolder;
|
||||
import com.netflix.zuul.ZuulFilter;
|
||||
import com.netflix.zuul.context.RequestContext;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 保存负载均衡隔离值
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2019/8/13
|
||||
*/
|
||||
@Component
|
||||
public class LbIsolationFilter extends ZuulFilter {
|
||||
@Value("${" + ConfigConstants.CONFIG_RIBBON_ISOLATION_ENABLED + ":false}")
|
||||
private boolean enableIsolation;
|
||||
|
||||
@Override
|
||||
public String filterType() {
|
||||
return FilterConstants.PRE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int filterOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter() {
|
||||
//根据配置控制是否开启过滤器
|
||||
return enableIsolation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object run() {
|
||||
RequestContext ctx = RequestContext.getCurrentContext();
|
||||
String version = ctx.getRequest().getHeader(CommonConstant.Z_L_T_VERSION);
|
||||
if (StrUtil.isNotEmpty(version)) {
|
||||
LbIsolationContextHolder.setVersion(version);
|
||||
} else {
|
||||
LbIsolationContextHolder.clear();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+6
@@ -4,8 +4,10 @@ import com.central.common.model.SysMenu;
|
||||
import com.central.gateway.feign.MenuService;
|
||||
import com.central.oauth2.common.service.impl.DefaultPermissionServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -24,4 +26,8 @@ public class PermissionServiceImpl extends DefaultPermissionServiceImpl {
|
||||
public List<SysMenu> findMenuByRoleCodes(String roleCodes) {
|
||||
return menuService.findByRoleCodes(roleCodes);
|
||||
}
|
||||
|
||||
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
|
||||
return hasPermission(authentication, request.getMethod(), request.getRequestURI());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user