当前位置: 首页 > news >正文

基于SpringbootShiro实现的CAS单点登录

概述

单点登录(Single Sign On,SSO)是一种登录管理机制,主要用于多系统集成,即在多个系统中,用户只需要到一个中央服务器登录一次即可访问这些系统中的任何一个,无须多次登录。常见的例子就是,当我们在淘宝网上登录了之后,如果再访问天猫网的话是不需要再次登录的。

详细

一、运行效果

image.png

image.png

二、实现过程

①、cas单点登录流程图

CAS是SSO的一种实现方式,CAS系统分为服务端与客户端,服务端提供登录认证的功能,客户端需要跳转到服务端进行登录认证,大体流程如下

image.png

②、cas 服务端搭建

CAS 服务端登录需要使用https,在本地我们可以使用 JDK 自带的 keytool 工具生成数字证书,具体流程和配置如下:

a 修改hosts文件,将要配置的CAS服务端域名映射到本地:

127.0.0.1       www.xiaoti.com

b 生成密钥库文件,这里设置密钥库口令,名字与姓氏处填写单点登录服务器的域名(这里是 www.xiaoti.com),其余项可随便填写。654321,设置密钥口令:654321,两者须相同:

c 查看生成的密钥库,输入密钥库密码654321:keytool -list -keystore localhost.keystored 生成crt证书文件,输入密钥库密码654321:keytool -export -alias localhost -keystore localhost.keystore -file localhost.crte 客户端信任证书,这里需要输入的密码是changeit:keytool -import -keystore "D:\Program Files\Java\jdk1.8.0_66\jre\lib\security\cacerts" -file localhost.crt -alias localhostf tomcat配置,server.xml配置:<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"maxThreads="200"SSLEnabled="true"scheme="https"secure="true"clientAuth="false"sslProtocol="TLS"keystoreFile="D:\dev\localhost.keystore"keystorePass="654321" />

 

③、 新建cas服务端项目

CAS已经提供了服务端的基本war包实现,我们只需在其基础上作修改即可,使用maven 的oerlay配置可以通过覆盖的方式来进行修改。

a 新建Maven webapp项目,这里命名为cas-server-demo,引入依赖:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>gdou.laixiaoming</groupId><artifactId>cas-server-demo</artifactId><packaging>war</packaging><version>0.0.1-SNAPSHOT</version><name>cas-server-demo Maven Webapp</name><url>http://maven.apache.org</url><properties><cas.version>5.2.5</cas.version></properties><dependencies><dependency><groupId>org.apereo.cas</groupId><artifactId>cas-server-webapp</artifactId><version>${cas.version}</version><type>war</type><scope>runtime</scope></dependency></dependencies><build><finalName>cas</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><failOnMissingWebXml>false</failOnMissingWebXml><warName>cas</warName><overlays><overlay><groupId>org.apereo.cas</groupId><artifactId>cas-server-webapp</artifactId></overlay></overlays></configuration></plugin></plugins></build></project>

b 打包,选择上面我们配置的tomcat,启动:
浏览器打开https://www.xiaoti.com:8443/cas/login,默认登录名和密码是casuserMellon,输入后可成功登录

④、配置数据库认证

上面我们成功搭建了CAS Server,但是只能使用默认的用户名和密码进行登录,如果我们的用户名和密码是存储在数据库的话,需要引入 JDBC的支持并进行配置:

a 首先,pom.xml配置文件中增加依赖:

<dependency><groupId>org.apereo.cas</groupId><artifactId>cas-server-support-jdbc</artifactId><version>${cas.version}</version></dependency><dependency><groupId>org.apereo.cas</groupId><artifactId>cas-server-support-jdbc-drivers</artifactId><version>${cas.version}</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.36</version></dependency>

b 创建用户密码表:

CREATE TABLE `user` (

  `id` bigint(20) NOT NULL AUTO_INCREMENT,

  `userName` varchar(15) DEFAULT NULL,

  `password` char(32) DEFAULT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;

c 将war包中的的application.properties复制出来:

image.png

放到项目如下位置,这里的路径需要对应(确保部署后的application.properties可以对原文件进行覆盖),才能实现更新:

image.png

d 修改application.properties,关于JDBC这里的更详细的配置,可以访问官网 database-authentication部分:

#数据库连接配置

cas.authn.jdbc.query[0].user=root

cas.authn.jdbc.query[0].password=mysql

cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver

cas.authn.jdbc.query[0].url=jdbc:mysql://localhost:3306/cas_auth

cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect

##从数据库中获取用户名和密码进行匹配登录

cas.authn.jdbc.query[0].sql=SELECT * FROM `user` WHERE userName=?

cas.authn.jdbc.query[0].fieldPassword=password

e 重新构建项目并启动,输入数据库中存在的用户名和密码,是可以成功登录的;

⑤、cas服务端搭建(整合Shiro和SpringBoot)

新建maven项目,引入相关依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.3.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>gdou.laixiaoming</groupId><artifactId>cas-client-a</artifactId><version>0.0.1-SNAPSHOT</version><name>cas-client-a</name><description>CAS Client Demo.</description><properties><java.version>1.8</java.version><shiro.version>1.4.0</shiro.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- shiro --><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-spring</artifactId><version>${shiro.version}</version></dependency><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-core</artifactId><version>${shiro.version}</version></dependency><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-cas</artifactId><version>${shiro.version}</version></dependency><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-aspectj</artifactId><version>${shiro.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

shiro配置

扩展CasRealm,在登录成功后,可以获取到登录的用户名,在客户端这边再把用户拥有的角色和权限查询出来并保存:
public class MyCasRealm extends CasRealm{@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {//获取用户名String username = (String)principals.getPrimaryPrincipal();SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
//        authorizationInfo.setRoles(new HashSet<>(Arrays.asList("admin")));
//        authorizationInfo.setStringPermissions(new HashSet<>(Arrays.asList("admin")));return authorizationInfo;}
}Shiro配置:
@Configuration
public class ShiroConfig {@Beanpublic ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();shiroFilterFactoryBean.setSecurityManager(securityManager);//配置自定义casFilterMap<String, Filter> filters = new LinkedHashMap<>();CasFilter casFilter = new CasFilter();casFilter.setFailureUrl("/casFailure");filters.put("cas", casFilter);shiroFilterFactoryBean.setFilters(filters);//配置filter调用链Map<String,String> filterChainDefinitionMap = new LinkedHashMap<>();//anon为匿名,不拦截filterChainDefinitionMap.put("/static/**", "anon");filterChainDefinitionMap.put("/casFailure", "anon");//拦截CAS Server返回的ticketfilterChainDefinitionMap.put("/cas", "cas");//退出登录filterChainDefinitionMap.put("/logout", "anon");filterChainDefinitionMap.put("/logouttips", "anon");//需要登录访问的页面filterChainDefinitionMap.put("/**", "user");shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);//service指定了登录成功后的回调地址,回调/cas将被CasFilter拦截,获取服务端返回的Service Ticket进行登录shiroFilterFactoryBean.setLoginUrl("https://www.xiaoti.com:8443/cas/login?service=http://www.localhost1.com:9090/cas");//登录成功后要跳转的链接shiroFilterFactoryBean.setSuccessUrl("/");//未授权跳转页面shiroFilterFactoryBean.setUnauthorizedUrl("/403");return shiroFilterFactoryBean;}@Beanpublic MyCasRealm casRealm(){//使用自定义RealmMyCasRealm casRealm = new MyCasRealm();casRealm.setCachingEnabled(true);casRealm.setAuthenticationCachingEnabled(true);casRealm.setAuthenticationCacheName("authenticationCache");casRealm.setAuthorizationCachingEnabled(true);casRealm.setAuthorizationCacheName("authorizationCache");//指定CAS服务端地址casRealm.setCasServerUrlPrefix("https://www.xiaoti.com:8443/cas");//当前应用的CAS服务URL,用于接收和处理CAS服务端的TicketcasRealm.setCasService("http://www.localhost1.com:9090/cas");return casRealm;}@Beanpublic SecurityManager securityManager(){DefaultWebSecurityManager securityManager =  new DefaultWebSecurityManager();securityManager.setRealm(casRealm());return securityManager;}/*** Shiro生命周期处理器*/@Beanpublic LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {return new LifecycleBeanPostProcessor();}@Bean@DependsOn({"lifecycleBeanPostProcessor"})public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() {DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();advisorAutoProxyCreator.setProxyTargetClass(true);return advisorAutoProxyCreator;}/*** 开启Shiro AOP的注解支持(如@RequiresRoles,@RequiresPermissions)*/@Beanpublic AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager){AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);return authorizationAttributeSourceAdvisor;}}

⑥、cas单点登出配置

退出登录时,将页面重定向到CAS的退出页面,service参数的设置指定了退出登录后的回调地址:

@GetMapping("/logout")public String logout(){SecurityUtils.getSubject().logout();return "redirect:https://www.xiaoti.com:8443/cas/logout?service=https://www.xiaoti.com:9090/logouttips";}

service参数名可以在CAS服务端通过修改application.properties进行配置,关于登出的更多配置,可见官网:

#单点登出

#配置允许登出后跳转到指定页面

cas.logout.followServiceRedirects=true

#跳转到指定页面需要的参数名为 service

cas.logout.redirectParameter=service

在CAS服务端退出后,会向注册的每个服务发送登出请求,该请求可以由SingleSignOutFilter进行拦截并销毁当前会话:

@Configuration
public class CasConfig {@Beanpublic FilterRegistrationBean singleSignOutFilterRegistration() {FilterRegistrationBean registration = new FilterRegistrationBean(new SingleSignOutFilter());registration.addUrlPatterns("/*");return registration;}@Beanpublic ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> singleSignOutListenerRegistration() {ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> registration =new ServletListenerRegistrationBean<>(new SingleSignOutHttpSessionListener());return registration;}
}

⑥、cas单点登出配置

退出登录时,将页面重定向到CAS的退出页面,service参数的设置指定了退出登录后的回调地址:

@GetMapping("/logout")

         public String logout(){

                   SecurityUtils.getSubject().logout();

                   return "redirect:https://www.xiaoti.com:8443/cas/logout?service=https://www.xiaoti.com:9090/logouttips";

         }

#单点登出

#配置允许登出后跳转到指定页面

cas.logout.followServiceRedirects=true

#跳转到指定页面需要的参数名为 service

cas.logout.redirectParameter=service

在CAS服务端退出后,会向注册的每个服务发送登出请求,该请求可以由SingleSignOutFilter进行拦截并销毁当前会话:

@Configuration

public class CasConfig {

  

    @Bean

    public FilterRegistrationBean singleSignOutFilterRegistration() {

        FilterRegistrationBean registration = new FilterRegistrationBean(new SingleSignOutFilter());

        registration.addUrlPatterns("/*");

        return registration;

    }

  

    @Bean

    public ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> singleSignOutListenerRegistration() {

        ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> registration =

                new ServletListenerRegistrationBean<>(new SingleSignOutHttpSessionListener());

        return registration;

    }

}

⑦、cas服务端配置

客户端搭建好后,需要在CAS服务端上配置哪些服务可以注册到CAS服务端上,服务的管理也有许多方式,这里使用的JSON的方式,需要先在服务端引入相关依赖(更多说明见官网):

<dependency>

                            <groupId>org.apereo.cas</groupId>

                            <artifactId>cas-server-support-json-service-registry</artifactId>

                            <version>${cas.version}</version>

                   </dependency>

然后,在已经生成的war包中找到文件:

image.png

将文件复制到这个位置:

image.png

修改,serviceId指定允许注册的客户端,更多配置见官网:

{

  "@class" : "org.apereo.cas.services.RegexRegisteredService",

  "serviceId" : "^(https|imaps|http)://(www\\.localhost1\\.com:9090|www\\.localhost2\\.com:9091)/.*",

  "name" : "HTTPS and IMAPS",

  "id" : 10000001,

  "description" : "This service definition authorizes all application urls that support HTTPS and IMAPS protocols.",

  "evaluationOrder" : 10000

}

同时在application.properties指定配置文件位置:

#客户端服务注册

cas.serviceRegistry.json.location=classpath:/services

至此,CAS客户端搭建完成了

三、项目结构图

image.png

四、补充

CAS全称为Central Authentication Service即中央认证服务,是一个企业多语言单点登录的解决方案,并努力去成为一个身份验证和授权需求的综合平台。

CAS是由Yale大学发起的一个企业级的、开源的项目,旨在为Web应用系统提供一种可靠的单点登录解决方法(属于 Web SSO )。

CAS协议至少涉及三方:客户端Web浏览器,请求身份验证的Web应用程序和CAS服务器。 它也可能涉及后端服务,如数据库服务器,它没有自己的HTTP接口,但与Web应用程序进行通信。

相关文章:

基于SpringbootShiro实现的CAS单点登录

概述 单点登录&#xff08;Single Sign On,SSO&#xff09;是一种登录管理机制&#xff0c;主要用于多系统集成&#xff0c;即在多个系统中&#xff0c;用户只需要到一个中央服务器登录一次即可访问这些系统中的任何一个&#xff0c;无须多次登录。常见的例子就是&#xff0c;…...

SocketTool V4.0 使用说明

TCP/UDP Socket 调 试 工 具 提 供 了 TCP Server,TCP Client,UDP Server,UDP Client,UDP Group 五种 Socket 调试方案。 下面是一份简要的使用流程&#xff1a; TCP 通信测试&#xff1a; 1) 创建 TCP Server 选中左方的 TCP Server, 然后点击 ”创建 ”按钮&#xff0c;软件弹…...

Jenkins结合allure生成测试报告

前言&#xff1a; 我们在做自动化测试的过程中最重要的肯定是报告的输出啦&#xff0c;最近几年allure可以说是最最主流报告展示工具啦。 一、服务端安装allure 在安装Jenkins的机器 安装allure&#xff0c;我们在Jenkins上能跑动前提是在对应服务器上代码能正常运行&#xf…...

【Linux】缓冲区/回车换行

1、缓冲区 C程序默认有输出缓冲区。数据输出时&#xff0c;被及时看到&#xff0c;是立马刷新了&#xff1b;如果没被看到&#xff0c;是被暂存在数据缓冲区中。fflush(stdout); 【强制刷新】\n【行刷新&#xff0c;也是一种刷新方式】 2、回车换行 \n【回车换行】输入完一行内…...

Java手写插入排序和算法案例拓展

1. Java手写插入排序和算法案例拓展 1.1 算法思维导图 #mermaid-svg-jIZ3LAdg1NLcOvaM {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-jIZ3LAdg1NLcOvaM .error-icon{fill:#552222;}#mermaid-svg-jIZ3LAdg1NLcOvaM…...

Python Opencv实践 - 视频文件操作

参考资料&#xff1a; 视频处理VideoCapture类---OpenCV-Python开发指南&#xff08;38&#xff09;_python opencv videocapture_李元静的博客-CSDN博客 OpenCV VideoCapture.get()参数详解 - 简书FOURCC四字符码对照表_4fvcc_Kellybook的博客-CSDN博客 import cv2 as cv im…...

HCS 中的一些概念(二)

一、Service OM 1、首页&#xff08;资源状态&#xff09; 2、服务列表 计算资源&#xff1a;计算资源又分为可用分区&#xff08;AZ&#xff09;、规格和虚拟机组&#xff0c;可在此处创建虚拟机、虚拟机组、主机组和规格 网络资源&#xff1a;网络资源又分为物理网络…...

Scanner类用法(学习笔记)

Scanner类用法&#xff08;学习笔记&#xff0c;后续会补充&#xff09; 1.next&#xff08;&#xff09;用法 package com.yushifu.scanner; import java.util.Scanner;//util java工具包 //Scanner类&#xff08;获取用户的输入&#xff09; Scanner s new Scanner&#…...

idea2021.1.3版本双击启动,没反应

今天打开电脑&#xff0c;点开idea&#xff0c;界面悬在这里&#xff0c;几秒然后就是没了。然后就一直打不开idea了。 然后又是卸载重装&#xff0c;又是删除缓存文件。我把电脑关于idea的文件全都删除了 。重新安装后&#xff08;首次运行倒是可以打开&#xff0c;但是关掉id…...

MC-4/11/01/400 ELAU 软件允许用户完全访问相机设置

MC-4/11/01/400 ELAU 软件允许用户完全访问相机设置 一个完整的Sentinel模具保护解决方案包括一到四台冲击式摄像机、专用红外LED照明和镜头、Sentinel软件以及所有与模压机连接的必要互连组件。摄像机支架基于磁性&#xff0c;可快速、安全、灵活地部署。此外&#xff0c;一个…...

Error contacting service. It is probably not running.问题解决

一 问题描述 Error contacting service. It is probably not running. 查看zookeeper 目录下数据目录下的zookeeper.out 如果你没找到这个目录那么 OK 你的问题就是 zoo.cfg 文件中数据目录设置错误 zookeeper.out下报错 ERROR [main:QuorumPeerMain86] - Invalid config,…...

01_网络编程_传统IO

网络编程 1.什么是网络编程 在网络通信协议下&#xff0c;不同计算机上运行的程序&#xff0c;进行的数据传输。 如果想把一个计算的结果&#xff0c;或者是电脑上的文件通过网络传递给你的朋友&#xff0c;就需要用到网络编程。 在实际生活中&#xff0c;网络通信无处不在…...

vue 检查指定路由是否存在

今天路由跳转报错了 RangeError: Maximum call stack size exceeded 但显然 我的代码只有一个简单的路由跳转 并没有很大的的堆栈数据操作 所以 我就联想到了 会不会是因为路由不存在 我们可以通过 console.log(this.$router.options.routes)输出整个路由对象类看一下 或者…...

自动化办公更简单了:新版python-office,有哪些更新?

#职场经验谈# 大家好&#xff0c;这里是程序员晚枫&#xff0c;小破站/小红薯都叫这个名。 去年4月开源了一个Python自动化办公项目&#xff1a;python-office&#xff0c;GitHub和Gitee都能看到。1行代码实现复杂的自动化办公任务&#xff0c;帮助不懂代码的小白&#xff0c;…...

windows flask服务卡死的问题

windows flask服务卡死的问题 最近的工作中&#xff0c;需要用python写一个flask服务&#xff0c;供C端调用&#xff0c;但是偶尔服务会卡住&#xff0c;只接收数据但不进行处理&#xff0c;不过CtrlC后又可以继续运行。 查看了网上的一些解决方法&#xff0c;但似乎都没有什…...

项目上线部署--》服务器部署流程(一)

目录 &#x1f31f;准备工作 服务器购买 域名购买 域名解析&#xff08;配置 DNS&#xff09; &#x1f31f;服务器环境搭建 配置服务器 安装 CentOS 开发人员相关包 ​编辑 配置免密登陆 &#x1f31f;写在最后 &#x1f31f;准备工作 服务器购买 国内服务器&#x…...

Python:函数调用的实参

相关阅读 Python专栏https://blog.csdn.net/weixin_45791458/category_12403403.html 调用就是附带可能为空的一系列参数来执行一个可调用对象 &#xff08;例如函数&#xff09;&#xff0c;它的语法的BNF范式如下所示&#xff0c;有关BNF范式的规则&#xff0c;可以参考之前…...

174. 地下城游戏 -- 动规

174. 地下城游戏 class CalculateMinimumHP:"""174. 地下城游戏https://leetcode.cn/problems/dungeon-game/"""def solution(self, dungeon: List[List[int]]) -> int:# 我们想计算左上⻆到右下⻆所需的最⼩⽣命值m, n len(dungeon), len(d…...

js实现websocket服务端和客户端

天行健&#xff0c;君子以自强不息&#xff1b;地势坤&#xff0c;君子以厚德载物。 每个人都有惰性&#xff0c;但不断学习是好好生活的根本&#xff0c;共勉&#xff01; 文章均为学习整理笔记&#xff0c;分享记录为主&#xff0c;如有错误请指正&#xff0c;共同学习进步。…...

qt qml RadioButton如何设置字体颜色,style提示找不到怎么办?

qt QML中设置RadioButton的字体颜色&#xff0c;可以使用RadioButton的label属性来设置文本的样式。下面是一个示例代码&#xff1a; import QtQuick 2.6 import QtQuick.Controls 2.2 import QtQuick.Controls 1.4 as Controls1_4 import QtQuick.Controls.Styles 1.4 import…...

后进先出(LIFO)详解

LIFO 是 Last In, First Out 的缩写&#xff0c;中文译为后进先出。这是一种数据结构的工作原则&#xff0c;类似于一摞盘子或一叠书本&#xff1a; 最后放进去的元素最先出来 -想象往筒状容器里放盘子&#xff1a; &#xff08;1&#xff09;你放进的最后一个盘子&#xff08…...

生成xcframework

打包 XCFramework 的方法 XCFramework 是苹果推出的一种多平台二进制分发格式&#xff0c;可以包含多个架构和平台的代码。打包 XCFramework 通常用于分发库或框架。 使用 Xcode 命令行工具打包 通过 xcodebuild 命令可以打包 XCFramework。确保项目已经配置好需要支持的平台…...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

k8s从入门到放弃之Ingress七层负载

k8s从入门到放弃之Ingress七层负载 在Kubernetes&#xff08;简称K8s&#xff09;中&#xff0c;Ingress是一个API对象&#xff0c;它允许你定义如何从集群外部访问集群内部的服务。Ingress可以提供负载均衡、SSL终结和基于名称的虚拟主机等功能。通过Ingress&#xff0c;你可…...

MVC 数据库

MVC 数据库 引言 在软件开发领域,Model-View-Controller(MVC)是一种流行的软件架构模式,它将应用程序分为三个核心组件:模型(Model)、视图(View)和控制器(Controller)。这种模式有助于提高代码的可维护性和可扩展性。本文将深入探讨MVC架构与数据库之间的关系,以…...

第25节 Node.js 断言测试

Node.js的assert模块主要用于编写程序的单元测试时使用&#xff0c;通过断言可以提早发现和排查出错误。 稳定性: 5 - 锁定 这个模块可用于应用的单元测试&#xff0c;通过 require(assert) 可以使用这个模块。 assert.fail(actual, expected, message, operator) 使用参数…...

自然语言处理——Transformer

自然语言处理——Transformer 自注意力机制多头注意力机制Transformer 虽然循环神经网络可以对具有序列特性的数据非常有效&#xff0c;它能挖掘数据中的时序信息以及语义信息&#xff0c;但是它有一个很大的缺陷——很难并行化。 我们可以考虑用CNN来替代RNN&#xff0c;但是…...

【JavaSE】绘图与事件入门学习笔记

-Java绘图坐标体系 坐标体系-介绍 坐标原点位于左上角&#xff0c;以像素为单位。 在Java坐标系中,第一个是x坐标,表示当前位置为水平方向&#xff0c;距离坐标原点x个像素;第二个是y坐标&#xff0c;表示当前位置为垂直方向&#xff0c;距离坐标原点y个像素。 坐标体系-像素 …...

MFC 抛体运动模拟:常见问题解决与界面美化

在 MFC 中开发抛体运动模拟程序时,我们常遇到 轨迹残留、无效刷新、视觉单调、物理逻辑瑕疵 等问题。本文将针对这些痛点,详细解析原因并提供解决方案,同时兼顾界面美化,让模拟效果更专业、更高效。 问题一:历史轨迹与小球残影残留 现象 小球运动后,历史位置的 “残影”…...