I have a quarkus application, created a custom annotation with interceptor to secure endpoints.
// Custom annotation
Код: Выделить всё
@InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) public @interface PermitRole { } Код: Выделить всё
@Interceptor @PermitRole public class LiveTraderRolesAuthorization { @Inject HttpHeaders headers; @Inject JWTTokenParser jwtTokenParser; @AroundInvoke public Object authorize(InvocationContext context) throws Exception { // here i have logic to ***parse Authorization header JWT token using nimbus-jose*** and setting authorized flag. if(authorized) { return context.proceed(); } } } Код: Выделить всё
@GET @PermitRole @Produces(MediaType.APPLICATION_JSON) public RestResponse getSome(@PathParam("Id") String Id) { //logic } NOTE: I am using nimbus-jose-jwt library to parse the Jwt token, not anything specific to quarkus.
Источник: https://stackoverflow.com/questions/781 ... in-quarkus
Мобильная версия