Search in sources :

Example 11 with AmqpValue

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);
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonReceiver(io.vertx.proton.ProtonReceiver) HonoUserAdapter(org.eclipse.hono.auth.HonoUserAdapter) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Vertx(io.vertx.core.Vertx) Autowired(org.springframework.beans.factory.annotation.Autowired) HonoUser(org.eclipse.hono.auth.HonoUser) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) AuthenticationConstants(org.eclipse.hono.service.auth.AuthenticationConstants) Objects(java.util.Objects) ConnectionFactory(org.eclipse.hono.connection.ConnectionFactory) Section(org.apache.qpid.proton.amqp.messaging.Section) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) HonoUser(org.eclipse.hono.auth.HonoUser) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) HonoUserAdapter(org.eclipse.hono.auth.HonoUserAdapter) Section(org.apache.qpid.proton.amqp.messaging.Section) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue)

Example 12 with AmqpValue

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);
}
Also used : Message(org.apache.qpid.proton.message.Message) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 13 with AmqpValue

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);
}
Also used : Message(org.apache.qpid.proton.message.Message) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 14 with AmqpValue

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);
}
Also used : Message(org.apache.qpid.proton.message.Message) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Aggregations

AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)14 Message (org.apache.qpid.proton.message.Message)10 Test (org.junit.Test)6 Section (org.apache.qpid.proton.amqp.messaging.Section)5 JsonObject (io.vertx.core.json.JsonObject)4 Vertx (io.vertx.core.Vertx)3 ProtonConnection (io.vertx.proton.ProtonConnection)3 Handler (io.vertx.core.Handler)2 ProtonHelper.message (io.vertx.proton.ProtonHelper.message)2 Data (org.apache.qpid.proton.amqp.messaging.Data)2 AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 ProtonClient (io.vertx.proton.ProtonClient)1 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)1 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)1 ProtonReceiver (io.vertx.proton.ProtonReceiver)1 ProtonSender (io.vertx.proton.ProtonSender)1 ProtonServer (io.vertx.proton.ProtonServer)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1