}
private PolicyEnforcer createPolicyEnforcer(
EndpointInfo endpointInfo, SoapMessage msg
) throws WSSPolicyException {
EffectivePolicy dispatchPolicy = null;
List<OperationPolicy> operationPolicies = new ArrayList<OperationPolicy>();
Collection<BindingOperationInfo> bindingOperationInfos = endpointInfo.getBinding().getOperations();
for (Iterator<BindingOperationInfo> bindingOperationInfoIterator =
bindingOperationInfos.iterator(); bindingOperationInfoIterator.hasNext();) {
BindingOperationInfo bindingOperationInfo = bindingOperationInfoIterator.next();
QName operationName = bindingOperationInfo.getName();
// todo: I'm not sure what the effectivePolicy exactly contains,
// a) only the operation policy,
// or b) all policies for the service,
// or c) all policies which applies for the current operation.
// c) is that what we need for stax.
EffectivePolicy policy =
(EffectivePolicy)bindingOperationInfo.getProperty("policy-engine-info-serve-request");
//PolicyEngineImpl.POLICY_INFO_REQUEST_SERVER);
String localName = operationName.getLocalPart();
if (MessageUtils.isRequestor(msg)) {
policy =
(EffectivePolicy)bindingOperationInfo.getProperty("policy-engine-info-client-response");
// Save the Dispatch Policy as it may be used on another BindingOperationInfo
if (policy != null
&& "http://cxf.apache.org/jaxws/dispatch".equals(operationName.getNamespaceURI())) {
dispatchPolicy = policy;
}
if (bindingOperationInfo.getOutput() != null) {
MessageInfo messageInfo = bindingOperationInfo.getOutput().getMessageInfo();
localName = messageInfo.getName().getLocalPart();
if (!messageInfo.getMessageParts().isEmpty()
&& messageInfo.getMessagePart(0).getConcreteName() != null) {
localName = messageInfo.getMessagePart(0).getConcreteName().getLocalPart();
}
}
}
SoapOperationInfo soapOperationInfo = bindingOperationInfo.getExtensor(SoapOperationInfo.class);
if (soapOperationInfo != null && policy == null && dispatchPolicy != null) {
policy = dispatchPolicy;
}
if (policy != null && soapOperationInfo != null) {
String soapNS;
BindingInfo bindingInfo = bindingOperationInfo.getBinding();
if (bindingInfo instanceof SoapBindingInfo) {
soapNS = ((SoapBindingInfo)bindingInfo).getSoapVersion().getNamespace();
} else {
//no idea what todo here...
//most probably throw an exception:
throw new IllegalArgumentException("BindingInfo is not an instance of SoapBindingInfo");
}
//todo: I think its a bug that we handover only the localPart of the operation.
// Needs to be fixed in ws-security-policy-stax
OperationPolicy operationPolicy = new OperationPolicy(localName);
operationPolicy.setPolicy(policy.getPolicy());
operationPolicy.setOperationAction(soapOperationInfo.getAction());
operationPolicy.setSoapMessageVersionNamespace(soapNS);
operationPolicies.add(operationPolicy);
}