in nmr/core/src/main/java/org/apache/servicemix/nmr/core/FlowRegistryImpl.java [79:139]
public void dispatch(InternalExchange exchange) {
if (exchange.getRole() == Role.Consumer) {
if (exchange.getDestination() == null) {
InternalReference target = (InternalReference) exchange.getTarget();
// TODO: possible NPE on target should be avoided
assert target != null;
boolean match = false;
boolean securityMatch = false;
for (InternalEndpoint endpoint : target.choose(registry)) {
if (Boolean.valueOf((String) endpoint.getMetaData().get(Endpoint.UNTARGETABLE))) {
continue;
}
match = true;
if (authorizationService != null) {
String endpointName = (String) endpoint.getMetaData().get(Endpoint.ENDPOINT_NAME);
String uniqueName = endpoint.getId();
if (endpointName != null && endpointName.length() != 0) {
uniqueName = uniqueName + "|" + endpointName;
}
Set<GroupPrincipal> acls = authorizationService.getAcls(uniqueName,
exchange.getOperation());
if (!acls.contains(GroupPrincipal.ANY)) {
Subject subject = exchange.getIn().getSecuritySubject();
if (subject == null) {
continue;
}
for (Principal groupPrincipal : acls) {
for (Principal principal: subject.getPrincipals()) {
if (groupPrincipal.equals(principal)) {
securityMatch = true;
}
}
}
if (!securityMatch) {
continue;
}
}
}
securityMatch = true;
if (internalDispatch(exchange, endpoint, true)) {
return;
}
}
if (!match) {
throw new ServiceMixException("Could not dispatch exchange. No matching endpoints.");
} else if (!securityMatch) {
throw new ServiceMixException("User not authenticated or not authorized to access any matching endpoint.");
} else {
throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
}
} else {
if (!internalDispatch(exchange, exchange.getDestination(), false)) {
throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
}
}
} else {
if (!internalDispatch(exchange, exchange.getSource(), false)) {
throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
}
}
}