Spring security integration JWT process diagram
This article mainly introduces the JWT integration process diagram of spring security. It is introduced in great detail through the example code, which has a certain reference value for everyone's study or work. Friends in need can refer to it
1、 Create projects and import dependencies
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.9.1</version> </dependency>
2、 Related configurations and codes
2.1) to implement JWT, you need two filters. First, if the user logs in successfully, the encrypted JWT data format is returned to him, and the key is stored in the server secret
Second, verify that the client carries a token when accessing
2.2) create JWT login filter and implement abstractauthenticationprocessingfilter
2.3) override parent method
2.4) create the token verification filter carried during client access
This just shows that JWT data does not have to carry the account password role, as long as it can verify the identity, because token itself is like a password. The user information here is for spring security
You can design it according to your own business
2.5) create a securityconfig configuration class, and the configuration in it will not be explained. I don't understand. Turn to my previous blog
2.6)controller
3、 Test effect diagram
3.1) log in first
3.2) use the token given to us to access
The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.