package com.java1234.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * spring security配置
 * @author user
 *
 */
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)//开启security注解
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{

	/**
	 * 	请求授权
	 */
	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http.csrf().disable().cors().disable().headers().disable()
				.authorizeRequests()
                .antMatchers("/","/film/**","/webSite/**","/webSiteInfo/**","/aboutMe","/static/**").permitAll()
                //其他地址的访问均需验证权限
                .anyRequest().authenticated()
                .and()
                .formLogin()
                //指定登录页是"/login"
                .loginPage("/login")
                .defaultSuccessUrl("/admin")//登录成功后默认跳转到"/hello"
                .permitAll()
                .and()
                .logout()
                .logoutSuccessUrl("/login")//退出登录后的默认url是"/home"
                .permitAll();
	}

	/**
	 * 用户认证
	 */
	@Override
	protected void configure(AuthenticationManagerBuilder auth) throws Exception {
		auth
			.inMemoryAuthentication()
			.withUser("java1234")
			.password("123456")
			.roles("ADMIN");
	}
	
	

	
	
}
最近下载更多
admin_z  LV22 2023年12月26日
huyuxin  LV3 2023年12月10日
chj173  LV1 2023年5月30日
qiangmin1223  LV12 2023年4月22日
计算机暴龙战士  LV19 2023年4月2日
admin115  LV6 2022年11月19日
1025490081  LV2 2022年11月7日
testuser1234567  LV24 2022年6月30日
877549024  LV8 2022年4月21日
AlanLi  LV19 2022年4月8日
最近浏览更多
yyhrhv  LV8 2024年9月3日
wyyz5211314  LV4 2024年4月23日
暂无贡献等级
微信网友_6927932988952576  LV12 2024年3月31日
Denck1111 2024年3月27日
暂无贡献等级
zolscy  LV24 2024年3月24日
ming_123_9715  LV23 2024年3月8日
暂无贡献等级
fzlzxc  LV10 2024年1月23日
小草12345 2023年12月26日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友