Code Monkey home page Code Monkey logo

jenjin-io's Issues

Conditional Contextual Tasks

It would be excellent to have an (optional) way of making a contextual task conditional; I'm thinking something like a Predicate<Message> that can be passed along with each contextual task, and the task will only execute if the predicate evaluates to true.

I'm thinking this could really help #6 because it would allow for completely ignoring deauthentication requests when not already authenticated and whatnot, and also because it would give a pretty convenient way to inject the Authenticator into the execution thread:

connectionBuilder.withContextualTask( (context) -> {
    if(!context.isAuthenticated) {
        authenticator.authenticate(context);
    }
}, (message) -> message instanceof AuthenticationRequest);

Authentication Interface

Given the following:

  1. User information is stored in the ExecutionContext
  2. A variable number of strings are required to authenticate
    • Usually, but not necessarily exactly, two (think two-factor auth)
  3. Authentication can be handled by multiple backends; SQL, Mongo, Flat Files, APIs, etc...

It seems reasonable to have an interface for authentication, something like the following

public interface Authenticator<T extends ExecutionContext>
{
    /**
     * Authenticate the user with the given credentials, populating the given ExecutionContext
     * IF AND ONLY IF the authentication is successful.
     *
     * @param context The context that will be populated with user data IF the authentication
     * is successful.  If the authentication is not successful, the context should remain 
     * unmodified.
     *
     * @param credentials One or more Strings identifying the user.
     *
     * @return true if the authentication was a success and the context was populated with user
     * data, false if the authentication was a failure and the context was not modified.
     *
     * @throws AuthenticationException If there is an unexpected exception when handling the 
     * authentication.
     */
    bool authenticate(T context, String... credentials) throws AuthenticationException;

    /**
     * Deauthenticate the user with the given credentials, depopulating the given 
     * ExecutionContext IF AND ONLY IF the authentication is successful.
     *
     * @param context The context that will be depopulated with user data IF the 
     * deauthentication is successful.  If the deauthentication is not successful,
     * the context should remain unmodified.  
     * (Maybe not, just a rough draft)
     *
     * @param credentials One or more Strings identifying the user.
     *
     * @throws AuthenticationException If there is an unexpected exception when handling the 
     * authentication.
     */
    void deauthenticate(T context, String... credentials) throws AuthenticationException;

    /**
     * Update the user with the given credentials from the given 
     * ExecutionContext.
     *
     * @param context The context that will be used to update user data.  
     * The context should remain unmodified.
     *
     * @param credentials One or more Strings identifying the user.
     *
     * @throws AuthenticationException If there is an unexpected exception when handling the 
     * update.
     */
    void update(T context, String... credentials) throws AuthenticationException;
}

Since the generic type of Server is also <T extends ExecutionContext> it should be an enormous pain drop right in without causing problems.

There'd have to be a way to access it (preferably from a Message containing the credentials); maybe a new interface like AuthenticationRequest or something that has a method returning credentials? That way a Message implementation could implement both interfaces.

That would result in some gross casting, though, so maybe it should be implemented as a part of the ExecutionContext?

Anyway, definitely an idea worth exploring.

Integration Test fails intermittently

Only seen in CI builds, likely due to the fact that the test contains a large number of threads and blocking. Would be better to use timeouts instead.

Create adaptTo argument for MessageAdapter

We can adapt message from a different type of message; why not to a different type of message?

Obviously this can be default empty, and the existing adaptFrom argument could be made optional as well.

Better use of generics

Currently the Message and Connection classes make decent use of generics; both of the (.*)ConnectionBuilder classes, the ServerBuilder class, and the Server class could use a boost in this department, mainly to avoid ugly casting of ExecutionContext arguments in Lambdas.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.