Skip to content

Commit

Permalink
Minor refactoring of class and method names
Browse files Browse the repository at this point in the history
  • Loading branch information
kirktrue committed Feb 21, 2025
1 parent cf1abbf commit 7f62a08
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @see ClientCredentialsAccessTokenRetriever
* @see DefaultAccessTokenRetriever
* @see FileTokenRetriever
* @see FileAccessTokenRetriever
* @see HttpAccessTokenRetriever
* @see JwtBearerAccessTokenRetriever
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ConfigurationUtils(Map<String, ?> configs, String saslMechanism) {
* ignored. Any whitespace is trimmed off of the beginning and end.
*/

public Path validateFile(String name) {
public File validateFile(String name) {
URL url = validateUrl(name);
File file;

Expand All @@ -85,7 +85,7 @@ public Path validateFile(String name) {
if (file.isDirectory())
throw new ConfigException(String.format("The OAuth configuration option %s references a directory (%s), not a file", name, file));

return file.toPath();
return file;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void configure(Map<String, ?> configs, String saslMechanism, List<AppConf
URL tokenEndpointUrl = cu.validateUrl(SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL);

if (tokenEndpointUrl.getProtocol().toLowerCase(Locale.ROOT).equals("file")) {
delegate = new FileTokenRetriever();
delegate = new FileAccessTokenRetriever();
} else {
String grantType = cu.validateString(SASL_OAUTHBEARER_TOKEN_ENDPOINT_GRANT_TYPE, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.kafka.common.KafkaException;
import org.apache.kafka.common.utils.Utils;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand All @@ -34,17 +35,17 @@
*
* @see AccessTokenRetriever
*/
public class FileTokenRetriever implements AccessTokenRetriever {
public class FileAccessTokenRetriever implements AccessTokenRetriever {

private String accessToken;

@Override
public void configure(Map<String, ?> configs, String saslMechanism, List<AppConfigurationEntry> jaasConfigEntries) {
ConfigurationUtils cu = new ConfigurationUtils(configs, saslMechanism);
String accessTokenFileName = cu.validateFile(SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL).toFile().getPath();
File accessTokenFileName = cu.validateFile(SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL);

try {
String fileContents = Utils.readFileAsString(accessTokenFileName);
String fileContents = Utils.readFileAsString(accessTokenFileName.getPath());
// always non-null; to remove any newline chars or backend will report err
accessToken = fileContents.trim();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.security.Key;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -91,12 +92,12 @@ public class JwksFileVerificationKeyResolver implements CloseableVerificationKey
@Override
public void configure(Map<String, ?> configs, String saslMechanism, List<AppConfigurationEntry> jaasConfigEntries) {
ConfigurationUtils cu = new ConfigurationUtils(configs, saslMechanism);
String jwksFileName = cu.validateFile(SASL_OAUTHBEARER_JWKS_ENDPOINT_URL).toFile().getPath();
log.debug("Starting creation of new VerificationKeyResolver from {}", jwksFileName);
File jwksFile = cu.validateFile(SASL_OAUTHBEARER_JWKS_ENDPOINT_URL);
log.debug("Starting creation of new VerificationKeyResolver from {}", jwksFile.getPath());
JsonWebKeySet jwks;

try {
String json = Utils.readFileAsString(jwksFileName);
String json = Utils.readFileAsString(jwksFile.getPath());
jwks = new JsonWebKeySet(json);
} catch (Exception e) {
throw new KafkaException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.kafka.common.security.oauthbearer.internals.secured.AccessTokenRetriever;
import org.apache.kafka.common.security.oauthbearer.internals.secured.AccessTokenValidator;
import org.apache.kafka.common.security.oauthbearer.internals.secured.DefaultAccessTokenRetriever;
import org.apache.kafka.common.security.oauthbearer.internals.secured.FileTokenRetriever;
import org.apache.kafka.common.security.oauthbearer.internals.secured.FileAccessTokenRetriever;
import org.apache.kafka.common.security.oauthbearer.internals.secured.HttpAccessTokenRetriever;
import org.apache.kafka.common.security.oauthbearer.internals.secured.LoginAccessTokenValidator;
import org.apache.kafka.common.security.oauthbearer.internals.secured.OAuthBearerTest;
Expand Down Expand Up @@ -224,7 +224,7 @@ public void testConfigureWithAccessTokenFile() throws Exception {
Map<String, Object> jaasConfig = Collections.emptyMap();
configureHandler(handler, configs, jaasConfig);
assertInstanceOf(DefaultAccessTokenRetriever.class, handler.accessTokenRetriever);
assertInstanceOf(FileTokenRetriever.class, ((DefaultAccessTokenRetriever) handler.accessTokenRetriever).delegate());
assertInstanceOf(FileAccessTokenRetriever.class, ((DefaultAccessTokenRetriever) handler.accessTokenRetriever).delegate());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class FileTokenRetrieverTest extends OAuthBearerTest {
public class FileAccessTokenRetrieverTest extends OAuthBearerTest {

@Test
public void testFileTokenRetrieverHandlesNewline() throws IOException {
Expand Down

0 comments on commit 7f62a08

Please sign in to comment.