|
| 1 | +package info.xiaomo.security; |
| 2 | + |
| 3 | + |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; |
| 5 | +import org.springframework.boot.SpringApplication; |
| 6 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| 7 | +import org.springframework.boot.autoconfigure.domain.EntityScan; |
| 8 | +import org.springframework.context.annotation.ComponentScan; |
| 9 | +import org.springframework.context.annotation.Configuration; |
| 10 | +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
| 11 | +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
| 12 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 13 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
| 14 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
| 15 | + |
| 16 | +/** |
| 17 | + * 把今天最好的表现当作明天最新的起点..~ |
| 18 | + * いま 最高の表現 として 明日最新の始発..~ |
| 19 | + * Today the best performance as tomorrow newest starter! |
| 20 | + * Created by IntelliJ IDEA. |
| 21 | + * |
| 22 | + * @author: xiaomo |
| 23 | + * @github: https://github.com/qq83387856 |
| 24 | + * @email: hupengbest@163.com |
| 25 | + * @QQ_NO: 83387856 |
| 26 | + * @Date: 2016/4/1 15:38 |
| 27 | + * @Description: RabbitMq启动器 |
| 28 | + * @Copyright(©) 2015 by xiaomo. |
| 29 | + **/ |
| 30 | +@Configuration |
| 31 | +@EnableAutoConfiguration |
| 32 | +@ComponentScan("info.xiaomo") |
| 33 | +@EntityScan("info.xiaomo.*.model") |
| 34 | +@EnableJpaRepositories("info.xiaomo.*.dao") |
| 35 | +@EnableWebSecurity |
| 36 | +public class SecurityMain extends WebSecurityConfigurerAdapter { |
| 37 | + public static void main(String[] args) throws Exception { |
| 38 | + SpringApplication.run(SecurityMain.class, args); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + protected void configure(HttpSecurity http) throws Exception { |
| 43 | + http.authorizeRequests() |
| 44 | + .antMatchers("/", "/home").permitAll() |
| 45 | + .anyRequest().authenticated() |
| 46 | + .and() |
| 47 | + .formLogin() |
| 48 | + .loginPage("/login") |
| 49 | + .permitAll() |
| 50 | + .and() |
| 51 | + .logout() |
| 52 | + .permitAll(); |
| 53 | + } |
| 54 | + |
| 55 | + @Autowired |
| 56 | + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { |
| 57 | + auth.inMemoryAuthentication() |
| 58 | + .withUser("user").password("password").roles("USER"); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | +} |
0 commit comments