use of org.eclipse.hono.auth.HonoUserAdapter in project hono by eclipse.
the class AuthenticationServerClient method getToken.
private Future<HonoUser> getToken(final ProtonConnection openCon) {
final Promise<HonoUser> result = Promise.promise();
final ProtonMessageHandler messageHandler = (delivery, message) -> {
final String type = MessageHelper.getApplicationProperty(message.getApplicationProperties(), AuthenticationConstants.APPLICATION_PROPERTY_TYPE, String.class);
if (AuthenticationConstants.TYPE_AMQP_JWT.equals(type)) {
final String payload = MessageHelper.getPayloadAsString(message);
if (payload != null) {
final HonoUser user = new HonoUserAdapter() {
@Override
public String getToken() {
return payload;
}
};
LOG.debug("successfully retrieved token from Authentication service");
result.complete(user);
} else {
result.fail(new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, "message from Authentication service contains no body"));
}
} else {
result.fail(new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, "Authentication service issued unsupported token [type: " + type + "]"));
}
};
openReceiver(openCon, messageHandler).onComplete(attempt -> {
if (attempt.succeeded()) {
vertx.setTimer(5000, tid -> {
result.tryFail(new ServerErrorException(HttpURLConnection.HTTP_UNAVAILABLE, "time out reached while waiting for token from Authentication service"));
});
LOG.debug("opened receiver link to Authentication service, waiting for token ...");
} else {
result.fail(attempt.cause());
}
});
return result.future();
}
use of org.eclipse.hono.auth.HonoUserAdapter in project hono by eclipse.
the class AuthenticationServerClient method getToken.
private void getToken(final ProtonConnection openCon, final Future<HonoUser> authResult) {
final ProtonMessageHandler messageHandler = (delivery, message) -> {
String type = MessageHelper.getApplicationProperty(message.getApplicationProperties(), AuthenticationConstants.APPLICATION_PROPERTY_TYPE, String.class);
if (AuthenticationConstants.TYPE_AMQP_JWT.equals(type)) {
Section body = message.getBody();
if (body instanceof AmqpValue) {
final String token = ((AmqpValue) body).getValue().toString();
HonoUser user = new HonoUserAdapter() {
@Override
public String getToken() {
return token;
}
};
LOG.debug("successfully retrieved token from Authentication service");
authResult.complete(user);
} else {
authResult.fail("message from Authentication service contains no body");
}
} else {
authResult.fail("Authentication service issued unsupported token [type: " + type + "]");
}
};
openReceiver(openCon, messageHandler).compose(openReceiver -> {
LOG.debug("opened receiver link to Authentication service, waiting for token ...");
}, authResult);
}
Aggregations