use of org.apache.neethi.Policy in project cxf by apache.
the class AbstractSTSClient method setPolicyInternal.
protected void setPolicyInternal(String policyReference) {
PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
ReferenceResolver resolver = new RemoteReferenceResolver(null, builder);
PolicyRegistry registry = bus.getExtension(PolicyEngine.class).getRegistry();
Policy resolved = registry.lookup(policyReference);
if (null != resolved) {
this.setPolicyInternal(resolved);
} else {
this.setPolicyInternal(resolver.resolveReference(policyReference));
}
}
use of org.apache.neethi.Policy in project cxf by apache.
the class AbstractSTSClient method cancel.
/**
* Make an "Cancel" invocation and return the response as a STSResponse Object
*/
protected STSResponse cancel(SecurityToken token) throws Exception {
createClient();
client.getRequestContext().clear();
client.getRequestContext().putAll(ctx);
client.getRequestContext().put(SecurityConstants.TOKEN, token);
BindingOperationInfo boi = findOperation("/RST/Cancel");
boolean attachTokenDirectly = true;
if (boi == null) {
attachTokenDirectly = false;
boi = findOperation("/RST/Issue");
Policy cancelPolicy = new Policy();
ExactlyOne one = new ExactlyOne();
cancelPolicy.addPolicyComponent(one);
All all = new All();
one.addPolicyComponent(all);
all.addAssertion(getAddressingAssertion());
final SecureConversationToken secureConversationToken = new SecureConversationToken(SPConstants.SPVersion.SP12, SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT, null, null, null, null);
secureConversationToken.setOptional(true);
class InternalProtectionToken extends ProtectionToken {
InternalProtectionToken(SPVersion version, Policy nestedPolicy) {
super(version, nestedPolicy);
super.setToken(secureConversationToken);
}
}
DefaultSymmetricBinding binding = new DefaultSymmetricBinding(SPConstants.SPVersion.SP12, new Policy());
all.addAssertion(binding);
all.addAssertion(getAddressingAssertion());
binding.setProtectionToken(new InternalProtectionToken(SPConstants.SPVersion.SP12, new Policy()));
binding.setIncludeTimestamp(true);
binding.setOnlySignEntireHeadersAndBody(true);
binding.setProtectTokens(false);
String addrNamespace = addressingNamespace;
if (addrNamespace == null) {
addrNamespace = "http://www.w3.org/2005/08/addressing";
}
List<Header> headers = new ArrayList<>();
headers.add(new Header("To", addrNamespace));
headers.add(new Header("From", addrNamespace));
headers.add(new Header("FaultTo", addrNamespace));
headers.add(new Header("ReplyTo", addrNamespace));
headers.add(new Header("Action", addrNamespace));
headers.add(new Header("MessageID", addrNamespace));
headers.add(new Header("RelatesTo", addrNamespace));
SignedParts parts = new SignedParts(SPConstants.SPVersion.SP12, true, null, headers, false);
parts.setOptional(true);
all.addPolicyComponent(parts);
client.getRequestContext().put(PolicyConstants.POLICY_OVERRIDE, cancelPolicy);
}
if (isSecureConv) {
client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/SCT/Cancel");
} else {
client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/Cancel");
}
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
writer.writeStartElement("wst", "RequestSecurityToken", namespace);
writer.writeNamespace("wst", namespace);
writer.writeStartElement("wst", "RequestType", namespace);
writer.writeCharacters(namespace + "/Cancel");
writer.writeEndElement();
writer.writeStartElement("wst", "CancelTarget", namespace);
Element el = null;
if (attachTokenDirectly) {
el = token.getToken();
} else {
el = token.getUnattachedReference();
if (el == null) {
el = token.getAttachedReference();
}
}
StaxUtils.copy(el, writer);
writer.writeEndElement();
writer.writeEndElement();
Object[] obj = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
return new STSResponse((DOMSource) obj[0], null);
}
use of org.apache.neethi.Policy in project cxf by apache.
the class AbstractPolicySecurityTest method runInInterceptorAndValidate.
protected void runInInterceptorAndValidate(String document, String policyDocument, List<QName> assertedInAssertions, List<QName> notAssertedInAssertions, List<CoverageType> types) throws Exception {
final Policy policy = this.policyBuilder.getPolicy(this.readDocument(policyDocument).getDocumentElement());
final Document doc = this.readDocument(document);
this.runInInterceptorAndValidate(doc, policy, assertedInAssertions, notAssertedInAssertions, types);
}
use of org.apache.neethi.Policy in project cxf by apache.
the class WSPolicyFeature method resolveExternal.
protected Policy resolveExternal(PolicyReference ref, String baseURI, Bus bus) {
PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
ReferenceResolver resolver = new RemoteReferenceResolver(baseURI, builder);
PolicyRegistry registry = bus.getExtension(PolicyEngine.class).getRegistry();
Policy resolved = registry.lookup(ref.getURI());
if (null != resolved) {
return resolved;
}
return resolver.resolveReference(ref.getURI());
}
use of org.apache.neethi.Policy in project cxf by apache.
the class WSPolicyFeature method initializeEndpointPolicy.
private Policy initializeEndpointPolicy(Endpoint endpoint, Bus bus) {
initialize(bus);
DescriptionInfo i = endpoint.getEndpointInfo().getDescription();
Collection<Policy> loadedPolicies = null;
if (policyElements != null || policyReferenceElements != null) {
loadedPolicies = new ArrayList<>();
PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
if (null != policyElements) {
for (Element e : policyElements) {
loadedPolicies.add(builder.getPolicy(e));
}
}
if (null != policyReferenceElements) {
for (Element e : policyReferenceElements) {
PolicyReference pr = builder.getPolicyReference(e);
Policy resolved = resolveReference(pr, builder, bus, i);
if (null != resolved) {
loadedPolicies.add(resolved);
}
}
}
}
Policy thePolicy = new Policy();
if (policies != null) {
for (Policy p : policies) {
thePolicy = thePolicy.merge(p);
}
}
if (loadedPolicies != null) {
for (Policy p : loadedPolicies) {
thePolicy = thePolicy.merge(p);
}
}
return thePolicy;
}
Aggregations