springboot 按钮权限验证_springboot+spring security 权限验证

ps:度娘是万能的,还是做下笔记

springboot进坑请移步大神博客胡小海丶

基于springboot做security权限验证

org.springframework.boot

spring-boot-starter-parent

1.4.5.RELEASE

1.不多说先导包:pom.xml

org.springframework.boot

spring-boot-starter-security

org.springframework.security

spring-security-taglibs

2.java注解配置:SecurityConfig.java

@EnableWebSecurity()

public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override

protected void configure(HttpSecurity http) throws Exception {

/**

* .anyRequest() :全部拦截:配置权限

*/

http.authorizeRequests().anyRequest().hasRole("USER")//权限ROLE_USER

.and().formLogin().loginPage("/loginPage")//登录页面

.loginProcessingUrl("/login")//登录请求(自带)

.defaultSuccessUrl("/")//成功之后

.failureUrl("/loginPage")//失败之后

.permitAll()

.and().exceptionHandling().accessDeniedPage("/accessdenied")//没有权限的页面

.and().logout().logoutUrl("/logout")//登出(自带)

.logoutSuccessUrl("/loginPage").invalidateHttpSession(true)//登出之后的页面和清楚session

http.rememberMe()//基于token的remember-me的认证

.tokenValiditySeconds(604800);//token过期时间

http.headers().frameOptions()//请求头

.sameOrigin();//响应头

}

@Override

protected void configure(AuthenticationManagerBuilder auth) throws Exception {

auth

.inMemoryAuthentication()

.withUser("admin")//用户名:admin

.password("123456")//密码:12346

.roles("USER");//权限ROLE_USER

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值