content: package com.ctg.test.springbootauth.config;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  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.core.userdetails.User;
  import org.springframework.security.core.userdetails.UserDetailsService;
  import org.springframework.security.provisioning.InMemoryUserDetailsManager;
  
  /**
   * @Description: spring security配置
   * @Author: yanhonghai
   * @Date: 2019/4/18 0:38
   */
  @Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
      /**
       * 对应密码模式，内存中新建2个用户；实际用数据库查询
       *
       * @return
       */
      @Bean
      @Override
      protected UserDetailsService userDetailsService() {
          InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
          manager.createUser(User.withUsername("user_1").password("123456").authorities("USER").build());
          manager.createUser(User.withUsername("user_2").password("123456").authorities("USER").build());
          return manager;
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          // @formatter:off
          http
                  .requestMatchers().anyRequest()
                  .and()
                  .authorizeRequests()
                  .antMatchers("/oauth/*").permitAll();//生产token的url允许任何登录的用户访问
          // @formatter:on
      }
  }