有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java蚂蚁模式配置

我有这个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);
    }
}

现在我想在我的项目中加入炫耀。我配置了一个大摇大摆的控制器:

@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登录。 我尝试了这个(注意,我为招摇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) 个答案