forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Mutual TLS authentication for Core Peer Forwarding. Resolves o…
…pensearch-project#1758. (opensearch-project#1771) Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
16 changed files
with
458 additions
and
59 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...core/src/main/java/org/opensearch/dataprepper/peerforwarder/ForwardingAuthentication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.peerforwarder; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public enum ForwardingAuthentication { | ||
MUTUAL_TLS("mutual_tls"), | ||
UNAUTHENTICATED("unauthenticated"); | ||
|
||
private static final Map<String, ForwardingAuthentication> STRING_NAME_TO_ENUM_MAP = new HashMap<>(); | ||
|
||
private final String name; | ||
|
||
static { | ||
Arrays.stream(ForwardingAuthentication.values()) | ||
.forEach(enumValue -> STRING_NAME_TO_ENUM_MAP.put(enumValue.name, enumValue)); | ||
} | ||
|
||
ForwardingAuthentication(final String name){ | ||
this.name = name; | ||
} | ||
|
||
public String getName(){ | ||
return name; | ||
} | ||
|
||
static ForwardingAuthentication getByName(final String name) { | ||
return Optional.ofNullable(STRING_NAME_TO_ENUM_MAP.get(name)) | ||
.orElseThrow(() -> new IllegalArgumentException("Unrecognized ForwardingAuthentication: " + name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../src/test/java/org/opensearch/dataprepper/peerforwarder/ForwardingAuthenticationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.peerforwarder; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
|
||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
class ForwardingAuthenticationTest { | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(EnumToStringNameArgumentsProvider.class) | ||
void getValue_returns_expected_value (final ForwardingAuthentication enumValue, final String expectedName) { | ||
assertThat(enumValue.getName(), equalTo(expectedName)); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(ForwardingAuthentication.class) | ||
void getByName_returns_correct_enum_from_expected_name(final ForwardingAuthentication enumValue) { | ||
|
||
final String stringName = enumValue.getName(); | ||
|
||
assertThat(ForwardingAuthentication.getByName(stringName), equalTo(enumValue)); | ||
} | ||
|
||
@Test | ||
void getByName_throws_for_null() { | ||
assertThrows(IllegalArgumentException.class, () -> ForwardingAuthentication.getByName(null)); | ||
} | ||
|
||
@Test | ||
void getByName_throws_for_empty_string() { | ||
assertThrows(IllegalArgumentException.class, () -> ForwardingAuthentication.getByName("")); | ||
} | ||
|
||
@Test | ||
void getByName_throws_for_unrecognized_non_empty_name() { | ||
assertThrows(IllegalArgumentException.class, () -> ForwardingAuthentication.getByName(UUID.randomUUID().toString())); | ||
} | ||
|
||
private static class EnumToStringNameArgumentsProvider implements ArgumentsProvider { | ||
@Override | ||
public Stream<? extends Arguments> provideArguments(final ExtensionContext context) { | ||
return Stream.of( | ||
arguments(ForwardingAuthentication.MUTUAL_TLS, "mutual_tls"), | ||
arguments(ForwardingAuthentication.UNAUTHENTICATED, "unauthenticated") | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.