Last active
December 30, 2019 15:24
-
-
Save wkorando/14ea4640d547499c182ec468dbf41c52 to your computer and use it in GitHub Desktop.
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
@Configuration | |
@EnableConfigurationProperties({ CommandLineSecurityConfigurer.class }) | |
@ConditionalOnNotWebApplication | |
public class NonWebSecurityConfig { | |
@Bean | |
public GrantedAuthority createGrantedAuthority(CommandLineSecurityConfigurer cliSecurityConfigurer) { | |
return new SimpleGrantedAuthority("ROLE_" + cliSecurityConfigurer.getRequiredRole()); | |
} | |
} |
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
@Configuration | |
@ConditionalOnWebApplication | |
@EnableConfigurationProperties({WebSecurityConfigurer.class}) | |
@EnableWebSecurity | |
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | |
@Autowired | |
private WebSecurityConfigurer webSecurityConfigurer; | |
@Override | |
protected void configure(final HttpSecurity http) throws Exception { | |
http | |
.csrf().disable() | |
.authorizeRequests() | |
.antMatchers(webSecurityConfigurer.getAdminEndpoints()).hasRole("ADMIN") | |
.antMatchers(webSecurityConfigurer.getUserEndpoints()).hasRole("USER") | |
.antMatchers(webSecurityConfigurer.getUnsecuredEndpoints()).permitAll() | |
.antMatchers("/login*").permitAll() | |
.anyRequest().authenticated() | |
.and() | |
.formLogin(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment