-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4b9f23
commit 22b3875
Showing
36 changed files
with
2,100 additions
and
12 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# These are explicitly windows files and should use crlf | ||
*.bat text eol=crlf | ||
|
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,9 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build | ||
|
||
.idea | ||
*.swp | ||
*.swo |
16 changes: 16 additions & 0 deletions
16
...am-rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/AuthenticationData.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,16 @@ | ||
package software.amazon.awssdk.eventstreamrpc; | ||
|
||
/** | ||
* Exact implementation of this is between the EventStreamRPCServiceHandler at the Authentication handler itself | ||
*/ | ||
public interface AuthenticationData { | ||
|
||
/** | ||
* Return a human readable string for who the identity of the client/caller is. This | ||
* string must be appropriate for audit logs and enable tracing specific callers/clients | ||
* to relevant decision and operations executed | ||
* | ||
* @return | ||
*/ | ||
public String getIdentityLabel(); | ||
} |
14 changes: 14 additions & 0 deletions
14
...rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/AuthenticationHandler.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,14 @@ | ||
package software.amazon.awssdk.eventstreamrpc; | ||
|
||
import software.amazon.awssdk.crt.eventstream.Header; | ||
|
||
import java.util.List; | ||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* apply() accepts the connection message and produces authentication data from it to at least be | ||
* used for authorization decisions | ||
* | ||
* Exact implementation is up to service implementations to decide what it is and how to handle it | ||
*/ | ||
public interface AuthenticationHandler extends BiFunction<List<Header>, byte[], AuthenticationData> { } |
11 changes: 11 additions & 0 deletions
11
...-stream-rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/Authorization.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,11 @@ | ||
package software.amazon.awssdk.eventstreamrpc; | ||
|
||
/** | ||
* Authorization decision object contains the decision in general | ||
* and the authentication data along with it. | ||
* | ||
*/ | ||
public enum Authorization { | ||
ACCEPT, | ||
REJECT | ||
} |
13 changes: 13 additions & 0 deletions
13
...-rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/AuthorizationHandler.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,13 @@ | ||
package software.amazon.awssdk.eventstreamrpc; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Handler receives the input data of the connection message and produces an authorization result | ||
* which is a decision on accept or rejecting the connection | ||
* | ||
* -The apply function must return an Authorization object with a non-null AuthenticationData object | ||
* returned. It's great idea for implementations to log appropriate input | ||
* | ||
*/ | ||
public interface AuthorizationHandler extends Function<AuthenticationData, Authorization> { } |
60 changes: 60 additions & 0 deletions
60
...ver/src/main/java/software/amazon/awssdk/eventstreamrpc/DebugLoggingOperationHandler.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,60 @@ | ||
package software.amazon.awssdk.eventstreamrpc; | ||
|
||
import com.google.gson.Gson; | ||
import software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Useful to set as a handler for an operation with no implementation yet. | ||
*/ | ||
public class DebugLoggingOperationHandler extends OperationContinuationHandler | ||
<EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage> { | ||
private static final Logger LOGGER = Logger.getLogger(DebugLoggingOperationHandler.class.getName()); | ||
private final OperationModelContext operationModelContext; | ||
|
||
public DebugLoggingOperationHandler(final OperationModelContext modelContext, final OperationContinuationHandlerContext context) { | ||
super(context); | ||
this.operationModelContext = modelContext; | ||
} | ||
|
||
@Override | ||
public OperationModelContext<EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage> getOperationModelContext() { | ||
return operationModelContext; | ||
} | ||
|
||
/** | ||
* Called when the underlying continuation is closed. Gives operations a chance to cleanup whatever | ||
* resources may be on the other end of an open stream. Also invoked when an underlying ServerConnection | ||
* is closed associated with the stream/continuation | ||
*/ | ||
@Override | ||
protected void onStreamClosed() { | ||
LOGGER.info(String.format("%s operation onStreamClosed()", | ||
operationModelContext.getOperationName())); | ||
} | ||
|
||
@Override | ||
public EventStreamJsonMessage handleRequest(EventStreamJsonMessage request) { | ||
LOGGER.info(String.format("%s operation handleRequest() :: %s", operationModelContext.getOperationName(), | ||
operationModelContext.getServiceModel().toJson(request))); | ||
return new EventStreamJsonMessage() { | ||
@Override | ||
public byte[] toPayload(Gson gson) { | ||
return "{}".getBytes(StandardCharsets.UTF_8); | ||
} | ||
|
||
@Override | ||
public String getApplicationModelType() { | ||
return operationModelContext.getResponseApplicationModelType(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) { | ||
LOGGER.info(String.format("%s operation handleStreamEvent() :: %s", operationModelContext.getOperationName(), | ||
operationModelContext.getServiceModel().toJson(streamRequestEvent))); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...ver/src/main/java/software/amazon/awssdk/eventstreamrpc/EventStreamRPCServiceHandler.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,60 @@ | ||
package software.amazon.awssdk.eventstreamrpc; | ||
|
||
import java.util.Collection; | ||
|
||
public abstract class EventStreamRPCServiceHandler implements OperationContinuationHandlerFactory { | ||
private AuthenticationHandler authenticationHandler; | ||
private AuthorizationHandler authorizationHandler; | ||
|
||
public EventStreamRPCServiceHandler() { | ||
authorizationHandler = null; | ||
} | ||
|
||
protected abstract EventStreamRPCServiceModel getServiceModel(); | ||
|
||
/** | ||
* Probably only useful for logging | ||
* @return Returns the service name for the set of RPC operations | ||
*/ | ||
public String getServiceName() { | ||
return getServiceModel().getServiceName(); | ||
} | ||
|
||
/** | ||
* TODO: How may we want to protect this from being re-assigned after service creation? | ||
* @param handler | ||
*/ | ||
public void setAuthorizationHandler(final AuthorizationHandler handler) { | ||
this.authorizationHandler = handler; | ||
} | ||
|
||
/** | ||
* Use this to determine if the connection should be accepted or rejected for this service | ||
* | ||
* @return | ||
*/ | ||
public AuthorizationHandler getAuthorizationHandler() { | ||
return authorizationHandler; | ||
} | ||
|
||
@Override | ||
public Collection<String> getAllOperations() { | ||
return getServiceModel().getAllOperations(); | ||
} | ||
|
||
/** | ||
* Pulls caller/client identity when server connection occurs | ||
* @return | ||
*/ | ||
public AuthenticationHandler getAuthenticationHandler() { | ||
return authenticationHandler; | ||
} | ||
|
||
/** | ||
* TODO: How may we want to protect this from being re-assigned after service creation? | ||
* @param authenticationHandler | ||
*/ | ||
public void setAuthenticationHandler(AuthenticationHandler authenticationHandler) { | ||
this.authenticationHandler = authenticationHandler; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...main/java/software/amazon/awssdk/eventstreamrpc/InvalidServiceConfigurationException.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,15 @@ | ||
package software.amazon.awssdk.eventstreamrpc; | ||
|
||
public class InvalidServiceConfigurationException extends RuntimeException { | ||
public InvalidServiceConfigurationException(String msg) { | ||
super(msg); | ||
} | ||
|
||
public InvalidServiceConfigurationException(String msg, Throwable cause) { | ||
super(msg, cause); | ||
} | ||
|
||
public InvalidServiceConfigurationException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Oops, something went wrong.