Skip to content

Commit

Permalink
Make authenticator name more concise
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <petern@amazon.com>
  • Loading branch information
peternied authored and RyanL1997 committed Jun 13, 2023
1 parent 5582c5c commit 8c8bb88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
import org.opensearch.security.dlic.rest.validation.PasswordValidator;
import org.opensearch.security.filter.SecurityFilter;
import org.opensearch.security.filter.SecurityRestFilter;
import org.opensearch.security.http.HTTPOnBehalfOfJwtAuthenticator;
import org.opensearch.security.http.OnBehalfOfAuthenticator;
import org.opensearch.security.http.SecurityHttpServerTransport;
import org.opensearch.security.http.SecurityNonSslHttpServerTransport;
import org.opensearch.security.http.XFFResolver;
Expand Down Expand Up @@ -838,8 +838,8 @@ public Collection<Object> createComponents(Client localClient, ClusterService cl

securityRestHandler = new SecurityRestFilter(backendRegistry, auditLog, threadPool,
principalExtractor, settings, configPath, compatConfig);

HTTPOnBehalfOfJwtAuthenticator acInstance = new HTTPOnBehalfOfJwtAuthenticator();
final OnBehalfOfAuthenticator onBehalfOfAuthenticator = new OnBehalfOfAuthenticator();

final DynamicConfigFactory dcf = new DynamicConfigFactory(cr, settings, configPath, localClient, threadPool, cih);
dcf.registerDCFListener(backendRegistry);
Expand All @@ -848,7 +848,7 @@ public Collection<Object> createComponents(Client localClient, ClusterService cl
dcf.registerDCFListener(xffResolver);
dcf.registerDCFListener(evaluator);
dcf.registerDCFListener(securityRestHandler);
dcf.registerDCFListener(acInstance);
dcf.registerDCFListener(onBehalfOfAuthenticator);
if (!(auditLog instanceof NullAuditLog)) {
// Don't register if advanced modules is disabled in which case auditlog is instance of NullAuditLog
dcf.registerDCFListener(auditLog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.opensearch.security.securityconf.DynamicConfigModel;
import org.opensearch.security.user.AuthCredentials;

public class HTTPOnBehalfOfJwtAuthenticator implements HTTPAuthenticator {
public class OnBehalfOfAuthenticator implements HTTPAuthenticator {

protected final Logger log = LogManager.getLogger(this.getClass());

Expand All @@ -58,13 +58,13 @@ public class HTTPOnBehalfOfJwtAuthenticator implements HTTPAuthenticator {
private String signingKey;
private String encryptionKey;

public HTTPOnBehalfOfJwtAuthenticator() {
public OnBehalfOfAuthenticator() {
super();
init();
}

// FOR TESTING
public HTTPOnBehalfOfJwtAuthenticator(String signingKey, String encryptionKey){
public OnBehalfOfAuthenticator(String signingKey, String encryptionKey){
this.signingKey = signingKey;
this.encryptionKey = encryptionKey;
init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.opensearch.security.user.AuthCredentials;
import org.opensearch.security.util.FakeRestRequest;

public class HTTPOnBehalfOfJwtAuthenticatorTest {
public class OnBehalfOfAuthenticatorTest {
final static byte[] secretKeyBytes = new byte[1024];
final static String claimsEncryptionKey = RandomStringUtils.randomAlphanumeric(16);
final static SecretKey secretKey;
Expand Down Expand Up @@ -91,10 +91,7 @@ public void testBadKey() throws Exception {
@Test
public void testTokenMissing() throws Exception {

HTTPOnBehalfOfJwtAuthenticator jwtAuth = new HTTPOnBehalfOfJwtAuthenticator(
BaseEncoding.base64().encode(secretKeyBytes),
claimsEncryptionKey
);
OnBehalfOfAuthenticator jwtAuth = new OnBehalfOfAuthenticator(BaseEncoding.base64().encode(secretKeyBytes),claimsEncryptionKey);
Map<String, String> headers = new HashMap<String, String>();

AuthCredentials credentials = jwtAuth.extractCredentials(new FakeRestRequest(headers, new HashMap<String, String>()), null);
Expand All @@ -107,10 +104,7 @@ public void testInvalid() throws Exception {

String jwsToken = "123invalidtoken..";

HTTPOnBehalfOfJwtAuthenticator jwtAuth = new HTTPOnBehalfOfJwtAuthenticator(
BaseEncoding.base64().encode(secretKeyBytes),
claimsEncryptionKey
);
OnBehalfOfAuthenticator jwtAuth = new OnBehalfOfAuthenticator(BaseEncoding.base64().encode(secretKeyBytes), claimsEncryptionKey);
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "Bearer " + jwsToken);

Expand All @@ -127,10 +121,7 @@ public void testBearer() throws Exception {
.signWith(secretKey, SignatureAlgorithm.HS512)
.compact();

HTTPOnBehalfOfJwtAuthenticator jwtAuth = new HTTPOnBehalfOfJwtAuthenticator(
BaseEncoding.base64().encode(secretKeyBytes),
claimsEncryptionKey
);
OnBehalfOfAuthenticator jwtAuth = new OnBehalfOfAuthenticator(BaseEncoding.base64().encode(secretKeyBytes), claimsEncryptionKey);
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "Bearer " + jwsToken);

Expand Down Expand Up @@ -295,7 +286,7 @@ private AuthCredentials extractCredentialsFromJwtHeader(
final Boolean bwcPluginCompatibilityMode
) {
final String jwsToken = jwtBuilder.signWith(secretKey, SignatureAlgorithm.HS512).compact();
final HTTPOnBehalfOfJwtAuthenticator jwtAuth = new HTTPOnBehalfOfJwtAuthenticator(signingKey, encryptionKey);
final OnBehalfOfAuthenticator jwtAuth = new OnBehalfOfAuthenticator(signingKey, encryptionKey);
final Map<String, String> headers = Map.of("Authorization", "Bearer " + jwsToken);
return jwtAuth.extractCredentials(new FakeRestRequest(headers, new HashMap<>()), null);
}
Expand Down

0 comments on commit 8c8bb88

Please sign in to comment.