Skip to content

Instantly share code, notes, and snippets.

@mdagis
Last active January 22, 2018 22:29
Show Gist options
  • Save mdagis/c079c04b457750550631 to your computer and use it in GitHub Desktop.
Save mdagis/c079c04b457750550631 to your computer and use it in GitHub Desktop.
WebSecurityConfig for CORS Spring Boot
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/*").permitAll()
.antMatchers("/*").hasRole("USER")
.and()
.httpBasic();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("1111").roles("USER");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment