KafkaUserModel { public static String decodeUsername(String username) { if (username.contains("CN=")) { try { return new LdapName(username).getRdns().stream() .filter(rdn -> rdn.getType().equalsIgnoreCase("cn")) .map(rdn -> rdn.getValue().toString()).collect(Collectors.joining()); } catch (InvalidNameException e) { throw new IllegalArgumentException(e); } } else { return username; } } protected  KafkaUserModel(String namespace, String name, Labels labels); static KafkaUserModel fromCrd(CertManager certManager,
                                         PasswordGenerator passwordGenerator,
                                         KafkaUser kafkaUser,
                                         Secret clientsCaCert,
                                         Secret clientsCaKey,
                                         Secret userSecret); Secret generateSecret(); @SuppressWarnings("checkstyle:BooleanExpressionComplexity") void maybeGenerateCertificates(CertManager certManager, PasswordGenerator passwordGenerator,
                                          Secret clientsCaCertSecret, Secret clientsCaKeySecret,
                                          Secret userSecret, int validityDays, int renewalDays); void maybeGeneratePassword(PasswordGenerator generator, Secret userSecret); static String decodeUsername(String username); static String getTlsUserName(String username); static String getScramUserName(String username); String getUserName(); String getName(); static String getSecretName(String username); String getSecretName(); void setAuthentication(KafkaUserAuthentication authentication); void setQuotas(KafkaUserQuotas quotas); KafkaUserQuotas getQuotas(); Set<SimpleAclRule> getSimpleAclRules(); void setSimpleAclRules(List<AclRule> rules); boolean isTlsUser(); boolean isScramUser(); boolean isNoneUser(); static final String KEY_PASSWORD; static final String ENV_VAR_CLIENTS_CA_VALIDITY; static final String ENV_VAR_CLIENTS_CA_RENEWAL; static final String KAFKA_USER_OPERATOR_NAME; }
@Test public void testDecodeUsername() { assertThat(KafkaUserModel.decodeUsername("CN=my-user"), is("my-user")); assertThat(KafkaUserModel.decodeUsername("CN=my-user,OU=my-org"), is("my-user")); assertThat(KafkaUserModel.decodeUsername("OU=my-org,CN=my-user"), is("my-user")); }