[http URL的HTTP错误响应:401未经授权

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

无论何时使用以下方法,我都可以从角度调用服务

   @Override
    protected void configure(HttpSecurity http) throws Exception{
        http.csrf().disable().authorizeRequests().antMatchers("/").permitAll();
    }

但是当我按如下所示更改configure方法时,出现401错误。

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.csrf().disable()
                // dont authenticate this particular request
                .authorizeRequests().antMatchers("/authenticate", "/register","/basicauth").permitAll().
                // all other requests need to be authenticated
                        anyRequest().authenticated().and().
                // make sure we use stateless session; session won't be used to
                // store user's state.
                        exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        // Add a filter to validate the tokens with every request
        httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
    }

如何克服这个问题。

我的错误如下

enter image description here

java angular authentication spring-security http-status-code-401
1个回答
0
投票
您需要在antMatchers()中指定整个端点。据我所知,您要访问的URL是.../api/v1/basicauth =>将

/ basicauth字符串更改为/ api / v1 / basicauth

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