Skip to content

Commit

Permalink
javadoc
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Oct 3, 2023
1 parent 641c195 commit 74a925d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 70 deletions.
66 changes: 0 additions & 66 deletions src/main/java/org/opensearch/security/filter/NettyRequest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import io.netty.handler.ssl.SslHandler;

/**
* Wraps the functionality of RestRequest for use in the security plugin
*/
public class OpenSearchRequest implements SecurityRequest {

protected final RestRequest underlyingRequest;
Expand Down Expand Up @@ -68,6 +71,7 @@ public Map<String, String> params() {
return underlyingRequest.params();
}

/** Gets access to the underlying request object */
public RestRequest breakEncapsulationForRequest() {
return underlyingRequest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public boolean completeWithResponse(int statusCode, Map<String, String> headers,
throw new UnsupportedOperationException("Channel was not defined");
}

if (hasCompleted()) {
throw new UnsupportedOperationException("This channel has already completed");
}

try {
final BytesRestResponse restResponse = new BytesRestResponse(RestStatus.fromCode(statusCode), body);
if (headers != null) {
Expand All @@ -54,6 +58,7 @@ public void markCompleted() {
hasCompleted.set(true);
}

/** Gets access to the underlying channel object */
public RestChannel breakEncapsulationForChannel() {
return underlyingChannel;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/opensearch/security/filter/SecurityRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@

import org.opensearch.rest.RestRequest.Method;

/** How the security plugin interacts with requests */
public interface SecurityRequest {

/** Collection of headers associated with the request */
public Map<String, List<String>> getHeaders();

/** The SSLEngine associated with the request */
public SSLEngine getSSLEngine();

/** The path of the request */
public String path();

/** The method type of this request */
public Method method();

/** The remote address of the request, possible null */
public Optional<InetSocketAddress> getRemoteAddress();

/** The full uri of the request */
public String uri();

/** Finds the first value of the matching header or null */
default public String header(final String headerName) {
final Optional<Map<String, List<String>>> headersMap = Optional.ofNullable(getHeaders());
return headersMap.map(headers -> headers.get(headerName)).map(List::stream).flatMap(Stream::findFirst).orElse(null);
}

/** The parameters associated with this request */
public Map<String, String> params();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
*/
public interface SecurityRequestChannel extends SecurityRequest {

/**
* If this channel has been been used to send a response
*/
public boolean hasCompleted();

/** Use this channel to send a response */
public boolean completeWithResponse(final int statusCode, final Map<String, String> headers, final String body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import org.opensearch.rest.RestChannel;
import org.opensearch.rest.RestRequest;

/**
* Generates wrapped versions of requests for use in the security plugin
*/
public class SecurityRequestFactory {

public static SecurityRequestChannel from() {
return null;
}

/** Creates a security requset from a RestRequest */
public static SecurityRequest from(final RestRequest request) {
return new OpenSearchRequest(request);
}

/** Creates a security request channel from a RestRequest & RestChannel */
public static SecurityRequestChannel from(final RestRequest request, final RestChannel channel) {
return new OpenSearchRequestChannel(request, channel);
}
Expand Down

0 comments on commit 74a925d

Please sign in to comment.