你知道我的spring安全配置有什么问题吗?

问题描述 投票:0回答:1

我需要验证所有从 "apiauth "开始的请求,除了 "apiauthlogin "和 "apiauthtokenrefresh"。这是我的安全配置方法。问题是,它并没有按照预期工作。它检查 "apiauthtokenrefresh "的认证,即使我给它分配了 permitAll。




    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/api/auth/login").antMatcher("/api/auth/token/refresh")
                .antMatcher("/api/auth/**")
                .antMatcher("/api/**");
        http
                .cors()
                .and()
                .csrf()
                .disable()
                .exceptionHandling()
                .authenticationEntryPoint(unauthorizedHandler)
                .and()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                .antMatchers(AUTH_WHITELIST)
                .permitAll()
                .antMatchers("/api/auth/login","/api/auth/token/refresh").permitAll()
                .antMatchers("/api/auth/**").authenticated()
                .antMatchers("/api/**").permitAll()
                .anyRequest()
                .permitAll();

        // Add our custom JWT security filter
        http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);

    }

java spring api security authentication
1个回答
1
投票

删除前3行代码。

Javadoc的 antMatcher(String) 说。

Invoking antMatcher(String)凌驾于...之上 以前调用[...]。antMatcher(String), [...].

调用4次并不像你想的那样。

© www.soinside.com 2019 - 2024. All rights reserved.