spring boot simple implementation interceptor

token authentication mechanism on one, based on the use of jwt.

You can use interceptors to verify the token. Then we use spring boot to achieve a simple blocker feature, and implement verification token inside the interceptor.

 

To create the first interceptor class JwtInterceptor, implement the interceptor function.

JwtInterceptor class to achieve HandlerInterceptor interface. The interface contains three methods 

preHandle is executed before the execution of the request, so we will write token validation in here, postHandle request is executed after execution, but that's only done when preHandle returns true. afterCompletion mentoring rendering method after completion of execution, the same need preHandle method returns TRUE, the method commonly used to clean up resources and so on.

Finished interceptor class also needs to be configured:

In this configuration inside the interceptor class and the URL where I tried two full path, adding the two are OK. Of course, to write their own words can be written as fuzzy path

Such as: "/ admin / *" and so on.

 

So that when the access path will be first-class interceptor JwtInterceptor, verification token. If not or will expire throws out.

Published 20 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/qrnhhhh/article/details/92769685