use of org.apache.neethi.Assertion in project cxf by apache.
the class PolicyEngineTest method testAddAssertions.
@Test
public void testAddAssertions() {
engine = new PolicyEngineImpl();
Collection<Assertion> assertions = new ArrayList<>();
Assertion a = control.createMock(Assertion.class);
EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
EasyMock.expect(a.isOptional()).andReturn(true);
control.replay();
engine.addAssertions(a, false, assertions);
assertTrue(assertions.isEmpty());
control.verify();
control.reset();
EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
control.replay();
engine.addAssertions(a, true, assertions);
assertEquals(1, assertions.size());
assertSame(a, assertions.iterator().next());
control.verify();
assertions.clear();
Policy p = new Policy();
a = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
p.addAssertion(a);
// id has no #
engine.getRegistry().register("ab", p);
// local reference is an id + #
PolicyReference pr = new PolicyReference();
pr.setURI("#ab");
engine.addAssertions(pr, false, assertions);
assertEquals(1, assertions.size());
assertSame(a, assertions.iterator().next());
}
use of org.apache.neethi.Assertion in project tesb-rt-se by Talend.
the class SingleBusLocatorRegistrar method isSecuredByPolicy.
/**
* Is the transport secured by a policy
*/
private boolean isSecuredByPolicy(Server server) {
boolean isSecured = false;
EndpointInfo ei = server.getEndpoint().getEndpointInfo();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
LOG.finest("No Policy engine found");
return isSecured;
}
Destination destination = server.getDestination();
EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination, null);
Collection<Assertion> assertions = ep.getChosenAlternative();
for (Assertion a : assertions) {
if (a instanceof TransportBinding) {
TransportBinding tb = (TransportBinding) a;
TransportToken tt = tb.getTransportToken();
AbstractToken t = tt.getToken();
if (t instanceof HttpsToken) {
isSecured = true;
break;
}
}
}
Policy policy = ep.getPolicy();
List<PolicyComponent> pcList = policy.getPolicyComponents();
for (PolicyComponent a : pcList) {
if (a instanceof TransportBinding) {
TransportBinding tb = (TransportBinding) a;
TransportToken tt = tb.getTransportToken();
AbstractToken t = tt.getToken();
if (t instanceof HttpsToken) {
isSecured = true;
break;
}
}
}
return isSecured;
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class MGF256AlgorithmSuiteLoader method getAlgorithmSuite.
public AlgorithmSuite getAlgorithmSuite(Bus bus, SPConstants.SPVersion version, Policy nestedPolicy) {
AssertionBuilderRegistry reg = bus.getExtension(AssertionBuilderRegistry.class);
if (reg != null) {
String ns = "http://cxf.apache.org/custom/security-policy";
final Map<QName, Assertion> assertions = new HashMap<>();
QName qName = new QName(ns, "Basic256GCMMGFSHA256");
assertions.put(qName, new PrimitiveAssertion(qName));
reg.registerBuilder(new PrimitiveAssertionBuilder(assertions.keySet()) {
public Assertion build(Element element, AssertionBuilderFactory fact) {
if (XMLPrimitiveAssertionBuilder.isOptional(element) || XMLPrimitiveAssertionBuilder.isIgnorable(element)) {
return super.build(element, fact);
}
QName q = new QName(element.getNamespaceURI(), element.getLocalName());
return assertions.get(q);
}
});
}
return new GCMAlgorithmSuite(version, nestedPolicy);
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class HTTPServerAssertionBuilderTest method testBuildAssertion.
@Test
public void testBuildAssertion() throws Exception {
HTTPServerAssertionBuilder ab = new HTTPServerAssertionBuilder();
Assertion a = ab.buildAssertion();
assertTrue(a instanceof JaxbAssertion);
assertTrue(a instanceof HTTPServerAssertionBuilder.HTTPServerPolicyAssertion);
assertEquals(new ServerPolicyCalculator().getDataClassName(), a.getName());
assertFalse(a.isOptional());
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class AssertionInfoMap method checkEffectivePolicy.
public List<List<Assertion>> checkEffectivePolicy(Policy policy) {
List<List<Assertion>> validated = new ArrayList<>(4);
List<QName> errors = new ArrayList<>();
Iterator<List<Assertion>> alternatives = policy.getAlternatives();
while (alternatives.hasNext()) {
List<Assertion> pc = alternatives.next();
if (supportsAlternative(pc, errors)) {
validated.add(pc);
}
}
if (!validated.isEmpty()) {
return validated;
}
Set<String> msgs = new LinkedHashSet<>();
for (QName name : errors) {
Collection<AssertionInfo> ais = getAssertionInfo(name);
boolean found = false;
for (AssertionInfo ai : ais) {
if (!ai.isAsserted()) {
String s = name.toString();
if (ai.getErrorMessage() != null) {
s += ": " + ai.getErrorMessage();
}
msgs.add(s);
found = true;
}
}
if (!found) {
msgs.add(name.toString());
}
}
StringBuilder error = new StringBuilder();
for (String msg : msgs) {
error.append('\n').append(msg);
}
throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE, error.toString()));
}
Aggregations