Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring引导管理安全性与端口集的工作方式不同_Spring_Spring Boot - Fatal编程技术网

Spring引导管理安全性与端口集的工作方式不同

Spring引导管理安全性与端口集的工作方式不同,spring,spring-boot,Spring,Spring Boot,我正在尝试配置一个支持执行器的Spring引导应用程序(1.2.3,但在1.2.4.BUILD-SNAPSHOT版本中也失败)。我想使用Actuator安全配置来控制对管理端点的访问,以及我们自己对应用程序其余部分的身份验证 这是我的安全配置: @Configuration @EnableWebSecurity @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class SecurityConfiguration extends W

我正在尝试配置一个支持执行器的Spring引导应用程序(1.2.3,但在1.2.4.BUILD-SNAPSHOT版本中也失败)。我想使用Actuator安全配置来控制对管理端点的访问,以及我们自己对应用程序其余部分的身份验证

这是我的安全配置:

@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter
{

    @Autowired
    private CustomAuthenticationProvider customAuthProvider;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        auth.authenticationProvider(customAuthProvider);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        http
            .authorizeRequests()
            .regexMatchers(API_DOC_REGEX).permitAll()
            .regexMatchers(String.format(PATH_REGEX, PUBLIC_ACCESS)).permitAll()
            .regexMatchers(String.format(PATH_REGEX, INTERNAL_ACCESS)).access("isAuthenticated() && authentication.hasOrigin('INTERNAL')")
            .regexMatchers(String.format(PATH_REGEX, EXTERNAL_AUTHENTICATED_ACCESS)).authenticated()
            .antMatchers("/**").denyAll()
            .and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
            .and()
            .addFilterAfter(customAuthProcessingFilter(), BasicAuthenticationFilter.class)
            .csrf().disable();
    }

}
当我没有设置管理端口时,这可以正常工作,但是当我设置管理端口时,管理URL返回401响应。如果我注释掉行
.antMatchers(“/**”).denyAll()
,那么一切都会顺利进行,根本不需要验证。因此,当我设置自定义端口时,它似乎正在使用我的应用程序的安全配置作为执行器端点,但我不知道为什么


在自定义端口上运行时,如何让它使用自己的安全性?

扩展来自的注释,为管理内容添加另一个适配器(即使它已经有一个适配器)似乎已经修复了它。这是我最后的课程:

@Order(0)
@Configuration
public class ManagementSecurityConfig extends WebSecurityConfigurerAdapter
{

    @Autowired
    ManagementServerProperties managementProperties;

    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        http
                .requestMatchers()
                .requestMatchers(new RequestMatcher()
                {

                    @Override
                    public boolean matches(HttpServletRequest request)
                    {
                        return managementProperties.getContextPath().equals(request.getContextPath());
                    }
                })
                .and()
                .authorizeRequests()
                .anyRequest().hasRole("ADMIN")
                .and()
                .httpBasic();
    }
}

添加另一个
websecurityConfigureAdapter
,它具有
@顺序(ManagementServerProperties.ACCESS\u OVERRIDE\u Order)
,如中所述,看起来这就是我正在做的事情?文件中说,可以使用外部属性(management.security.*)修改致动器的安全功能。要覆盖应用程序访问规则,请添加WebSecurityConfigureAdapter类型的@Bean,如果不想覆盖执行器访问规则,请使用@Order(SecurityProperties.access\u override\u Order)或@Order(ManagementServerProperties.access\u override\u Order)如果您确实想覆盖致动器访问规则。否,您是在配置一般应用规则,而不是管理规则。