有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java REST拆分令牌体的一部分,并返回它

我有一个Java令牌,用于在客户机和服务器之间进行身份验证,现在我得到了以下格式:

bearer{token}

现在我想裁剪出持有者,这样我就只有代币的价值了:

到目前为止,我已经提出了这个方法:

    public static String cropToken(String token){
    token = token.replace("bearer{", "");
    token = token.replace("}", "");
    return token;
}

然后我将新标记分配回资源中的原始引用:

    public Response create(@HeaderParam("Authorization")String token, String content) throws IOException, AuthenticationException
    {
    TokenAuthenticator authenticator = new TokenAuthenticator(() -> new 
JpaUserRepository(JpaConnection.create()));
    token =TokenSplitter.cropToken(token);
    AuthenticationContext  authenticationContext = 
authenticator.authenticate(token);

这是最佳实践还是有更好的方法


共 (0) 个答案