栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

29-SpringBoot 安全与SpringSecurity

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

29-SpringBoot 安全与SpringSecurity

相关概念

Spring Security是针对Spring项目的安全框架,也是Spring Boot底层安全模块默认的技术选型。他可以实现强大的web安全控制。对于安全控制,我们仅需引入spring-boot-starter-security模块,进行少量的配置,即可实现强大的
安全管理。

几个类:
WebSecurityConfigurerAdapter:自定义Security策略
AuthenticationManagerBuilder:自定义认证策略
@EnableWebSecurity:开启WebSecurity模式

• 应用程序的两个主要区域是“认证”和“授权”(或者访问控制)。这两个主要区域是Spring Security 的两个目标。

• “认证”(Authentication),是建立一个他声明的主体的过程(一个“主体”一般是指用户,设备或一些可以在你的应用程序中执行动作的其他系统)。

• “授权”(Authorization)指确定一个主体是否允许在你的应用程序执行一个动作的过程。为了抵达需要授权的店,主体的身份已经有认证过程建立。

• 这个概念是通用的而不只在Spring Security中。

1.添加依赖
 
            org.thymeleaf.extras
            thymeleaf-extras-springsecurity5
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-security
        
2.后端代码

MySecurityConfig

package com.limi.springboottest2.config;

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;



@EnableWebSecurity
public class MySecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //super.configure(http);
        //定制请求的授权规则
        http.authorizeRequests().antMatchers("/").permitAll()
                .antMatchers("/level1
    @GetMapping("/")
    public String index() {
        return "welcome";
    }

    
    @GetMapping("/userlogin")
    public String loginPage() {
        return PREFIX+"login";
    }


    
    @GetMapping("/level1/{path}")
    public String level1(@PathVariable("path")String path) {
        return PREFIX+"level1/"+path;
    }

    
    @GetMapping("/level2/{path}")
    public String level2(@PathVariable("path")String path) {
        return PREFIX+"level2/"+path;
    }

    
    @GetMapping("/level3/{path}")
    public String level3(@PathVariable("path")String path) {
        return PREFIX+"level3/"+path;
    }

}

3.前端代码

welcome.html





Insert title here


欢迎光临武林秘籍管理系统

游客您好,如果想查看武林秘籍 请登录

,您好,您的角色有:


普通武功秘籍

高级武功秘籍

login.html





Insert title here


	

欢迎登陆武林秘籍管理系统


用户名:
密码:
记住我
1.level1

1.html





Insert title here


	返回
	

罗汉拳

罗汉拳站当央,打起来不要慌

2.html





Insert title here


	返回
	

武当长拳

长一点在长一点

3.html





Insert title here


	返回
	

全真剑法

全都是真的

2.level2

1.html





Insert title here


	返回
	

太极拳

一个西瓜圆又圆 劈它一刀成两半 你一半来 给你你不要 给他他不收 那就不给 把两人撵走 他们不走你走 走啦,一挥手,伤自尊 不买西瓜别缠我,缓慢纠缠様 两人缠我赖皮,手慢动作左右挥动 看我厉害,转头缓步拍苍蝇状 拍死了,手抱西瓜状+奥特曼十字手+广播操准备运动的站立

2.html





Insert title here


	返回
	

七伤拳

练这拳的人全都死了

3.html





Insert title here


	返回
	

梯云纵

踩自己的脚往上跳

3.level3

1.html





Insert title here


	返回
	

葵花宝典

欲练神功,挥刀自宫

2.html





Insert title here


	返回
	

龟派气功

龟-派-气-功-波

3.html





Insert title here


	返回
	

独孤九剑

欲练此剑,必先犯贱

4.测试


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1007322.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号