Skip to content

Commit

Permalink
Fixes spotless errors
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Sep 28, 2023
1 parent 09f4339 commit 15b4d6a
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean validateToken(AuthToken token) {
if (token instanceof BasicAuthToken) {
final BasicAuthToken basicAuthToken = (BasicAuthToken) token;
return basicAuthToken.getUser().equals(SecurityUtils.getSubject().toString())
&& basicAuthToken.getPassword().equals(shiroTokenPasswordMap.get(basicAuthToken));
&& basicAuthToken.getPassword().equals(shiroTokenPasswordMap.get(basicAuthToken));
}
return false;
}
Expand Down Expand Up @@ -140,10 +140,10 @@ public String generatePassword() {
CharacterRule specialCharacterRule = new CharacterRule(EnglishCharacterData.Special, 1);

List<CharacterRule> rules = Arrays.asList(
lowercaseCharacterRule,
uppercaseCharacterRule,
numericCharacterRule,
specialCharacterRule
lowercaseCharacterRule,
uppercaseCharacterRule,
numericCharacterRule,
specialCharacterRule
);
PasswordGenerator passwordGenerator = new PasswordGenerator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.junit.Before;
import org.opensearch.identity.Subject;
import org.opensearch.identity.noop.NoopSubject;
import org.opensearch.identity.noop.NoopTokenManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,42 @@
*/
public class InitializeExtensionSecurityRequest extends TransportRequest {

private final String serviceAccountToken;

public InitializeExtensionSecurityRequest(String serviceAccountToken) {
this.serviceAccountToken = serviceAccountToken;
}

public InitializeExtensionSecurityRequest(StreamInput in) throws IOException {
super(in);
serviceAccountToken = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(serviceAccountToken);
}

public String getServiceAccountToken() {
return serviceAccountToken;
}

@Override
public String toString() {
return "InitializeExtensionsRequest{" + "serviceAccountToken= " + serviceAccountToken + "}";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InitializeExtensionSecurityRequest that = (InitializeExtensionSecurityRequest) o;
return Objects.equals(serviceAccountToken, that.serviceAccountToken);
}

@Override
public int hashCode() {
return Objects.hash(serviceAccountToken);
}
private final String serviceAccountToken;

public InitializeExtensionSecurityRequest(String serviceAccountToken) {
this.serviceAccountToken = serviceAccountToken;
}

public InitializeExtensionSecurityRequest(StreamInput in) throws IOException {
super(in);
serviceAccountToken = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(serviceAccountToken);
}

public String getServiceAccountToken() {
return serviceAccountToken;
}

@Override
public String toString() {
return "InitializeExtensionsRequest{" + "serviceAccountToken= " + serviceAccountToken + "}";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InitializeExtensionSecurityRequest that = (InitializeExtensionSecurityRequest) o;
return Objects.equals(serviceAccountToken, that.serviceAccountToken);
}

@Override
public int hashCode() {
return Objects.hash(serviceAccountToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,44 @@
* @opensearch.internal
*/
public class InitializeExtensionSecurityResponse extends TransportResponse {
private String name;
private String name;

public InitializeExtensionSecurityResponse(String name) {
this.name = name;
}
public InitializeExtensionSecurityResponse(String name) {
this.name = name;
}

public InitializeExtensionSecurityResponse(StreamInput in) throws IOException {
name = in.readString();
}
public InitializeExtensionSecurityResponse(StreamInput in) throws IOException {
name = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
}

/**
* @return the node that is currently leading, according to the responding node.
*/
/**
* @return the node that is currently leading, according to the responding node.
*/

public String getName() {
return this.name;
}
public String getName() {
return this.name;
}

@Override
public String toString() {
return "InitializeExtensionResponse{" + "name = " + name + "}";
}
@Override
public String toString() {
return "InitializeExtensionResponse{" + "name = " + name + "}";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InitializeExtensionSecurityResponse that = (InitializeExtensionSecurityResponse) o;
return Objects.equals(name, that.name);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InitializeExtensionSecurityResponse that = (InitializeExtensionSecurityResponse) o;
return Objects.equals(name, that.name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

package org.opensearch.extensions;

import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
Expand Down Expand Up @@ -38,6 +35,8 @@
import org.opensearch.extensions.action.ExtensionActionRequest;
import org.opensearch.extensions.action.ExtensionActionResponse;
import org.opensearch.extensions.action.ExtensionTransportActionsHandler;
import org.opensearch.extensions.action.IssueServiceAccountRequest;
import org.opensearch.extensions.action.IssueServiceAccountResponse;
import org.opensearch.extensions.action.RegisterTransportActionsRequest;
import org.opensearch.extensions.action.RemoteExtensionActionResponse;
import org.opensearch.extensions.action.TransportActionRequestFromExtension;
Expand All @@ -52,8 +51,6 @@
import org.opensearch.transport.TransportException;
import org.opensearch.transport.TransportResponseHandler;
import org.opensearch.transport.TransportService;
import org.opensearch.extensions.action.IssueServiceAccountRequest;
import org.opensearch.extensions.action.IssueServiceAccountResponse;

import java.io.IOException;
import java.net.InetAddress;
Expand All @@ -63,6 +60,9 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -99,7 +99,6 @@ public static enum OpenSearchRequestType {
REQUEST_OPENSEARCH_NAMED_WRITEABLE_REGISTRY
}


private ExtensionTransportActionsHandler extensionTransportActionsHandler;
private Map<String, Extension> extensionSettingsMap;
private Map<String, DiscoveryExtensionNode> initializedExtensions;
Expand Down Expand Up @@ -423,38 +422,38 @@ protected void doRun() throws Exception {
private void initializeExtensionSecurity(DiscoveryExtensionNode extension) {
final CompletableFuture<InitializeExtensionSecurityResponse> inProgressFuture = new CompletableFuture<>();
final TransportResponseHandler<InitializeExtensionSecurityResponse> initializeExtensionSecurityResponseHandler =
new TransportResponseHandler<InitializeExtensionSecurityResponse>() {
new TransportResponseHandler<InitializeExtensionSecurityResponse>() {

@Override
public InitializeExtensionSecurityResponse read(StreamInput in) throws IOException {
return new InitializeExtensionSecurityResponse(in);
}
@Override
public InitializeExtensionSecurityResponse read(StreamInput in) throws IOException {
return new InitializeExtensionSecurityResponse(in);
}

@Override
public void handleResponse(InitializeExtensionSecurityResponse response) {
System.out.println("Registered security settings for " + response.getName());
inProgressFuture.complete(response);
}
@Override
public void handleResponse(InitializeExtensionSecurityResponse response) {
System.out.println("Registered security settings for " + response.getName());
inProgressFuture.complete(response);
}

@Override
public void handleException(TransportException exp) {
logger.error(new ParameterizedMessage("Extension initialization failed"), exp);
inProgressFuture.completeExceptionally(exp);
}
@Override
public void handleException(TransportException exp) {
logger.error(new ParameterizedMessage("Extension initialization failed"), exp);
inProgressFuture.completeExceptionally(exp);
}

@Override
public String executor() {
return ThreadPool.Names.GENERIC;
}
};
@Override
public String executor() {
return ThreadPool.Names.GENERIC;
}
};
try {
logger.info("Sending extension request type: " + REQUEST_EXTENSION_REGISTER_SECURITY_SETTINGS);
AuthToken serviceAccountToken = identityService.getTokenManager().issueServiceAccountToken(extension.getId());
transportService.sendRequest(
extension,
REQUEST_EXTENSION_REGISTER_SECURITY_SETTINGS,
new InitializeExtensionSecurityRequest(serviceAccountToken.asAuthHeaderValue()),
initializeExtensionSecurityResponseHandler
extension,
REQUEST_EXTENSION_REGISTER_SECURITY_SETTINGS,
new InitializeExtensionSecurityRequest(serviceAccountToken.asAuthHeaderValue()),
initializeExtensionSecurityResponseHandler
);

inProgressFuture.orTimeout(EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS).join();
Expand Down Expand Up @@ -517,7 +516,7 @@ public void issueServiceAccount(Extension extension) {
String authTokenAsString = serviceAccountToken.asAuthHeaderValue();
final CompletableFuture<IssueServiceAccountResponse> inProgressFuture = new CompletableFuture<>();
final TransportResponseHandler<IssueServiceAccountResponse> issueServiceAccountResponseHandler = new TransportResponseHandler<
IssueServiceAccountResponse>() {
IssueServiceAccountResponse>() {

@Override
public IssueServiceAccountResponse read(StreamInput in) throws IOException {
Expand All @@ -528,7 +527,7 @@ public IssueServiceAccountResponse read(StreamInput in) throws IOException {
public void handleResponse(IssueServiceAccountResponse response) {
for (DiscoveryExtensionNode extension : extensionIdMap.values()) {
if (extension.getName().equals(response.getName())
&& (serviceAccountToken.equals(response.getServiceAccountString()))) {
&& (serviceAccountToken.equals(response.getServiceAccountString()))) {
logger.info("Successfully issued service account token to extension: " + extension.getName());
break;
}
Expand All @@ -549,15 +548,13 @@ public String executor() {
};

transportService.sendRequest(
discoveryExtensionNode,
REQUEST_EXTENSION_ISSUE_SERVICE_ACCOUNT,
new IssueServiceAccountRequest(authTokenAsString),
issueServiceAccountResponseHandler
discoveryExtensionNode,
REQUEST_EXTENSION_ISSUE_SERVICE_ACCOUNT,
new IssueServiceAccountRequest(authTokenAsString),
issueServiceAccountResponseHandler
);
}



static String getRequestExtensionActionName() {
return REQUEST_EXTENSION_ACTION_NAME;
}
Expand Down Expand Up @@ -614,7 +611,6 @@ void setCustomSettingsRequestHandler(CustomSettingsRequestHandler customSettings
this.customSettingsRequestHandler = customSettingsRequestHandler;
}


public void setIdentityService(IdentityService identityService) {
this.identityService = identityService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package org.opensearch.extensions;

import java.util.List;
import org.opensearch.action.ActionModule;
import org.opensearch.client.node.NodeClient;
import org.opensearch.cluster.service.ClusterService;
Expand All @@ -21,6 +20,7 @@
import org.opensearch.transport.TransportService;

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.Set;

Expand Down
Loading

0 comments on commit 15b4d6a

Please sign in to comment.