Error in spring security configuration class

In my spring application, I am using spring 4.0.4 and spring Security 3.2.3. I copied this code directly from the tutorial on the sprin website, but I have a compilation problem because the method registerAuthenticationcannot be reevaluated from the class WebSecurityConfigurerAdapter, and the class HttpSecuritydoes not have a method authorizeUrls, Do I have a bank? Or is it a version?

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("letsnosh").password("noshing").roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeUrls()
                .antMatchers("/order/**").hasRole("USER")
                .antMatchers("/checkout").hasRole("USER")
                .anyRequest().anonymous()
                .and()
                //This will generate a login form if none is supplied.
                .formLogin();
    }

    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
}
+4
source share
5 answers

It looks like it's now .authorizeRequests()from 3.2.0.RC1 . See https://jira.spring.io/browse/SEC-2202

+4
source

now this .authorizeRequests()

+1
source

, . , spring -security-web spring -security-config ? ( maven).

<!-- Spring security -->
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
</dependency>
0

gradle,

compile 'org.springframework.security:spring-security-web:3.2.0.M2'
compile 'org.springframework.security:spring-security-core:3.2.0.M2'
compile 'org.springframework.security:spring-security-config:3.2.0.M2'

, .

, , .anyRequest().anonymous() , , , . , , .

0

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().withUser("letsnosh").password("noshing").roles("USER");
}
0

Source: https://habr.com/ru/post/1540103/


All Articles