शायद मैं यहां कुछ गलत कर रहा हूं, मैं बस यह नहीं समझ सकता कि ...स्प्रिंग बूट हेल्थ एंडपॉइंट पर अनाम पहुंच को पुनः सक्षम कैसे करें?
मेरे पास एक ही एप्लिकेशन के भीतर एक Oauth2 प्रमाणीकरण सर्वर और संसाधन सर्वर है।
संसाधन सर्वर विन्यास:
@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER-1)
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
public static final String RESOURCE_ID = "resources";
@Override
public void configure(final ResourceServerSecurityConfigurer resources) {
resources
.resourceId(RESOURCE_ID);
}
@Override
public void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/**").access("#oauth2.hasScope('read')")
.antMatchers(HttpMethod.POST, "/**").access("#oauth2.hasScope('write')")
.antMatchers(HttpMethod.PUT, "/**").access("#oauth2.hasScope('write')")
.antMatchers(HttpMethod.PATCH, "/**").access("#oauth2.hasScope('write')")
.antMatchers(HttpMethod.DELETE, "/**").access("#oauth2.hasScope('write')")
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
.antMatchers(HttpMethod.GET, "/health").permitAll();
}
}
प्रमाणीकरण सर्वर विन्यास:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Override
public void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(new BCryptPasswordEncoder());
}
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and().httpBasic().realmName("OAuth Server");
}
}
जब मैं पहुँच/स्वास्थ्य के लिए प्रयास करते हैं, मैं एक HTTP/1.1 401 अनधिकृत मिला है।
मैं स्प्रिंग बूट को कैसे/अज्ञात रूप से सुलभ बनाने के लिए राजी कर सकता हूं?
सुरक्षा में कॉन्फिग मुझे लगता है कि आप इसे जोड़ने में चूक जाते हैं: .antMatchers (HttpMethod.GET, "/ health")। PermitAll(); – mherbert
जिस क्रम में आप अपनी मैपिंग निर्दिष्ट करते हैं वह वह क्रम भी है जिसमें उनका परामर्श किया जाता है। पहला मैच जीतता है ... '/ **' के रूप में आपके '/ स्वास्थ्य' मैपिंग सबकुछ बेकार है। इसे कार्यान्वित करने के लिए '/ **' मैपिंग के ऊपर ले जाएं। –
@ एम। डीनियम धन्यवाद, जिसने समस्या हल की। यदि आप इसे एक उत्तर के रूप में जोड़ते हैं, तो मुझे इसे स्वीकार करने में खुशी होगी। – endrec