| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package cn.seecoder.paas.web;
- import cn.seecoder.paas.web.security.JwtAuthenticationTokenFilter;
- import cn.seecoder.paas.web.security.User;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.security.authentication.AuthenticationManager;
- 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.security.config.http.SessionCreationPolicy;
- import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
- @Configuration
- @EnableWebSecurity
- public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
- private final JwtAuthenticationTokenFilter filter;
- @Autowired
- public WebSecurityConfig(JwtAuthenticationTokenFilter filter) {
- super();
- this.filter = filter;
- }
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .cors()
- .and()
- .sessionManagement()
- .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
- .and()
- .addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class)
- .csrf().disable()
- .authorizeRequests()
- .antMatchers("/api/auth/**").permitAll()
- .antMatchers("/api/**").hasAuthority(User.ADMIN_AUTHORITY.getAuthority())
- .and();
- }
- @Bean
- @Override
- public AuthenticationManager authenticationManagerBean() throws Exception {
- return super.authenticationManagerBean();
- }
- }
|