Spring Security 回顾二

Spring Security 框架介绍 Spring Security 是一个功能强大且高度可定制的安全框架,专注于为 Java 应用程序提供身份验证和授权功能。它是 Spring 生态系统的一部分,广泛用于保护 Web 应用程序、REST API 和方法级别的安全。 核心功能 身份验证(Authentication):验证用户身份,常见方式包括表单登录、OAuth2、LDAP 等。 授权(Authorization):控制用户访问权限,确保用户只能访问其有权访问的资源。 防护攻击:提供对常见攻击(如 CSRF、XSS、SQL 注入)的防护。 会话管理:支持会话固定保护、并发会话控制等功能。 集成其他安全协议:支持 OAuth2、SAML、OpenID Connect 等协议。 Spring Security 的核心组件 SecurityContextHolder:存储当前用户的安全上下文。 Authentication:表示用户的身份验证信息。 UserDetails:封装用户信息(如用户名、密码、权限等)。 UserDetailsService:加载用户信息,用于身份验证。 GrantedAuthority:表示用户的权限。 SecurityFilterChain:定义请求的过滤链,处理安全逻辑。 Spring Security 的基本用法 1. 添加依赖 在 Maven 项目中,添加 Spring Security 依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> 2. 配置 Spring Security 通过 […] →Read more

Spring Security 回顾一

Spring Security 框架介绍 1. Spring Security 是什么? Spring Security 是 Spring 框架的安全管理框架,用于提供 身份认证(Authentication) 和 授权(Authorization) 机制。它主要用于保护 Web 应用 和 REST API,防止 未授权访问 和 常见安全攻击(如 CSRF、XSS、Session Fixation、Clickjacking 等)。 2. Spring Security 的核心概念 Spring Security 主要涉及以下核心概念: 2.1 身份认证(Authentication) 身份认证是指 验证用户身份 的过程。Spring Security 支持多种认证方式: 用户名 + 密码(默认基于 UserDetailsService) JWT 令牌(适用于 REST API) OAuth 2.0 / OpenID Connect(支持 Google、GitHub […] →Read more

IDaaS – Identity as a Service

Identity as a Service 身份认证作为一种服务, 包括身份验证,用户管理, 访问控制等功能, 实现安全的身份认证和访问控制, 减少从头构建身份认证管理系统的成本和复杂性. 例如 Okta, Authing, Auth0, AWS Cogito/IAM, 以及开源的 Keycloak, 它主要包含如下关键组件 认证服务器 Authentiation Server 负责用户的身份认证与授权, 支持多种身份验证协议, 如 OAuth, OpenID Connect 和 SAML. Authentiation Server 维护用户的身份信息和凭据, 并验证用户的身份以颁发访问令牌. 客户端 Clients Confidential Clients Public Clients Bearer-only Clients 令牌 Token Access Token ID Token 身份提供者 Identity Provider IDAP Active Directory SNS: Google, […] →Read more

Migrating From JDK 8 to Later JDK Releases

https://docs.oracle.com/en/java/javase/17/migrate/migrating-jdk-8-later-jdk-releases.html#GUID-7BB28E4D-99B3-4078-BDC4-FC24180CE82B →Read more

How Spring Boot Injects `SqlSessionTemplate` for `@Mapper` Interfaces

In Spring Boot with MyBatis, the @Mapper annotation is used to mark an interface as a MyBatis Mapper. Spring Boot automatically injects SqlSessionTemplate behind the scenes to enable SQL execution for these mapper interfaces. How Spring Boot Injects SqlSessionTemplate for @Mapper Interfaces Spring Boot and MyBatis integrate through MyBatis-Spring-Boot-Starter, which: Scans for @Mapper interfaces and […] →Read more

Vue.js 示例

1. 计数器组件(基础响应式) <template> <div> <p>Count: {{ count }}</p> <button @click="increment">+1</button> <button @click="reset">Reset</button> </div> </template> <script setup> import { ref } from 'vue'; // 响应式变量 const count = ref(0); // 方法 const increment = () => count.value++; const reset = () => count.value = 0; </script> 核心概念: ref 创建响应式变量 @click 事件绑定 模板中直接使用变量 2. Todo List(列表渲染 & […] →Read more

Designing Data Intensive Applications 1

Reliable, Scalable, and Maintainable Applications 数据库 A data-intensive application is typically built from the standard building blocks that provide the commonly needed functionality 缓存 Remember the result of an expensive operation to speed up reads. 搜索及索引 Allow users to search data by keyword or filter it by various ways 流处理 Send a messenger to another […] →Read more

gRPC transport

At a high level there are three distinct layers to the library: Stub, Channel, and Transport. Stub The Stub layer is what is exposed to most developers and provides type-safe bindings to whatever datamodel/IDL/interface you are adapting. gRPC comes with a plugin to the protocol-buffers compiler that generates Stub interfaces out of .proto files, but […] →Read more

Solve the dependency hell by maven

Resolving version conflicts in Maven can be tricky, but Maven provides several strategies and mechanisms to handle dependency conflicts effectively. Here’s a deeper dive into how you can resolve version conflicts in Maven: 1. Maven’s Dependency Mediation (Nearest-Wins Strategy) Maven uses a nearest-wins strategy to resolve version conflicts. This means that when multiple versions of […] →Read more