【问题标题】:Quarkus JWT - Fallback to JDBC authentication if JWT token is not presentQuarkus JWT - 如果 JWT 令牌不存在,则回退到 JDBC 身份验证
【发布时间】:2020-05-19 14:23:07
【问题描述】:

我正在使用 Quarkus 通过 JWT RBAC 对用户进行身份验证。但是,如果 HTTP 标头中不存在 JWT 令牌,我希望能够使用 HTTP 基本用户名/密码对和 JDBC 领域对用户进行身份验证。 Quarkus 可以吗?

【问题讨论】:

    标签: quarkus


    【解决方案1】:

    基本身份验证

    启用基本身份验证集quarkus.http.auth.basic=true。您还必须至少安装一个提供基于用户名/密码的 IdentityProvider 的扩展程序,例如 Elytron JDBC

    更多内容见:https://quarkus.io/guides/security#basic-authentication

    还要检查这个:http://www.adam-bien.com/roller/abien/entry/client_side_http_basic_access

    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import javax.ws.rs.client.ClientRequestContext;
    import javax.ws.rs.client.ClientRequestFilter;
    import javax.ws.rs.core.MultivaluedMap;
    import javax.xml.bind.DatatypeConverter;
    
    public class Authenticator implements ClientRequestFilter {
    
        private final String user;
        private final String password;
    
        public Authenticator(String user, String password) {
            this.user = user;
            this.password = password;
        }
    
        public void filter(ClientRequestContext requestContext) throws IOException {
            MultivaluedMap<String, Object> headers = requestContext.getHeaders();
            final String basicAuthentication = getBasicAuthentication();
            headers.add("Authorization", basicAuthentication);
    
        }
    
        private String getBasicAuthentication() {
            String token = this.user + ":" + this.password;
            try {
                return "BASIC " + DatatypeConverter.printBase64Binary(token.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException ex) {
                throw new IllegalStateException("Cannot encode with UTF-8", ex);
            }
        }
    }
    

    【讨论】:

    • 问题出在服务器端,而不是客户端。我已经安装了 elytron jdbc,但如果请求标头中存在 JWT 令牌,我想覆盖身份验证。
    猜你喜欢
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2019-01-22
    • 2020-08-23
    • 1970-01-01
    • 2020-07-07
    相关资源
    最近更新 更多