need spring security java config example showing basic auth only

后端 未结 2 800
你的背包
你的背包 2020-12-20 15:55

My current java security config looks as follows:

@Configuration
@EnableWebSecurity
public class RootConfig extends WebSecurityConfigurerAdapter {

@Override         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 16:21

    UPDATE: This is fixed in Spring Security 3.2.0.RC1+

    This is a bug in the Security Java Configuration that will be resolved for the next release. I have created SEC-2198 to track it. For now, a work around is to use something like the following:

    @Bean
    public BasicAuthenticationEntryPoint entryPoint() {
        BasicAuthenticationEntryPoint basicAuthEntryPoint = new BasicAuthenticationEntryPoint();
        basicAuthEntryPoint.setRealmName("My Realm");
        return basicAuthEntryPoint;
    }
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
    
        http
            .exceptionHandling()
                .authenticationEntryPoint(entryPoint())
                .and()
            .authorizeUrls()
                .anyRequest().authenticated()
                .and()
            .httpBasic();       
    }
    

    PS: Thanks for giving Spring Security Java Configuration a try! Keep the feedback up :)

提交回复
热议问题