assertNotNull(destination);
Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal("ffang"));
Channel channel = nmr.createChannel();
org.apache.servicemix.nmr.api.Exchange exchange = channel.createExchange(Pattern.InOut);
exchange.setTarget(
nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "dumy")));
exchange.getIn().setSecuritySubject(subject);
Source source = new StreamSource(new ByteArrayInputStream(
"<message>TestHelloWorld</message>".getBytes()));
exchange.getIn().setBody(source);
observer = new MessageObserver() {
public void onMessage(Message m) {
inMessage = m;
Subject receivedSubject =
(Subject)inMessage.get(NMRTransportFactory.NMR_SECURITY_SUBJECT);
assertNotNull(receivedSubject);
assertEquals(receivedSubject.getPrincipals().size(), 1);
assertEquals(receivedSubject.getPrincipals().iterator().next().getName(), "ffang");
Subject onBefalfsubject = Subject.getSubject(AccessController.getContext());
assertNotNull(onBefalfsubject);
assertEquals(onBefalfsubject, receivedSubject);
}
};
destination.setMessageObserver(observer);
channel.send(exchange);
Thread.sleep(2000);
assertNotNull(inMessage);
}