EL1057E: No bean resolver registered in the context to resolve access to bean 'permissionService'

简介: https://github.com/spring-projects/spring-security-oauth/issues/730@Slf4j@Component("permis...

https://github.com/spring-projects/spring-security-oauth/issues/730

@Slf4j
@Component("permissionService")
public class UacPermissionServiceImpl implements UacPermissionService{
    private AntPathMatcher antPathMatcher = new AntPathMatcher();
    @Override
    public boolean hasPermission(Authentication authentication, HttpServletRequest request) {
        String currentLoginName = SecurityUtils.getCurrentLoginName();
        Set<String> currentAuthorityUrl = SecurityUtils.getCurrentAuthorityUrl();
        String requestURI = request.getRequestURI();
        log.info("验证权限loginName={}, requestURI={}, hasAuthorityUrl={}", currentLoginName, requestURI, Joiner.on(",").join(currentAuthorityUrl));

        if (StringUtils.equals(currentLoginName, GlobalConstant.Sys.SUPER_MANAGER_LOGIN_NAME)) {
            return true;
        }
        for (final String authority : currentAuthorityUrl) {
            // DEMO项目放过查询权限
            if (requestURI.contains("query") || requestURI.contains("get") || requestURI.contains("check") || requestURI.contains("select")) {
                return true;
            }
            if (antPathMatcher.match(authority, requestURI)) {
                return true;
            }
        }
        return false;
    }
}
@Order
@Component
public class PcPermissionAuthorizeConfigProvider implements AuthorizeConfigProvider {

    /**
     * Config boolean.
     *
     * @param config the config
     *
     * @return the boolean
     */
    @Override
    public boolean config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        config
            .anyRequest()
                .access("@permissionService.hasPermission(authentication,request)");
        return true;
    }

}
@Configuration
public class PcSecurityExpressionHandler extends OAuth2WebSecurityExpressionHandler {
    @Bean
    public OAuth2WebSecurityExpressionHandler oAuth2WebSecurityExpressionHandler(ApplicationContext applicationContext) {
        OAuth2WebSecurityExpressionHandler expressionHandler = new OAuth2WebSecurityExpressionHandler();
        expressionHandler.setApplicationContext(applicationContext);
        return expressionHandler;
    }
}
@Configuration
@EnableResourceServer
public class PcResourceServerConfig extends ResourceServerConfigurerAdapter {
    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources.expressionHandler(pcSecurityExpressionHandler);
    }
}

暂时记录一下 以后整理

目录
相关文章
|
Java 数据库连接 mybatis
Consider defining a bean of type ‘com.example.democrud.democurd.usermapper.DaoMapper‘ in your config
Consider defining a bean of type ‘com.example.democrud.democurd.usermapper.DaoMapper‘ in your config
224 0
|
7月前
|
监控 druid Java
Springboot用JUnit测试接口时报错Failed to determine a suitable driver class configure a DataSource: ‘url‘
Springboot用JUnit测试接口时报错Failed to determine a suitable driver class configure a DataSource: ‘url‘
150 0
|
Java 数据库连接 Redis
Bean method ‘redisConnectionFactory‘ not loaded because @ConditionalOnClass did not find required c
Bean method ‘redisConnectionFactory‘ not loaded because @ConditionalOnClass did not find required c
134 0
|
XML 前端开发 Java
SpringMVC中context:annotation-config与mvc:annotation-driven和context:component-scan区别详解
SpringMVC中context:annotation-config与mvc:annotation-driven和context:component-scan区别详解
73 0
|
Java Spring
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
275 0
|
druid
A bean with that name has already been defined in class path resource and overriding is disabled.
A bean with that name has already been defined in class path resource and overriding is disabled.
238 0
|
Java 测试技术 Spring
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
878 0
|
XML Java 数据库连接
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
392 0
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
|
Nacos
Nacos报错:Error creating bean with name ‘authFilterRegistration‘ defined in class path resource
Nacos报错:Error creating bean with name ‘authFilterRegistration‘ defined in class path resource
501 0
|
Java API Spring
A component required a bean named xxx that could not be found
A component required a bean named xxx that could not be found
A component required a bean named xxx that could not be found