[英]EL1057E: No bean resolver registered in the context to resolve access to bean
I am using this resource server for authorizing request but whenever it tries to evaluate expression-"@ipWhitelistingProvider.isItValid(request)" it gives error stating- EL1057E: No bean resolver registered in the context to resolve access to bean 'ipWhitelistingProvider'.我正在使用此资源服务器来授权请求,但每当它尝试评估表达式-“@ipWhitelistingProvider.isItValid(request)”时,它会给出错误说明 - EL1057E:在上下文中没有注册 bean 解析器来解析对 bean 'ipWhitelistingProvider' 的访问。
@Profile("default")
@EnableResourceServer
@EnableWebSecurity
@Configuration
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Autowired
IpWhitelistingProvider ipWhitelistingProvider;
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/config/**").access("@ipWhitelistingProvider.isItValid(request) or #oauth2.hasScope('config')")
.anyRequest().authenticated()
.and().csrf().disable();
}
@Component("ipWhitelistingProvider")
public class IpWhitelistingProvider{
@Value("${ip.whitelist:1}")
List<String>whitelist;
String ipAcessWhitelistingString;
public boolean isItValid(HttpServletRequest request) {
String ip=request.getRemoteAddr();
if(whitelist.contains(ip)) {
return true;
}
else {
return false;
}
}
}
I managed to workaround this issue by doing the following: My default OAuth2 Expression Handler's Bean Resolver was null, so I added a @Bean with OAuth2WebSecurityExpressionHandler that explicitly sets the application context.我通过执行以下操作设法解决了这个问题:我的默认 OAuth2 表达式处理程序的 Bean 解析器是 null,所以我添加了一个带有显式设置应用程序上下文的 OAuth2WebSecurityExpressionHandler 的 @Bean。
@Bean
public OAuth2WebSecurityExpressionHandler oAuth2WebSecurityExpressionHandler(ApplicationContext applicationContext) {
OAuth2WebSecurityExpressionHandler expressionHandler = new OAuth2WebSecurityExpressionHandler();
expressionHandler.setApplicationContext(applicationContext);
return expressionHandler;
}
In my ResourceServerConfigurerAdapter, I configured resources and passed above bean在我的 ResourceServerConfigurerAdapter 中,我配置了资源并通过了上面的 bean
@Autowired
private OAuth2WebSecurityExpressionHandler expressionHandler;
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.expressionHandler(expressionHandler);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.