This commit is contained in:
2026-04-29 14:58:02 +08:00
parent e729f9bd31
commit b98c66ca21
370 changed files with 55094 additions and 0 deletions
@@ -0,0 +1,44 @@
package com.cyynote.controller;
import io.jsonwebtoken.Claims;
import org.noear.solon.annotation.Component;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Handler;
import org.noear.solon.core.handle.Result;
import org.noear.solon.core.route.RouterInterceptor;
import org.noear.solon.core.route.RouterInterceptorChain;
import org.noear.solon.sessionstate.jwt.JwtUtils;
@Component
public class JwtInterceptor implements RouterInterceptor {
public void doIntercept(Context ctx, Handler mainHandler, RouterInterceptorChain chain) throws Throwable {
boolean flag = true;
if ("/api/auth/signup".equals(ctx.path()) ||
"/api/auth/signin".equals(ctx.path()) ||
"/demo".equals(ctx.path()) ||
"/api/auth/logout".equals(ctx.path())
)
flag = false;
if (flag)
if (null != ctx.header("Authorization")) {
String token = ctx.header("Authorization");
token = token.replace("Bearer ", "");
System.out.println("token:" + token);
Claims claims = JwtUtils.parseJwt(token);
System.out.println("claims:" + claims);
if (null != claims) {
System.out.println("username:" + claims.get("user_name"));
System.out.println("exp:" + claims.get("exp"));
} else {
ctx.status(401);
ctx.render(Result.failure(401, ""));
}
} else {
ctx.status(401);
ctx.render(Result.failure(401, ""));
}
chain.doIntercept(ctx, mainHandler);
}
}