我有这个Spring配置和OAuth2:
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
private static final String RESOURCE_ID = "resource-server-rest-api";
private static final String SECURED_READ_SCOPE = "#oauth2.hasScope('read')";
private static final String SECURED_WRITE_SCOPE = "#oauth2.hasScope('write')";
private static final String SECURED_PATTERN = "/api/**";
private static final String PUBLIC_PATTERN = "/api/*/public/**";
@Override
public void configure(ResourceServerSecurityConfigurer resources) {
resources.resourceId(RESOURCE_ID);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.cors()
.and()
.anonymous()
.and()
.requestMatchers()
.antMatchers(SECURED_PATTERN)
.and().authorizeRequests()
.antMatchers(PUBLIC_PATTERN).permitAll()
.antMatchers(HttpMethod.POST, SECURED_PATTERN).access(SECURED_WRITE_SCOPE)
.anyRequest().access(SECURED_READ_SCOPE);
}
}
现在,我想将Swagger添加到我的项目中。我配置了SwaggerController:
@Controller //note - this is a spring-boot controller, not @RestController
public class SwaggerController {
public static final String SWAGGER_URL = "/api/v1/public/swagger/docs";
public static final String SWAGGER_HTML = "/swagger-ui.html";
@RequestMapping(SWAGGER_URL)
public String home() {
return "redirect:" + SWAGGER_HTML;
}
}
问题是我无法使“ /swagger-ui.html”路径不触发Spring登录。 我尝试了这一点(请注意,我为Swagger html添加了antMatchers):
@Override
public void configure(HttpSecurity http) throws Exception {
http
...
.and().authorizeRequests()
.antMatchers(PUBLIC_PATTERN).permitAll()
.antMatchers("/swagger-ui.htm").permitAll()// No authentication
... }
但是没有用。 我该如何配置HttpSecurity?
答案 0 :(得分:0)
那么招摇的主页应该重定向到/swagger-ui.html
吗?
如果是,则在配置HttpSecurity
时出现错字,仅键入 htm 。因此更改为:
.antMatchers("/swagger-ui.html").permitAll()
另一方面,如果招摇的首页是/swagger-ui.htm
。然后,将控制器中的SWAGGER_HTML
更改为:
public static final String SWAGGER_HTML = "/swagger-ui.htm";
答案 1 :(得分:0)
添加此替代项:
plot(df3$Date1, df3$Price1, type='l', col='blue', ylim = c(0, max(df3$Price2, na.rm = TRUE)))
lines(df3$Date1, df3$Price2, col='red')