Spring Security 数据库安全认证

本文详细介绍了如何在SpringBoot 2.1.3.RELEASE中集成MyBatis和Thymeleaf,包括maven依赖配置、数据库连接设置、安全配置及代码示例。项目采用多模块结构,通过GitHub链接提供了完整的代码,重点讲解了WebSecurityConfigurerAdapter接口的实现,以解决页面框架和表单标签的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringBoot 2.1.3.RELEASE

maven引入的jar

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

数据库一共6张表,其中有个表还没什么用

user---userRole---role--rolePermission---permission

dao层使用springboot-mybatis的注解开发

代码感觉有点多,放起来篇幅太长了,所以代码都在github上  https://github.com/weisfds/SpringBootDemo

注意该github上面项目是多模块的。

注意些地方

1,WebSecurityConfigurerAdapter 接口的实现类实现了configure(HttpSecurity http)里面有段代码

headers().frameOptions().disable().// 解决页面框架不能获取子页面
                and().

这是解决html <fromset>标签不能出现效果的,没有的话可以去掉

2,WebSecurityConfigurerAdapter接口的实现类实现了configure(AuthenticationManagerBuilder auth),里面主要是如果用户密码有加密,如md5等,encode(CharSequence charSequence)方法使用来对密码解密的,然后返回解密密码,但是不知为何只输出了userNotFoundPassword,matches(CharSequence charSequence, String s)进行输入密码和解密密码进行比较的,返回true才能登陆成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值