我想要写一个应用程序,它既允许RESTful形式与数据交互,又允许常规REST、CRUD端点和web。
在过去,我走了在JS中实现UI的大部分功能的路线,这将调用常规的REST端点。这很好,但是对于这个应用程序,我想使用Qute来执行生成页面内容的许多基本功能。但是,为了正确地管理端点并确保正确的RBAC控制,我需要通过cookie访问jwt,而不是普通的头。这似乎是可能的,但不是在我的其他端点需要它的标题形式。(资料来源:https://quarkus.io/guides/security-jwt#microprofile-jwt-configuration )
这里最好的做法是什么?我是否应该将这两个应用程序保持非常独立,并在Javascript中完成所有事情?
作为参考,我在代码中如何使用jwt:(例如来自UI qute生成,但我使用JWT的方式与CRUD端点相同)
@Traced
@Slf4j
@Path("/")
@Tags({@Tag(name = "UI")})
@RequestScoped
@Produces(MediaType.TEXT_HTML)
public class Index extends UiProvider {
@Inject
Template index;
@Inject
JsonWebToken jwt;
@Inject
UserService userService;
@GET
@PermitAll
@Produces(MediaType.TEXT_PLAIN)
public TemplateInstance index(
@Context SecurityContext securityContext
) {
logRequestContext(jwt, securityContext);
return index.data("hasToken", hasJwt(jwt));
}相关延期:
implementation 'io.quarkus:quarkus-resteasy-jackson'
implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-smallrye-jwt'
implementation 'io.quarkus:quarkus-smallrye-jwt-build'
implementation 'io.quarkus:quarkus-qute'
implementation 'io.quarkus:quarkus-resteasy-qute'尝试Config (使用yaml扩展)会导致所有rest交互的jwt处理异常:
mp:
jwt:
token:
header: Cookie
cookie: jwt
smallrye:
jwt:
always-check-authorization: trueCaused by: org.jose4j.jwt.consumer.InvalidJwtException: JWT processing failed. Additional details: [[17] Unable to process JOSE object (cause: org.jose4j.lang.JoseException: Invalid JOSE Compact Serialization. Expecting either 3 or 5 parts for JWS or JWE respectively but was 23.): function(n){var%20r%2Ce%2Ci%2Ct=this[0]%3Breturn%20arguments.length?(i=m(n)%2Cthis.each(function(e){var%20t%3B1===this.nodeType&&(null==(t=i?n.call(this%2Ce%2CS(this).val()):n)?t=%22%22:%22number%22==typeof%20t?t+=%22%22:Array.isArray(t)&&(t=S.map(t%2Cfunction(e){return%20null==e?%22%22:e+%22%22}))%2C(r=S.valHooks[this.type]||S.valHooks[this.nodeName.toLowerCase()])&&%22set%22in%20r&&void%200!==r.set(this%2Ct%2C%22value%22)||(this.value=t))})):t?(r=S.valHooks[t.type]||S.valHooks[t.nodeName.toLowerCase()])&&%22get%22in%20r&&void%200!==(e=r.get(t%2C%22value%22))?e:%22string%22==typeof(e=t.value)?e.replace(yt%2C%22%22):null==e?%22%22:e:void%200}]应该注意到,JWT在常规标题中对我来说很好,当没有设置cookie或header时,就会发生此错误。
我是最新的夸夸斯,2.4.1,最后
更新:我只是尝试用生成的令牌来测试ui端的"Cookie“方法,并发现这似乎是坏的.代码无法正确解析cookie中的令牌。现在,我将继续进行一个完整的JS实现,但我仍然想知道这是否有可能在某个时候实现。
要复制:https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/tree/main/software/open-qm-base-station和取消注释在https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/blob/main/software/open-qm-base-station/src/main/resources/application.yaml#L70上的行,您需要在父目录中发布库,以便进行构建,并使用它希望与Mongodb实例对话的大多数其他端点。
发布于 2021-11-08 21:39:33
smallrye.jwt.always-check-authorization=true将确保同时检查授权和Cookie头
https://stackoverflow.com/questions/69888326
复制相似问题