Skip to content

Commit

Permalink
feat(provider/kafka): add new resource KafkaUser (#391)
Browse files Browse the repository at this point in the history
Fix: #391
  • Loading branch information
fhussonnois committed Jul 4, 2024
1 parent 2e8db24 commit 015af5b
Show file tree
Hide file tree
Showing 35 changed files with 1,575 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,34 @@ public static Set<Class<?>> getSuperTypes(final Class<?> type) {
}
return result;
}


/**
* Converts a class simple name into kebab case.
*
* @param clazz the class simple name to be converted
* @return the kebab case representation of the class simple name
*/
public static String toKebabCase(final Class<?> clazz) {
if (clazz == null) {
return "";
}

StringBuilder kebabCase = new StringBuilder();
char[] chars = clazz.getSimpleName().toCharArray();

for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (Character.isUpperCase(c)) {
if (i != 0) {
kebabCase.append('-');
}
kebabCase.append(Character.toLowerCase(c));
} else {
kebabCase.append(c);
}
}

return kebabCase.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) The original authors
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.streamthoughts.jikkou.common.utils;

import java.security.SecureRandom;

/**
* Service interface for generating secure passwords.
*/
public interface SecurePasswordGenerator {

/**
* Generates a random secure password of the given length.
*
* @param length The length of the password to generate.
* @return a secure random generated password.
*/
String generate(int length);

static SecurePasswordGenerator getDefault() {
return new DefaultSecurePasswordGenerator();
}

/**
* Default implementation for {@link SecurePasswordGenerator}.
*/
class DefaultSecurePasswordGenerator implements SecurePasswordGenerator {
// Character sets to use in generated passwords
private static final String LOWERCASE_LETTERS = "abcdefghijklmnopqrstuvwxyz";
private static final String UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String DIGITS = "0123456789";
private static final String SPECIAL_CHARACTERS = "!@#$%^&*()-_=+?/~";
private static final String ALL_CHARACTERS = LOWERCASE_LETTERS + UPPERCASE_LETTERS + DIGITS + SPECIAL_CHARACTERS;

/**
* {@inheritDoc}
*/
@Override
public String generate(int length) {
SecureRandom random = new SecureRandom();
StringBuilder password = new StringBuilder(length);

// Ensure the password has at least one character from each character set
password.append(LOWERCASE_LETTERS.charAt(random.nextInt(LOWERCASE_LETTERS.length())));
password.append(UPPERCASE_LETTERS.charAt(random.nextInt(UPPERCASE_LETTERS.length())));
password.append(DIGITS.charAt(random.nextInt(DIGITS.length())));
password.append(SPECIAL_CHARACTERS.charAt(random.nextInt(SPECIAL_CHARACTERS.length())));

// Fill the rest of the password length with random characters from all character sets
for (int i = 4; i < length; i++) {
password.append(ALL_CHARACTERS.charAt(random.nextInt(ALL_CHARACTERS.length())));
}

// Shuffle the characters to ensure randomness
for (int i = password.length() - 1; i > 0; i--) {
int index = random.nextInt(i + 1);
char temp = password.charAt(index);
password.setCharAt(index, password.charAt(i));
password.setCharAt(i, temp);
}
return password.toString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) The original authors
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.streamthoughts.jikkou.core.exceptions;

/**
* An unchecked wrapper for {@link java.lang.InterruptedException}
*/
public class InterruptedException extends JikkouRuntimeException {

public InterruptedException(java.lang.InterruptedException cause) {
super(cause);
Thread.currentThread().interrupt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public interface Jackson {
.serializationInclusion(JsonInclude.Include.NON_ABSENT)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
.disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID)
.build();

ObjectMapper JSON_OBJECT_MAPPER = JsonMapper.builder()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public DefaultResourceListObjectBuilder<T> withItems(List<T> items) {
}

public DefaultResourceListObject<T> build() {
return new DefaultResourceListObject<T>(this.kind, this.apiVersion, this.metadata, this.items);
return new DefaultResourceListObject<>(this.kind, this.apiVersion, this.metadata, this.items);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public interface HasMetadata extends Resource {
* @param metadata the object meta to set.
* @return a new object.
*/
HasMetadata withMetadata(ObjectMeta metadata);
default HasMetadata withMetadata(ObjectMeta metadata) {
throw new UnsupportedOperationException();
}

/**
* Gets the optional metadata.
Expand Down
Loading

0 comments on commit 015af5b

Please sign in to comment.