Skip to content

Commit

Permalink
support configurable authMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzming committed Jan 24, 2020
1 parent a08f32f commit 09925f7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public final class AuthFactory {
private AuthFactory() {}

/**
* Request JWT from autho and pass the JWT to pulsar broker.
* Request JWT from auth0 and pass the JWT to pulsar broker.
* @param domain
* @param clientId
* @param clientSecret
Expand All @@ -20,4 +20,22 @@ public static Authentication auth0(String domain, String clientId, String client
return new AuthenticationAuth0(Auth0JWT.create(domain, clientId, clientSecret, audience).generateAndCheck());

}

/**
* Request JWT from auth0 with optional authMethod.
* @param domain
* @param clientId
* @param clientSecret
* @param audience
* @param authMethod
* @return
*/
public static Authentication auth0(String domain, String clientId, String clientSecret, String audience, String authMethod) {
String token = Auth0JWT.create(domain, clientId, clientSecret, audience).generateAndCheck();

AuthenticationAuth0 auth0 = new AuthenticationAuth0(token);
auth0.setAuthMethodName(authMethod);
return auth0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.kafkaesque.pulsar.client.auth;

import java.util.Arrays;
import java.util.List;

public final class AuthMethod {

public final static String TOKEN = "token";

public final static String AUTH0 = "auth0";

public final static List<String> supportedMethods = Arrays.asList(TOKEN, AUTH0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class AuthenticationAuth0 implements Authentication, EncodedAuthenticatio
private static final long serialVersionUID = 1L;
private Supplier<String> tokenSupplier;

private String authMethod = AuthMethod.AUTH0;

public AuthenticationAuth0(String token) {
this(() -> token);
}
Expand All @@ -40,7 +42,15 @@ public void close() throws IOException {

@Override
public String getAuthMethodName() {
return "auth0";
return authMethod;
}

public void setAuthMethodName(String name) {
if (AuthMethod.supportedMethods.contains(name)) {
authMethod = name;
} else {
throw new IllegalArgumentException("unsupport auth method " + name);
}
}

@Override
Expand Down

0 comments on commit 09925f7

Please sign in to comment.