Security自定义逻辑认证(极简案例)

项目结构

在这里插入图片描述

config

SecurityConfig

package com.wunaiieq.tmp2024121105.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
//security的配置类
@Configuration
public class SecurityConfig {//密码默认加密,此处配置密码编码器,设置不解析密码@Beanpublic PasswordEncoder passwordEncoder(){return NoOpPasswordEncoder.getInstance();}
}

controller

没用过,sercurity会自动联网,使用一个登录页面
PageController

package com.wunaiieq.tmp2024121105.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class PageController {@RequestMapping("/{page}")public String showPage(@PathVariable String page){return page;}
}

entity

Users

package com.wunaiieq.tmp2024121105.entity;public class Users {private Integer id;private String username;private String password;private String phone;public Users() {}public Users(Integer id, String username, String password, String phone) {this.id = id;this.username = username;this.password = password;this.phone = phone;}@Overridepublic String toString() {return "Users{" +"id=" + id +", username='" + username + '\'' +", password='" + password + '\'' +", phone='" + phone + '\'' +'}';}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}
}

mapper

UsersMapper

package com.wunaiieq.tmp2024121105.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wunaiieq.tmp2024121105.entity.Users;public interface UsersMapper extends BaseMapper<Users> {
}

service

UserDetailService01

package com.wunaiieq.tmp2024121105.service;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wunaiieq.tmp2024121105.entity.Users;
import com.wunaiieq.tmp2024121105.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;@Service
public class UserDetailService01 implements UserDetailsService {@Autowiredprivate UsersMapper usersMapper;//自定义认证逻辑@Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {//1.查询条件QueryWrapper<Users> wrapper = new QueryWrapper<Users>().eq("username", username);//2.查询用户Users users =usersMapper.selectOne(wrapper);//3.封装为UserDetails对象UserDetails userDetails = User.withUsername(users.getUsername()).password(users.getPassword()).authorities("admin").build();//4.返回封装好的UserDetails对象return userDetails;}
}

启动类

package com.wunaiieq.tmp2024121105;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.wunaiieq.tmp2024121105.mapper")
public class Tmp2024121105Application {public static void main(String[] args) {SpringApplication.run(Tmp2024121105Application.class, args);}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/488311.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

docker安装ddns-go(外网连接局域网)

docker先下载镜像&#xff0c;目前最新版是v6.7.6 也可以csdn资源下载 再导入dockers https://download.csdn.net/download/u014756339/90096748 docker load -i ddns-go.tar 启动 docker run -d --name ddns-go --restartalways --nethost -v /opt/ddns-go:/root jeessy/…

技术速递|dotnet scaffold – .NET 的下一代内容创建

作者&#xff1a;Sayed Ibrahim Hashimi - 首席项目经理 排版&#xff1a;Alan Wang Visual Studio 中为 ASP.NET Core 项目搭建脚手架是一项长期特性&#xff0c;是在 ASP.NET Core 发布后不久添加的。多年来&#xff0c;我们一直支持从命令行搭建脚手架。根据从命令行操作中获…

基于ZYNQ 7z010开发板 oled点亮的实现

dc拉高的时候就是发送128字节数据的时候 发送指令dc拉低 模式是00 sck先置低再置高 复位是与开发板上的按键一样都是低有效 25位字节指令 加 3字节的 页地址加起始结束 b0,00,10, timescale 1ns / 1ps module top0(input wire clk ,input wire rst_n,// out…

使用torch模拟 BMM int8量化计算。

使用torch模型BMM int8计算。 模拟&#xff1a;BMM->softmax->BMM 计算流程 import torch import numpy as np torch.manual_seed(777) def int8_quantize_per_token(x: torch.Tensor, axis: int -1, attnsFalse):if x.dtype ! torch.float32:x x.type(torch.float32)…

【CSS in Depth 2 精译_070】11.3 利用 OKLCH 颜色值来处理 CSS 中的颜色问题(下):从页面其他颜色衍生出新颜色

当前内容所在位置&#xff08;可进入专栏查看其他译好的章节内容&#xff09; 第四部分 视觉增强技术 ✔️【第 11 章 颜色与对比】 ✔️ 11.1 通过对比进行交流 11.1.1 模式的建立11.1.2 还原设计稿 11.2 颜色的定义 11.2.1 色域与色彩空间11.2.2 CSS 颜色表示法 11.2.2.1 RGB…

HTML:表格重点

用表格就用table caption为该表上部信息&#xff0c;用来说明表的作用 thead为表头主要信息&#xff0c;效果加粗 tbody为表格中的主体内容 tr是 table row 表格的行 td是table data th是table heading表格标题 &#xff0c;一般表格第一行的数据都是table heading

15.Java 网络编程(网络相关概念、InetAddress、NetworkInterface、TCP 网络通信、UDP 网络通信、超时中断)

一、网络相关概念 1、网络通信 网络通信指两台设备之间通过网络实现数据传输&#xff0c;将数据通过网络从一台设备传输到另一台设备 java.net 包下提供了一系列的类和接口用于完成网络通信 2、网络 两台以上设备通过一定物理设备连接构成网络&#xff0c;根据网络的覆盖范…

项目中使用AntV L7地图(五)添加飞线

项目中使用AntV L7地图&#xff0c;添加 飞线 文档地址&#xff1a;https://l7.antv.antgroup.com/zh/examples/line/animate/#trip_animate 一、初始化地图 使用的地图文件为四川地图JSON&#xff0c;下载地址:https://datav.aliyun.com/portal/school/atlas/area_selector#&…

MySQL-DQL之数据表操作

文章目录 零. 准备工作一. 简单查询1.查询所有的商品.2.查询商品名和商品价格.3.查询结果是表达式&#xff08;运算查询&#xff09;&#xff1a;将所有商品的价格10元进行显示. 二. 条件查询1. 比较查询2. 范围查询3. 逻辑查询4. 模糊查询5. 非空查询 三. 排序查询四. 聚合查询…

nacos bootstrap.yml 和 spring.config.import 加载配置的流程区别

相关依赖 springboot:2.7.15 nacos:2.2.3 bootstrap.yml加载方式 加载流程如下图所示 从图中可以看出,&#xff1a; 1.bootstrap.yml 的加载是在 BootstrapApplicationListener.onApplicationEvent 接收到 ApplicationEnvironmentPreparedEventEvent 事件后另起一个 Sprin…

Kubernetes Nginx-Ingress | 禁用HSTS/禁止重定向到https

目录 前言禁用HSTS禁止重定向到https关闭 HSTS 和设置 ssl-redirect 为 false 的区别 前言 客户请求经过ingress到服务后&#xff0c;默认加上了strict-transport-security&#xff0c;导致客户服务跨域请求失败&#xff0c;具体Response Headers信息如下&#xff1b; 分析 n…

关于idea-Java-servlet-Tomcat-Web开发中出现404NOT FOUND问题的解决

在做web项目时&#xff0c;第一次使用servlet开发链接前端和后端的操作&#xff0c;果不其然&#xff0c;遇到了诸多问题&#xff0c;而遇到最多的就是运行项目打开页面时出现404NOT FOUND的情况。因为这个问题我也是鼓捣了好久&#xff0c;上网查了许多资料才最终解决&#xf…

开发一套SDK 第一弹

自动安装依赖包 添加条件使能 #ex: filetypesh bash_ls 识别 达到预期,多个硬件环境 等待文件文件系统挂在完成 或者创建 /sys/class/ 属性文件灌入配置操作 AI 提供的 netlink 调试方法,也是目前主流调用方法,socket yyds #include <linux/module.h> #include <linux…

深入理解 Apache Shiro:安全框架全解析

亲爱的小伙伴们&#x1f618;&#xff0c;在求知的漫漫旅途中&#xff0c;若你对深度学习的奥秘、JAVA 、PYTHON与SAP 的奇妙世界&#xff0c;亦或是读研论文的撰写攻略有所探寻&#x1f9d0;&#xff0c;那不妨给我一个小小的关注吧&#x1f970;。我会精心筹备&#xff0c;在…

【PlantUML系列】流程图(四)

目录 目录 一、基础用法 1.1 开始和结束 1.2 操作步骤 1.3 条件判断 1.4 并行处理 1.5 循环 1.6 分区 1.7 泳道 一、基础用法 1.1 开始和结束 开始一般使用start关键字&#xff1b;结束一般使用stop/end关键字。基础用法包括&#xff1a; start ... stopstart ...…

Mac 录制电脑系统内的声音的具体方法?

1.第一步&#xff1a;下载BlackHole 软件 方式1&#xff1a;BlackHole官方下载地址 方式2&#xff1a; 百度云下载 提取码: n5dp 2.第二步&#xff1a;安装BlackHole 双击下载好的BlackHole安装包&#xff0c;安装默认提示安装。 3.第三步&#xff1a;在应用程序中找到音频…

Unity简单操作及使用教程

Unity 是一款强大的跨平台游戏引擎&#xff0c;它不仅支持 2D 和 3D 游戏的开发&#xff0c;还可以用于虚拟现实 (VR)、增强现实 (AR)、动画、建筑可视化等多个领域。Unity 提供了完整的开发环境&#xff0c;具有丰富的功能、工具和资源&#xff0c;可以帮助开发者快速实现创意…

一个简单带颜色的Map

越简单 越实用。越少设计&#xff0c;越易懂。 需求背景&#xff1a; 创建方法&#xff0c;声明一个hashset&#xff0c; 元素为 {“#DE3200”, “#FA8C00”, “#027B00”, “#27B600”, “#5EB600”} 。 对应的key为 key1 、key2、key3、key4、key5。 封装该方法&#xff0c…

Go快速开发框架集成Vue3漂亮的动态流程图编辑和动态流程展示插件

温馨提示&#xff1a;我们分享的文章是给需要的人&#xff0c;不需要的人请绕过&#xff0c;文明浏览&#xff0c;误恶语伤人&#xff01; 前言 为大家在开发流程相关业务时有个漂亮流程图展示&#xff0c;我们集成一个实用的流程图编辑器&#xff0c;让流程开发变得简单&…

论文阅读:Statistical Comparisons of Classifiers over Multiple Data Sets

论文地址&#xff1a;Statistical Comparisons of Classifiers over Multiple Data Sets (acm.org) 前面在机器学习之Friedman检验-CSDN博客 中提到了Friedman检验&#xff0c;这里将对这个方法的论文进行详细的阅读&#xff0c;以了解其原理。 摘要 尽管用于在单个数据集上比…