Search in sources :

Example 1 with MessageAuthorizationPolicy

use of org.apache.activemq.security.MessageAuthorizationPolicy in project activemq-artemis by apache.

the class MessageAuthenticationTest method createBroker.

@Override
protected BrokerService createBroker() throws Exception {
    BrokerService answer = new BrokerService();
    answer.setPersistent(false);
    answer.setMessageAuthorizationPolicy(new MessageAuthorizationPolicy() {

        @Override
        public boolean isAllowedToConsume(ConnectionContext context, Message message) {
            try {
                Object value = message.getProperty("myHeader");
                return "abc".equals(value);
            } catch (IOException e) {
                System.out.println("Caught: " + e);
                e.printStackTrace();
                return false;
            }
        }
    });
    answer.addConnector(bindAddress);
    return answer;
}
Also used : TextMessage(javax.jms.TextMessage) Message(org.apache.activemq.command.Message) MessageAuthorizationPolicy(org.apache.activemq.security.MessageAuthorizationPolicy) ConnectionContext(org.apache.activemq.broker.ConnectionContext) IOException(java.io.IOException) BrokerService(org.apache.activemq.broker.BrokerService)

Aggregations

IOException (java.io.IOException)1 TextMessage (javax.jms.TextMessage)1 BrokerService (org.apache.activemq.broker.BrokerService)1 ConnectionContext (org.apache.activemq.broker.ConnectionContext)1 Message (org.apache.activemq.command.Message)1 MessageAuthorizationPolicy (org.apache.activemq.security.MessageAuthorizationPolicy)1