WebSecurityConfig.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.yihu.wlyy.statistics.config;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  6. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  7. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  8. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  9. /**
  10. * Created by Administrator on 2016.10.17.
  11. */
  12. @Configuration
  13. @EnableWebSecurity
  14. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  15. @Value("${security.basic.username}")
  16. String username;
  17. @Value("${security.basic.password}")
  18. String password;
  19. protected void configure(HttpSecurity http) throws Exception {
  20. http.authorizeRequests()
  21. .antMatchers("/metrics/**").permitAll()
  22. .antMatchers("/health/**").permitAll()
  23. .antMatchers("/env/**").permitAll()
  24. .antMatchers("/dump/**").permitAll()
  25. .antMatchers("/trace/**").permitAll()
  26. .antMatchers("/mappings/**").permitAll()
  27. .antMatchers("/actuator/**").permitAll()
  28. .antMatchers("/beans/**").permitAll()
  29. .antMatchers("/configprops/**").permitAll()
  30. .antMatchers("/docs/**").permitAll()
  31. .antMatchers("/info/**").permitAll()
  32. .antMatchers("/configuration/**").permitAll()
  33. .antMatchers("/jolokia/**").permitAll()
  34. .anyRequest().authenticated()
  35. .and()
  36. .csrf().disable()
  37. .formLogin().defaultSuccessUrl("/swagger-ui.html").failureUrl("/login") //登录成功之后的跳转
  38. .permitAll()
  39. .and()
  40. .logout().logoutSuccessUrl("/login")
  41. .permitAll();
  42. }
  43. @Autowired
  44. public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  45. auth.inMemoryAuthentication()
  46. .withUser(username).password(password).roles("USER");
  47. }
  48. }