Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the Security Management of user Rights by integrating SpringSecurity Framework with SpringBoot2

Shulou Source: shulou.com Published: 2022-06-01 11:20:32 09月26日 Update

This article introduces how SpringBoot2 integrates SpringSecurity framework to achieve user rights security management, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. Introduction to Security 1. Basic concepts

Spring Security is a security framework that can provide declarative secure access control solutions for Spring-based enterprise applications. It provides a set of Bean that can be configured in the Spring application context, makes full use of the IOC,DI,AOP (aspect-oriented programming) function of Spring, provides declarative security access control for the application system, and reduces the work of writing a lot of repetitive code for security control.

2. Interpretation of Core API

1), SecurityContextHolder

The most basic object holds the current session user authentication, permissions, authentication and other core data. By default, SecurityContextHolder uses the ThreadLocal policy to store authentication information, which is bound to the thread. When the user exits, the authentication information of the current thread is automatically cleared. To understand the springcloud architecture, please add: three, six, two, four, seven, two, 59

Initialize the source code: obviously use ThreadLocal threads.

Private static void initialize () {if (! StringUtils.hasText (strategyName)) {strategyName = "MODE_THREADLOCAL";} if (strategyName.equals ("MODE_THREADLOCAL")) {strategy = new ThreadLocalSecurityContextHolderStrategy ();} else if (strategyName.equals ("MODE_INHERITABLETHREADLOCAL")) {strategy = new InheritableThreadLocalSecurityContextHolderStrategy ();} else if (strategyName.equals ("MODE_GLOBAL")) {strategy = new GlobalSecurityContextHolderStrategy () } else {try {Class clazz = Class.forName (strategyName); Constructor customStrategy = clazz.getConstructor (); strategy = (SecurityContextHolderStrategy) customStrategy.newInstance ();} catch (Exception var2) {ReflectionUtils.handleReflectionException (var2);}} + + initializeCount;}

2), Authentication

source code

Public interface Authentication extends Principal, Serializable {Collection

Tags: Users authentication security permissions information data pages login configuration core functions interfaces databases processes frameworks integration prefixes passwords threads authentication processes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Shulou Technology Linux Shulou Tech Info