Narendra :
I am learning Spring Boot. I created an sample Spring Boot Web Application with Spring Boot security and it is working perfectly.
Now I want to add Rest Webservices functionality in same web application.
ISSUE:
When i am trying to access any API, in response I am getting login.jsp .
Requirement: I want JSON respnse authentication and authorization not required.
What changes i need to do to achieve this.
WebSecurityConfig :
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Qualifier("userDetailsServiceImpl") <br>
@Autowired <br>
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**", "/registration").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Bean
public AuthenticationManager customAuthenticationManager() throws Exception {
return authenticationManager();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
}
}
Dickens A S :
Add that path to antMatchers
to permitAll,
antMatchers("/resources/**", "/registration", "/api/user/**").permitAll()
this will disable security for that URL
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=409456&siteId=1