Created
January 28, 2019 18:43
-
-
Save tsurdilo/5ea1c2066fd982d2b360872d977cf3a6 to your computer and use it in GitHub Desktop.
DefaultWebSecurityConfig with CORS enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.kie; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
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; | |
import org.springframework.web.cors.CorsConfiguration; | |
import org.springframework.web.cors.CorsConfigurationSource; | |
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | |
@Configuration("kieServerSecurity") | |
@EnableWebSecurity | |
public class DefaultWebSecurityConfig extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http | |
.cors().and() | |
.csrf().disable() | |
.authorizeRequests() | |
.antMatchers("/rest/*").authenticated() | |
.and() | |
.httpBasic(); | |
} | |
@Autowired | |
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { | |
auth.inMemoryAuthentication().withUser("user").password("user").roles("kie-server"); | |
auth.inMemoryAuthentication().withUser("wbadmin").password("wbadmin").roles("admin"); | |
auth.inMemoryAuthentication().withUser("kieserver").password("kieserver1!").roles("kie-server"); | |
} | |
@Bean | |
CorsConfigurationSource corsConfigurationSource() { | |
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | |
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues()); | |
return source; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment