Search in sources :

Example 1 with CryptosignAuth

use of io.crossbar.autobahn.wamp.auth.CryptosignAuth in project autobahn-java by crossbario.

the class Session method onPreSessionMessage.

private void onPreSessionMessage(IMessage message) throws Exception {
    if (message instanceof Welcome) {
        Welcome msg = (Welcome) message;
        mState = STATE_JOINED;
        mSessionID = msg.session;
        SessionDetails details = new SessionDetails(msg.realm, msg.session);
        mJoinFuture.complete(details);
        List<CompletableFuture<?>> futures = new ArrayList<>();
        for (OnJoinListener listener : mOnJoinListeners) {
            futures.add(runAsync(() -> listener.onJoin(this, details), mExecutor));
        }
        CompletableFuture d = combineFutures(futures);
        d.thenRunAsync(() -> {
            mState = STATE_READY;
            for (OnReadyListener listener : mOnReadyListeners) {
                listener.onReady(this);
            }
        }, mExecutor);
    } else if (message instanceof Abort) {
        Abort abortMessage = (Abort) message;
        CloseDetails details = new CloseDetails(abortMessage.reason, abortMessage.message);
        List<CompletableFuture<?>> futures = new ArrayList<>();
        for (OnLeaveListener listener : mOnLeaveListeners) {
            futures.add(runAsync(() -> listener.onLeave(this, details), mExecutor));
        }
        CompletableFuture d = combineFutures(futures);
        d.thenRunAsync(() -> {
            LOGGER.d("Notified Session.onLeave listeners, now closing transport");
            mState = STATE_DISCONNECTED;
            if (mTransport != null && mTransport.isOpen()) {
                try {
                    mTransport.close();
                } catch (Exception e) {
                    throw new CompletionException(e);
                }
            }
        }, mExecutor);
    } else if (message instanceof Challenge) {
        Challenge msg = (Challenge) message;
        io.crossbar.autobahn.wamp.types.Challenge challenge = new io.crossbar.autobahn.wamp.types.Challenge(msg.method, msg.extra);
        if (mAuthenticators != null) {
            if (msg.method.equals(TicketAuth.authmethod)) {
                for (IAuthenticator authenticator : mAuthenticators) {
                    if (authenticator.getAuthMethod().equals(TicketAuth.authmethod)) {
                        TicketAuth auth = (TicketAuth) authenticator;
                        auth.onChallenge(this, challenge).whenCompleteAsync((response, throwable) -> send(new Authenticate(response.signature, response.extra)), mExecutor);
                        break;
                    }
                }
            } else if (msg.method.equals(ChallengeResponseAuth.authmethod)) {
                for (IAuthenticator authenticator : mAuthenticators) {
                    if (authenticator.getAuthMethod().equals(ChallengeResponseAuth.authmethod)) {
                        ChallengeResponseAuth auth = (ChallengeResponseAuth) authenticator;
                        auth.onChallenge(this, challenge).whenCompleteAsync((response, throwable) -> send(new Authenticate(response.signature, response.extra)), mExecutor);
                        break;
                    }
                }
            } else if (msg.method.equals(CryptosignAuth.authmethod)) {
                for (IAuthenticator authenticator : mAuthenticators) {
                    if (authenticator.getAuthMethod().equals(CryptosignAuth.authmethod)) {
                        CryptosignAuth auth = (CryptosignAuth) authenticator;
                        auth.onChallenge(this, challenge).whenCompleteAsync((response, throwable) -> send(new Authenticate(response.signature, response.extra)), mExecutor);
                        break;
                    }
                }
            }
        }
    }
}
Also used : Result(io.crossbar.autobahn.wamp.messages.Result) Arrays(java.util.Arrays) Event(io.crossbar.autobahn.wamp.messages.Event) BiFunction(java.util.function.BiFunction) ChallengeResponseAuth(io.crossbar.autobahn.wamp.auth.ChallengeResponseAuth) EventDetails(io.crossbar.autobahn.wamp.types.EventDetails) Subscription(io.crossbar.autobahn.wamp.types.Subscription) Published(io.crossbar.autobahn.wamp.messages.Published) UnregisterRequest(io.crossbar.autobahn.wamp.requests.UnregisterRequest) TriConsumer(io.crossbar.autobahn.wamp.interfaces.TriConsumer) Unsubscribe(io.crossbar.autobahn.wamp.messages.Unsubscribe) Registration(io.crossbar.autobahn.wamp.types.Registration) IInvocationHandler(io.crossbar.autobahn.wamp.interfaces.IInvocationHandler) Publish(io.crossbar.autobahn.wamp.messages.Publish) CryptosignAuth(io.crossbar.autobahn.wamp.auth.CryptosignAuth) CallResult(io.crossbar.autobahn.wamp.types.CallResult) Subscribe(io.crossbar.autobahn.wamp.messages.Subscribe) ITransport(io.crossbar.autobahn.wamp.interfaces.ITransport) Error(io.crossbar.autobahn.wamp.messages.Error) Map(java.util.Map) Register(io.crossbar.autobahn.wamp.messages.Register) IMessage(io.crossbar.autobahn.wamp.interfaces.IMessage) Challenge(io.crossbar.autobahn.wamp.messages.Challenge) TicketAuth(io.crossbar.autobahn.wamp.auth.TicketAuth) SubscribeRequest(io.crossbar.autobahn.wamp.requests.SubscribeRequest) TypeReference(com.fasterxml.jackson.core.type.TypeReference) CallOptions(io.crossbar.autobahn.wamp.types.CallOptions) Invocation(io.crossbar.autobahn.wamp.messages.Invocation) InvocationDetails(io.crossbar.autobahn.wamp.types.InvocationDetails) Unsubscribed(io.crossbar.autobahn.wamp.messages.Unsubscribed) IABLogger(io.crossbar.autobahn.utils.IABLogger) Registered(io.crossbar.autobahn.wamp.messages.Registered) Shortcuts.getOrDefault(io.crossbar.autobahn.wamp.utils.Shortcuts.getOrDefault) CallRequest(io.crossbar.autobahn.wamp.requests.CallRequest) IDGenerator(io.crossbar.autobahn.wamp.utils.IDGenerator) CompletionException(java.util.concurrent.CompletionException) ABLogger(io.crossbar.autobahn.utils.ABLogger) Call(io.crossbar.autobahn.wamp.messages.Call) Authenticate(io.crossbar.autobahn.wamp.messages.Authenticate) Unregister(io.crossbar.autobahn.wamp.messages.Unregister) ProtocolError(io.crossbar.autobahn.wamp.exceptions.ProtocolError) Hello(io.crossbar.autobahn.wamp.messages.Hello) MESSAGE_TYPE_MAP(io.crossbar.autobahn.wamp.messages.MessageMap.MESSAGE_TYPE_MAP) List(java.util.List) SessionDetails(io.crossbar.autobahn.wamp.types.SessionDetails) WampException(io.crossbar.autobahn.wamp.reflectionRoles.WampException) CloseDetails(io.crossbar.autobahn.wamp.types.CloseDetails) ITransportHandler(io.crossbar.autobahn.wamp.interfaces.ITransportHandler) Goodbye(io.crossbar.autobahn.wamp.messages.Goodbye) Abort(io.crossbar.autobahn.wamp.messages.Abort) Unregistered(io.crossbar.autobahn.wamp.messages.Unregistered) IAuthenticator(io.crossbar.autobahn.wamp.interfaces.IAuthenticator) Subscribed(io.crossbar.autobahn.wamp.messages.Subscribed) Welcome(io.crossbar.autobahn.wamp.messages.Welcome) ISession(io.crossbar.autobahn.wamp.interfaces.ISession) PublishRequest(io.crossbar.autobahn.wamp.requests.PublishRequest) ReflectionServices(io.crossbar.autobahn.wamp.reflectionRoles.ReflectionServices) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) BiConsumer(java.util.function.BiConsumer) TriFunction(io.crossbar.autobahn.wamp.interfaces.TriFunction) InvocationResult(io.crossbar.autobahn.wamp.types.InvocationResult) CompletableFuture.runAsync(java.util.concurrent.CompletableFuture.runAsync) ReceptionResult(io.crossbar.autobahn.wamp.types.ReceptionResult) Executor(java.util.concurrent.Executor) RegisterOptions(io.crossbar.autobahn.wamp.types.RegisterOptions) SubscribeOptions(io.crossbar.autobahn.wamp.types.SubscribeOptions) Platform(io.crossbar.autobahn.wamp.utils.Platform) Yield(io.crossbar.autobahn.wamp.messages.Yield) Consumer(java.util.function.Consumer) RegisterRequest(io.crossbar.autobahn.wamp.requests.RegisterRequest) PublishOptions(io.crossbar.autobahn.wamp.types.PublishOptions) ISerializer(io.crossbar.autobahn.wamp.interfaces.ISerializer) UnsubscribeRequest(io.crossbar.autobahn.wamp.requests.UnsubscribeRequest) Publication(io.crossbar.autobahn.wamp.types.Publication) ApplicationError(io.crossbar.autobahn.wamp.exceptions.ApplicationError) CryptosignAuth(io.crossbar.autobahn.wamp.auth.CryptosignAuth) ArrayList(java.util.ArrayList) Challenge(io.crossbar.autobahn.wamp.messages.Challenge) CompletableFuture(java.util.concurrent.CompletableFuture) Abort(io.crossbar.autobahn.wamp.messages.Abort) Authenticate(io.crossbar.autobahn.wamp.messages.Authenticate) List(java.util.List) ArrayList(java.util.ArrayList) TicketAuth(io.crossbar.autobahn.wamp.auth.TicketAuth) IAuthenticator(io.crossbar.autobahn.wamp.interfaces.IAuthenticator) SessionDetails(io.crossbar.autobahn.wamp.types.SessionDetails) CompletionException(java.util.concurrent.CompletionException) WampException(io.crossbar.autobahn.wamp.reflectionRoles.WampException) ChallengeResponseAuth(io.crossbar.autobahn.wamp.auth.ChallengeResponseAuth) CompletionException(java.util.concurrent.CompletionException) Welcome(io.crossbar.autobahn.wamp.messages.Welcome) CloseDetails(io.crossbar.autobahn.wamp.types.CloseDetails)

Example 2 with CryptosignAuth

use of io.crossbar.autobahn.wamp.auth.CryptosignAuth in project autobahn-java by crossbario.

the class Session method reallyJoin.

private CompletableFuture<SessionDetails> reallyJoin(String realm, List<IAuthenticator> authenticators) {
    LOGGER.d("Called join() with realm=" + realm);
    mRealm = realm;
    mAuthenticators = authenticators;
    mGoodbyeSent = false;
    Map<String, Map> roles = new HashMap<>();
    roles.put("publisher", new HashMap<>());
    roles.put("subscriber", new HashMap<>());
    roles.put("caller", new HashMap<>());
    roles.put("callee", new HashMap<>());
    if (mAuthenticators == null) {
        send(new Hello(realm, roles));
    } else {
        List<String> authMethods = new ArrayList<>();
        String authID = null;
        Map<String, Object> authextra = null;
        for (IAuthenticator authenticator : mAuthenticators) {
            authMethods.add(authenticator.getAuthMethod());
            if (authenticator.getAuthMethod().equals(TicketAuth.authmethod)) {
                TicketAuth auth = (TicketAuth) authenticator;
                authID = auth.authid;
            } else if (authenticator.getAuthMethod().equals(ChallengeResponseAuth.authmethod)) {
                ChallengeResponseAuth auth = (ChallengeResponseAuth) authenticator;
                authID = auth.authid;
            } else if (authenticator.getAuthMethod().equals(CryptosignAuth.authmethod)) {
                CryptosignAuth auth = (CryptosignAuth) authenticator;
                authID = auth.authid;
                authextra = auth.authextra;
            }
        }
        send(new Hello(realm, roles, authMethods, authID, authextra));
    }
    mJoinFuture = new CompletableFuture<>();
    mState = STATE_HELLO_SENT;
    return mJoinFuture;
}
Also used : TicketAuth(io.crossbar.autobahn.wamp.auth.TicketAuth) HashMap(java.util.HashMap) CryptosignAuth(io.crossbar.autobahn.wamp.auth.CryptosignAuth) IAuthenticator(io.crossbar.autobahn.wamp.interfaces.IAuthenticator) ArrayList(java.util.ArrayList) Hello(io.crossbar.autobahn.wamp.messages.Hello) ChallengeResponseAuth(io.crossbar.autobahn.wamp.auth.ChallengeResponseAuth) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ChallengeResponseAuth (io.crossbar.autobahn.wamp.auth.ChallengeResponseAuth)2 CryptosignAuth (io.crossbar.autobahn.wamp.auth.CryptosignAuth)2 TicketAuth (io.crossbar.autobahn.wamp.auth.TicketAuth)2 IAuthenticator (io.crossbar.autobahn.wamp.interfaces.IAuthenticator)2 Hello (io.crossbar.autobahn.wamp.messages.Hello)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ABLogger (io.crossbar.autobahn.utils.ABLogger)1 IABLogger (io.crossbar.autobahn.utils.IABLogger)1 ApplicationError (io.crossbar.autobahn.wamp.exceptions.ApplicationError)1 ProtocolError (io.crossbar.autobahn.wamp.exceptions.ProtocolError)1 IInvocationHandler (io.crossbar.autobahn.wamp.interfaces.IInvocationHandler)1 IMessage (io.crossbar.autobahn.wamp.interfaces.IMessage)1 ISerializer (io.crossbar.autobahn.wamp.interfaces.ISerializer)1 ISession (io.crossbar.autobahn.wamp.interfaces.ISession)1 ITransport (io.crossbar.autobahn.wamp.interfaces.ITransport)1 ITransportHandler (io.crossbar.autobahn.wamp.interfaces.ITransportHandler)1 TriConsumer (io.crossbar.autobahn.wamp.interfaces.TriConsumer)1 TriFunction (io.crossbar.autobahn.wamp.interfaces.TriFunction)1 Abort (io.crossbar.autobahn.wamp.messages.Abort)1 Authenticate (io.crossbar.autobahn.wamp.messages.Authenticate)1