में स्प्रिंग के लॉगिन/लॉगआउट एपीआई को दस्तावेज करना मैं Spring Boot
का उपयोग कर डेमो रीस्ट सेवा विकसित कर रहा हूं जहां उपयोगकर्ता को संचालन के कुछ सबसेट करने के लिए लॉगिन करना है। Swagger UI
जोड़ने के बाद (springfox
लाइब्रेरी का उपयोग) है कि सरल विन्यास के साथ:स्वैगर
@Bean
public Docket docApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(any())
.paths(PathSelectors.ant("/api/**"))
.build()
.pathMapping("/")
.apiInfo(apiInfo())
.directModelSubstitute(LocalDate.class, String.class)
.useDefaultResponseMessages(true)
.enableUrlTemplating(true);
}
मैं Swagger UI
पृष्ठ पर सूचीबद्ध सभी कार्यों के साथ सभी API के साथ खत्म। दुर्भाग्यवश मेरे पास सूचीबद्ध लॉगिन/लॉगआउट एंडपॉइंट्स नहीं हैं।
समस्या यह है कि उस परिचालन का हिस्सा Swagger UI
अंतर्निहित रूप (मुझे यह वास्तव में अच्छी सुविधा मिलती है और इसे काम करना चाहती है) के माध्यम से नहीं किया जा सकता है, क्योंकि उपयोगकर्ता लॉग इन नहीं है। क्या उस समस्या का कोई समाधान है ? क्या मैं Swagger
में मैन्युअल रूप से कुछ अंतराल परिभाषित कर सकता हूं?
यदि प्रमाण पत्र जमा करने के लिए कोई फॉर्म था (यानी लॉगिन/लॉगआउट एंडपॉइंट्स) मैं उस सुरक्षित अंतराल का उपयोग करने से पहले प्राधिकरण कर सकता था। फिर, Swagger
उपयोगकर्ता प्रतिक्रिया से token/sessionid
निकाल सकता है और इसे @ApiImplicitParams
के माध्यम से परिभाषित कस्टम क्वेरी पैरामीटर पर पेस्ट कर सकता है।
नीचे आप मेरी सुरक्षा विन्यास पा सकते हैं: पार्टी के लिए
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginProcessingUrl("/api/login")
.usernameParameter("username")
.passwordParameter("password")
.successHandler(new CustomAuthenticationSuccessHandler())
.failureHandler(new CustomAuthenticationFailureHandler())
.permitAll()
.and()
.logout()
.logoutUrl("/api/logout")
.logoutSuccessHandler(new CustomLogoutSuccessHandler())
.deleteCookies("JSESSIONID")
.permitAll()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(new CustomAuthenticationEntryPoint())
.and()
.authorizeRequests()
.and()
.headers()
.frameOptions()
.disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}