spring cloud 认证授权代码段

本文详细解析了Spring Security配置代码,介绍了如何设置资源访问权限,实现登录与注销功能,并禁用CSRF保护,适用于需要深入理解Spring Security配置机制的开发者。
 protected void configure(HttpSecurity http) throws Exception {
//        http.httpBasic()
//            .and().csrf().disable()
//            .authorizeRequests()
//            	.antMatchers("/","/login").permitAll()
//            	.anyRequest().authenticated()
//            	.and()
//            .formLogin()
//            	//.loginPage("/login")
//            	.permitAll()
//            	.and()
//            .logout().permitAll();
    	// 硬编码形式白名单
    			http
    			.authorizeRequests()
    			.antMatchers(
    					StaticParams.PATHREGX.API, 
    					StaticParams.PATHREGX.CSS,
    					StaticParams.PATHREGX.JS,
    					StaticParams.PATHREGX.IMG).permitAll()//允许用户任意访问
    					.anyRequest().authenticated()//其余所有请求都需要认证后才可访问
    			.and()
    			.formLogin()
    				//.loginPage("/login/login.do")  //这里不适用自定义的页面,使用springsecurity 默认提供的页面
//    				.defaultSuccessUrl("/hello2")
    			.permitAll();//允许用户任意访问

    			http.csrf().disable();
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值