Making building the docker images optional in spring_boot_scan
[cxf.git] / systests / ws-security / src / test / java / org / apache / cxf / systest / ws / x509 / SHA512PolicyLoader.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.cxf.systest.ws.x509;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import javax.xml.namespace.QName;
25
26 import org.w3c.dom.Element;
27 import org.apache.cxf.Bus;
28 import org.apache.cxf.ws.policy.AssertionBuilderRegistry;
29 import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
30 import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder;
31 import org.apache.cxf.ws.security.policy.custom.AlgorithmSuiteLoader;
32 import org.apache.neethi.Assertion;
33 import org.apache.neethi.AssertionBuilderFactory;
34 import org.apache.neethi.Policy;
35 import org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder;
36 import org.apache.wss4j.dom.WSConstants;
37 import org.apache.wss4j.policy.SPConstants;
38 import org.apache.wss4j.policy.model.AbstractSecurityAssertion;
39 import org.apache.wss4j.policy.model.AlgorithmSuite;
40
41 /**
42 * This class retrieves the default AlgorithmSuites plus a custom AlgorithmSuite with the RSA SHA-512
43 * signature
44 */
45 public class SHA512PolicyLoader implements AlgorithmSuiteLoader {
46
47 public SHA512PolicyLoader(Bus bus) {
48 bus.setExtension(this, AlgorithmSuiteLoader.class);
49 }
50
51 public AlgorithmSuite getAlgorithmSuite(Bus bus, SPConstants.SPVersion version, Policy nestedPolicy) {
52 AssertionBuilderRegistry reg = bus.getExtension(AssertionBuilderRegistry.class);
53 if (reg != null) {
54 String ns = "http://cxf.apache.org/custom/security-policy";
55 final Map<QName, Assertion> assertions = new HashMap<QName, Assertion>();
56 QName qName = new QName(ns, "Basic128RsaSha512");
57 assertions.put(qName, new PrimitiveAssertion(qName));
58
59 reg.registerBuilder(new PrimitiveAssertionBuilder(assertions.keySet()) {
60 public Assertion build(Element element, AssertionBuilderFactory fact) {
61 if (XMLPrimitiveAssertionBuilder.isOptional(element)
62 || XMLPrimitiveAssertionBuilder.isIgnorable(element)) {
63 return super.build(element, fact);
64 }
65 QName q = new QName(element.getNamespaceURI(), element.getLocalName());
66 return assertions.get(q);
67 }
68 });
69 }
70 return new SHA512AlgorithmSuite(version, nestedPolicy);
71 }
72
73 public static class SHA512AlgorithmSuite extends AlgorithmSuite {
74
75 static {
76 ALGORITHM_SUITE_TYPES.put(
77 "Basic128RsaSha512",
78 new AlgorithmSuiteType(
79 "Basic128RsaSha512",
80 "http://www.w3.org/2001/04/xmlenc#sha512",
81 WSConstants.AES_128,
82 SPConstants.KW_AES128,
83 SPConstants.KW_RSA_OAEP,
84 SPConstants.P_SHA1_L128,
85 SPConstants.P_SHA1_L128,
86 128, 128, 128, 512, 1024, 4096
87 )
88 );
89 }
90
91 SHA512AlgorithmSuite(SPConstants.SPVersion version, Policy nestedPolicy) {
92 super(version, nestedPolicy);
93 setAsymmetricSignature("http://www.w3.org/2001/04/xmldsig-more#rsa-sha512");
94 }
95
96 @Override
97 protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
98 return new SHA512AlgorithmSuite(getVersion(), nestedPolicy);
99 }
100
101 @Override
102 protected void parseCustomAssertion(Assertion assertion) {
103 String assertionName = assertion.getName().getLocalPart();
104 String assertionNamespace = assertion.getName().getNamespaceURI();
105 if (!"http://cxf.apache.org/custom/security-policy".equals(assertionNamespace)) {
106 return;
107 }
108
109 if ("Basic128RsaSha512".equals(assertionName)) {
110 setAlgorithmSuiteType(ALGORITHM_SUITE_TYPES.get("Basic128RsaSha512"));
111 getAlgorithmSuiteType().setNamespace(assertionNamespace);
112 }
113 }
114 }
115
116
117 }