use of org.apache.qpid.proton.amqp.messaging.AmqpValue 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);
}
use of org.apache.qpid.proton.amqp.messaging.AmqpValue in project hono by eclipse.
the class CredentialsMessageFilterTest method testVerifySucceedsForValidGetAction.
/**
* Verifies that a valid message passes the filter.
*/
@Test
public void testVerifySucceedsForValidGetAction() {
// GIVEN a credentials message for user billie
final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get);
msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD));
msg.setContentType("application/json");
// WHEN receiving the message via a link with any tenant
final boolean filterResult = CredentialsMessageFilter.verify(target, msg);
// THEN message validation succeeds
assertTrue(filterResult);
}
use of org.apache.qpid.proton.amqp.messaging.AmqpValue in project hono by eclipse.
the class CredentialsMessageFilterTest method testVerifyFailsForMissingCorrelationId.
/**
* Verifies that a message that does not contain a message-id nor correlation-id
* does not pass the filter.
*/
@Test
public void testVerifyFailsForMissingCorrelationId() {
// GIVEN a message with an unsupported subject
final Message msg = ProtonHelper.message();
msg.setReplyTo("reply");
msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD));
msg.setContentType("application/json");
// WHEN receiving the message via a link with any tenant
final boolean filterResult = CredentialsMessageFilter.verify(target, msg);
// THEN message validation fails
assertFalse(filterResult);
}
use of org.apache.qpid.proton.amqp.messaging.AmqpValue in project hono by eclipse.
the class CredentialsMessageFilterTest method testVerifyFailsForUnknownAction.
/**
* Verifies that a message containing a subject that does not represent
* a Credentials API operation does not pass the filter.
*/
@Test
public void testVerifyFailsForUnknownAction() {
// GIVEN a message with an unsupported subject
final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.unknown);
msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD));
msg.setContentType("application/json");
// WHEN receiving the message via a link with any tenant
final boolean filterResult = CredentialsMessageFilter.verify(target, msg);
// THEN message validation fails
assertFalse(filterResult);
}
Aggregations