use of org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse in project kafka by apache.
the class KafkaAdminClient method describeUserScramCredentials.
@Override
public DescribeUserScramCredentialsResult describeUserScramCredentials(List<String> users, DescribeUserScramCredentialsOptions options) {
final KafkaFutureImpl<DescribeUserScramCredentialsResponseData> dataFuture = new KafkaFutureImpl<>();
final long now = time.milliseconds();
Call call = new Call("describeUserScramCredentials", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {
@Override
public DescribeUserScramCredentialsRequest.Builder createRequest(final int timeoutMs) {
final DescribeUserScramCredentialsRequestData requestData = new DescribeUserScramCredentialsRequestData();
if (users != null && !users.isEmpty()) {
final List<UserName> userNames = new ArrayList<>(users.size());
for (final String user : users) {
if (user != null) {
userNames.add(new UserName().setName(user));
}
}
requestData.setUsers(userNames);
}
return new DescribeUserScramCredentialsRequest.Builder(requestData);
}
@Override
public void handleResponse(AbstractResponse abstractResponse) {
DescribeUserScramCredentialsResponse response = (DescribeUserScramCredentialsResponse) abstractResponse;
DescribeUserScramCredentialsResponseData data = response.data();
short messageLevelErrorCode = data.errorCode();
if (messageLevelErrorCode != Errors.NONE.code()) {
dataFuture.completeExceptionally(Errors.forCode(messageLevelErrorCode).exception(data.errorMessage()));
} else {
dataFuture.complete(data);
}
}
@Override
void handleFailure(Throwable throwable) {
dataFuture.completeExceptionally(throwable);
}
};
runnable.call(call, now);
return new DescribeUserScramCredentialsResult(dataFuture);
}
use of org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse in project kafka by apache.
the class KafkaAdminClientTest method testDescribeUserScramCredentials.
@Test
public void testDescribeUserScramCredentials() throws Exception {
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
final String user0Name = "user0";
final ScramMechanism user0ScramMechanism0 = ScramMechanism.SCRAM_SHA_256;
final int user0Iterations0 = 4096;
final ScramMechanism user0ScramMechanism1 = ScramMechanism.SCRAM_SHA_512;
final int user0Iterations1 = 8192;
final CredentialInfo user0CredentialInfo0 = new CredentialInfo();
user0CredentialInfo0.setMechanism(user0ScramMechanism0.type());
user0CredentialInfo0.setIterations(user0Iterations0);
final CredentialInfo user0CredentialInfo1 = new CredentialInfo();
user0CredentialInfo1.setMechanism(user0ScramMechanism1.type());
user0CredentialInfo1.setIterations(user0Iterations1);
final String user1Name = "user1";
final ScramMechanism user1ScramMechanism = ScramMechanism.SCRAM_SHA_256;
final int user1Iterations = 4096;
final CredentialInfo user1CredentialInfo = new CredentialInfo();
user1CredentialInfo.setMechanism(user1ScramMechanism.type());
user1CredentialInfo.setIterations(user1Iterations);
final DescribeUserScramCredentialsResponseData responseData = new DescribeUserScramCredentialsResponseData();
responseData.setResults(Arrays.asList(new DescribeUserScramCredentialsResponseData.DescribeUserScramCredentialsResult().setUser(user0Name).setCredentialInfos(Arrays.asList(user0CredentialInfo0, user0CredentialInfo1)), new DescribeUserScramCredentialsResponseData.DescribeUserScramCredentialsResult().setUser(user1Name).setCredentialInfos(singletonList(user1CredentialInfo))));
final DescribeUserScramCredentialsResponse response = new DescribeUserScramCredentialsResponse(responseData);
final Set<String> usersRequestedSet = new HashSet<>();
usersRequestedSet.add(user0Name);
usersRequestedSet.add(user1Name);
for (final List<String> users : asList(null, new ArrayList<String>(), asList(user0Name, null, user1Name))) {
env.kafkaClient().prepareResponse(response);
final DescribeUserScramCredentialsResult result = env.adminClient().describeUserScramCredentials(users);
final Map<String, UserScramCredentialsDescription> descriptionResults = result.all().get();
final KafkaFuture<UserScramCredentialsDescription> user0DescriptionFuture = result.description(user0Name);
final KafkaFuture<UserScramCredentialsDescription> user1DescriptionFuture = result.description(user1Name);
final Set<String> usersDescribedFromUsersSet = new HashSet<>(result.users().get());
assertEquals(usersRequestedSet, usersDescribedFromUsersSet);
final Set<String> usersDescribedFromMapKeySet = descriptionResults.keySet();
assertEquals(usersRequestedSet, usersDescribedFromMapKeySet);
final UserScramCredentialsDescription userScramCredentialsDescription0 = descriptionResults.get(user0Name);
assertEquals(user0Name, userScramCredentialsDescription0.name());
assertEquals(2, userScramCredentialsDescription0.credentialInfos().size());
assertEquals(user0ScramMechanism0, userScramCredentialsDescription0.credentialInfos().get(0).mechanism());
assertEquals(user0Iterations0, userScramCredentialsDescription0.credentialInfos().get(0).iterations());
assertEquals(user0ScramMechanism1, userScramCredentialsDescription0.credentialInfos().get(1).mechanism());
assertEquals(user0Iterations1, userScramCredentialsDescription0.credentialInfos().get(1).iterations());
assertEquals(userScramCredentialsDescription0, user0DescriptionFuture.get());
final UserScramCredentialsDescription userScramCredentialsDescription1 = descriptionResults.get(user1Name);
assertEquals(user1Name, userScramCredentialsDescription1.name());
assertEquals(1, userScramCredentialsDescription1.credentialInfos().size());
assertEquals(user1ScramMechanism, userScramCredentialsDescription1.credentialInfos().get(0).mechanism());
assertEquals(user1Iterations, userScramCredentialsDescription1.credentialInfos().get(0).iterations());
assertEquals(userScramCredentialsDescription1, user1DescriptionFuture.get());
}
}
}
Aggregations