@Override public AuthenticationResult createEscalatedAuthenticationResult() { // if you found your self asking why the authenticatedBy field is set to null please read this: // https://github.com/druid-io/druid/pull/5706#discussion_r185940889 return new AuthenticationResult(internalClientUsername, authorizerName, null, null); } }
@Override public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain ) throws IOException, ServletException { // PreResponseAuthorizationCheckFilter checks that this attribute is set, // but the value doesn't matter since we skip authorization checks for requests that go through this filter servletRequest.setAttribute( AuthConfig.DRUID_AUTHENTICATION_RESULT, new AuthenticationResult(AuthConfig.ALLOW_ALL_NAME, AuthConfig.ALLOW_ALL_NAME, AuthConfig.ALLOW_ALL_NAME, null) ); // This request will not go to an Authorizer, so we need to set this for PreResponseAuthorizationCheckFilter servletRequest.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); filterChain.doFilter(servletRequest, servletResponse); }
@Override @Nullable public AuthenticationResult authenticateJDBCContext(Map<String, Object> context) { String user = (String) context.get("user"); String password = (String) context.get("password"); if (user == null || password == null) { return null; } if (checkCredentials(user, password.toCharArray())) { return new AuthenticationResult(user, authorizerName, name, null); } else { return null; } }
@Override public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException { HttpServletRequest httpReq = (HttpServletRequest) request; // Druid itself doesn't explictly handle OPTIONS requests, no resource handler will authorize such requests. // so this filter catches all OPTIONS requests and authorizes them. if (HttpMethod.OPTIONS.equals(httpReq.getMethod())) { if (httpReq.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT) == null) { // If the request already had credentials and authenticated successfully, keep the authenticated identity. // Otherwise, allow the unauthenticated request. if (allowUnauthenticatedHttpOptions) { httpReq.setAttribute( AuthConfig.DRUID_AUTHENTICATION_RESULT, new AuthenticationResult(AuthConfig.ALLOW_ALL_NAME, AuthConfig.ALLOW_ALL_NAME, null, null) ); } else { ((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } } httpReq.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); } chain.doFilter(request, response); }
AuthenticationResult authenticationResult = new AuthenticationResult(user, authorizerName, name, null); servletRequest.setAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT, authenticationResult); } else {