M
M
maxvinogradov2021-08-19 15:42:01
Java
maxvinogradov, 2021-08-19 15:42:01

Why does Spring Security refuse to let in despite permitall()?

I want authorization to be required only for the url where the word admin occurs. Now gives error Unauthorized everywhere.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .csrf().disable()
            .httpBasic()
            .and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
            .headers().frameOptions().disable()
            .and()
            .authorizeRequests()
            .antMatchers("**/admin/**").hasRole(Role.ADMIN.getAuthority())
            .anyRequest().permitAll();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-08-19
@maxvinogradov

I would try to do the following:
1) change the url and try again. For example, /admin/**
2) also try to debug the project. For example, what returns:
Role.ADMIN.getAuthority()and what is expected as input

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question