use of io.crossbar.autobahn.wamp.auth.TicketAuth 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;
}
}
}
}
}
}
use of io.crossbar.autobahn.wamp.auth.TicketAuth 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;
}
Aggregations