mneethiraj commented on code in PR #857: URL: https://github.com/apache/ranger/pull/857#discussion_r2849485476
########## agents-common/src/main/java/org/apache/ranger/plugin/authn/DefaultJwtProvider.java: ########## @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ranger.plugin.authn; + +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.ranger.authorization.hadoop.utils.RangerCredentialProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class DefaultJwtProvider implements JwtProvider { + private static final Logger LOG = LoggerFactory.getLogger(DefaultJwtProvider.class); + public static final String JWT_SOURCE = ".jwt.source"; + public static final String JWT_ENV = ".jwt.env"; + public static final String JWT_FILE = ".jwt.file"; + public static final String JWT_CRED_FILE = ".jwt.cred.file"; + public static final String JWT_CRED_ALIAS = ".jwt.cred.alias"; + + private final String propertyPrefix; + private final Configuration config; + private String jwt; + + public DefaultJwtProvider(String propertyPrefix, Configuration config){ + this.propertyPrefix = propertyPrefix; + this.config = config; + } + + @Override + public String getJwt() { Review Comment: Consider initializing `jwt` in the constructor and have `getAwt()` method simply return it. ``` public class DefaultJwtProvider implements JwtProvider { ... private final String jwt; public DefaultJwtProvider(String propertyPrefix, Configuration config) { ... this.jwt = readJwt(); } @Override public String getJwt() { return jwt; } private String readJwt() { ... } ########## agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java: ########## @@ -773,14 +777,15 @@ private Client buildClient() { return client; } - private void setJWTFilter(String jwtAsString) { - if (StringUtils.isNotBlank(jwtAsString)) { + private void setJWTFilter() { + if (jwtProvider != null) { Review Comment: Assign `this.jwtProvider` to a local variable before referencing it, to avoid potential NPE due to another thread calling `setJwtProvider(null)`. ``` JwtProvider jwtProvider = this.jwtProvider; if (jwtProvider != null) { ... } ########## agents-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPluginContext.java: ########## @@ -163,6 +170,14 @@ public RangerAdminClient createAdminClient(RangerPluginConfig pluginConfig) { return ret; } + public void registerJWTProvider(JwtProvider jwtProvider) { + this.jwtProvider = jwtProvider; Review Comment: `adminClient` should be updated of the new JwtProvider, right? ``` RangerAdminRESTClient restClient = (adminClient instanceof RangerAdminRESTClient) ? (RangerAdminRESTClient) adminClient : null; if (restClient != null) { restClient.setJwtProvider(jwtProvider); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
