मैंने स्प्रिंग सिक्योरिटी के साथ अपने स्प्रिंग बूट एप्लिकेशन में प्रमाणीकरण लागू किया है।स्प्रिंग बूट एप्लिकेशन में स्प्रिंग सिक्योरिटी को कैसे बंद करें
मुख्य वर्ग को नियंत्रित करने प्रमाणीकरण websecurityconfig किया जाना चाहिए:
@Configuration
@EnableWebSecurity
@PropertySource(value = { "classpath:/config/application.properties" })
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private RestAuthenticationSuccessHandler authenticationSuccessHandler;
@Autowired
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.and()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(
SessionCreationPolicy.STATELESS)
.and()
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/logout").permitAll()
.antMatchers("/ristore/**").authenticated()
.anyRequest().authenticated()
.and()
.formLogin()
.successHandler(authenticationSuccessHandler)
.failureHandler(new SimpleUrlAuthenticationFailureHandler());
}
जब से मैं OAuth कर रहा हूँ, मैं AuthServerConfig
और ResourceServerConfig
भी है। मेरा मुख्य आवेदन वर्ग इस तरह दिखता है:
@SpringBootApplication
@EnableSpringDataWebSupport
@EntityScan({"org.mdacc.ristore.fm.models"})
public class RistoreWebApplication extends SpringBootServletInitializer
{
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*");
}
};
}
public static void main(String[] args)
{
SpringApplication.run(RistoreWebApplication.class, args);
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RistoreWebApplication.class);
}
}
जब से हम कोड समेकन कर रहे हैं, हम प्रमाणीकरण को बंद करना अस्थायी रूप से की जरूरत है। हालांकि, मैंने निम्नलिखित विधियों का प्रयास किया और कुछ भी काम नहीं करता है। मुझे अभी भी 401 मिल रहा है जब मैंने इन बाकी एपीआई यूआरएल को मारा।
टिप्पणी बाहर
@Configuration
,@EnableWebSecurity
सहित सुरक्षा से संबंधित कक्षाओं में सभी एनोटेशन। Spring boot Security Disable security में, नीचे दिया गया था@EnableWebSecurity
जोड़ने के लिए सुझाव दिया गया था जो मुझे लगता है कि कोई समझ नहीं आता है। वैसे भी कोशिश की, काम नहीं किया।संशोधित websecurityconfig सभी सुरक्षा सामान को दूर करने और से केवल
http .authorizeRequests() .anyRequest().permitAll();
Disable Basic Authentication while using Spring Security Java configuration है। या तो मदद नहीं करता है।
निकालें सुरक्षा ऑटो config
@EnableAutoConfiguration (को बाहर = { org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class, org.springframework.boot। actuate.autoconfigure.ManagementSecurityAutoConfiguration.class})
क्या वे disabling spring security in spring boot app में किया था की तरह। हालांकि मुझे लगता है कि यह सुविधा केवल spring-boot-actuator
के साथ काम करती है जो मेरे पास नहीं है। तो यह कोशिश नहीं की।
वसंत सुरक्षा अक्षम करने का सही तरीका क्या है?
'जोड़ना @ EnableWebSecurity' को निष्क्रिय स्प्रिंग बूट सुरक्षा ऑटो विन्यास। आपके मामले में, आपके पास पहले से ही यह एनोटेशन है ताकि आप ऑटो कॉन्फ़िगरेशन का लाभ उठा सकें। मैं सुझाव देता हूं कि आपकी कक्षा से '@ EnableWebSecurity' को टिप्पणी करने का प्रयास करें और ऑटो कॉन्फ़िगरेशन से' SecurityAutoConfiguration.class' को बाहर निकालें। –
@MaciejWalkowiak क्या मुझे एप्लिकेशन क्लास में SecurityAutoConfiguration.class को बहिष्कृत करना चाहिए? – ddd
[इस] पर एक नज़र डालें (https://stackoverflow.com/questions/25639188/disable-basic- प्रमाणीकरण- दौरान-using-spring-security-java-configuration#25740336) – rocksteady