|
20 | 20 | import java.security.Principal; |
21 | 21 | import java.security.cert.X509Certificate; |
22 | 22 | import java.util.ArrayList; |
| 23 | +import java.util.Arrays; |
23 | 24 | import java.util.Collections; |
24 | 25 | import java.util.List; |
| 26 | +import java.util.regex.Pattern; |
| 27 | +import java.util.stream.Collectors; |
25 | 28 |
|
26 | 29 | import javax.security.auth.callback.Callback; |
27 | 30 | import javax.security.auth.callback.CallbackHandler; |
|
59 | 62 | import org.w3c.dom.Document; |
60 | 63 | import org.w3c.dom.Element; |
61 | 64 |
|
| 65 | +import static java.util.Collections.emptyList; |
| 66 | +import static java.util.Collections.unmodifiableList; |
| 67 | + |
62 | 68 | /** |
63 | 69 | * A WS-Security endpoint interceptor based on Apache's WSS4J. This interceptor supports messages created by the |
64 | 70 | * {@link org.springframework.ws.soap.axiom.AxiomSoapMessageFactory} and the |
|
138 | 144 | * @author Jamin Hitchcock |
139 | 145 | * @author Rob Leland |
140 | 146 | * @author Lars Uffmann |
| 147 | + * @author Andreas Winter |
141 | 148 | * @see <a href="http://ws.apache.org/wss4j/">Apache WSS4J 2.0</a> |
142 | 149 | * @since 2.3.0 |
143 | 150 | */ |
@@ -194,6 +201,8 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl |
194 | 201 | // To maintain same behavior as default, this flag is set to true |
195 | 202 | private boolean removeSecurityHeader = true; |
196 | 203 |
|
| 204 | + private List<Pattern> signatureSubjectDnPatterns = emptyList(); |
| 205 | + |
197 | 206 | /** |
198 | 207 | * Create a {@link WSSecurityEngine} by default. |
199 | 208 | */ |
@@ -225,6 +234,15 @@ public void setSecurementActor(String securementActor) { |
225 | 234 | handler.setOption(WSHandlerConstants.ACTOR, securementActor); |
226 | 235 | } |
227 | 236 |
|
| 237 | + /** |
| 238 | + * Defines whether to use a single certificate or a whole certificate chain when constructing |
| 239 | + * a BinarySecurityToken used for direct reference in signature. |
| 240 | + * The default is "true", meaning that only a single certificate is used. |
| 241 | + */ |
| 242 | + public void setSecurementSignatureSingleCertificate(boolean useSingleCertificate) { |
| 243 | + handler.setOption(WSHandlerConstants.USE_SINGLE_CERTIFICATE, useSingleCertificate); |
| 244 | + } |
| 245 | + |
228 | 246 | public void setSecurementEncryptionCrypto(Crypto securementEncryptionCrypto) { |
229 | 247 | handler.setSecurementEncryptionCrypto(securementEncryptionCrypto); |
230 | 248 | } |
@@ -485,6 +503,19 @@ public void setValidationSignatureCrypto(Crypto signatureCrypto) { |
485 | 503 | this.validationSignatureCrypto = signatureCrypto; |
486 | 504 | } |
487 | 505 |
|
| 506 | + /** |
| 507 | + * Certificate constraints which will be applied to the subject DN of the certificate used for |
| 508 | + * signature validation, after trust verification of the certificate chain associated with the |
| 509 | + * certificate. |
| 510 | + * |
| 511 | + * @param patterns A list of regex patterns which will be applied to the subject DN. |
| 512 | + * |
| 513 | + * @see <a href="https://ws.apache.org/wss4j/config.html">WSS4J configuration: SIG_SUBJECT_CERT_CONSTRAINTS</a> |
| 514 | + */ |
| 515 | + public void setValidationSubjectDnConstraints(List<Pattern> patterns) { |
| 516 | + signatureSubjectDnPatterns = patterns; |
| 517 | + } |
| 518 | + |
488 | 519 | /** Whether to enable signatureConfirmation or not. By default signatureConfirmation is enabled */ |
489 | 520 | public void setEnableSignatureConfirmation(boolean enableSignatureConfirmation) { |
490 | 521 |
|
@@ -670,6 +701,7 @@ protected RequestData initializeRequestData(MessageContext messageContext) { |
670 | 701 | // allow for qualified password types for .Net interoperability |
671 | 702 | requestData.setAllowNamespaceQualifiedPasswordTypes(true); |
672 | 703 |
|
| 704 | + requestData.setSubjectCertConstraints(signatureSubjectDnPatterns); |
673 | 705 | return requestData; |
674 | 706 | } |
675 | 707 |
|
@@ -710,6 +742,8 @@ protected RequestData initializeValidationRequestData(MessageContext messageCont |
710 | 742 | // allow for qualified password types for .Net interoperability |
711 | 743 | requestData.setAllowNamespaceQualifiedPasswordTypes(true); |
712 | 744 |
|
| 745 | + requestData.setSubjectCertConstraints(signatureSubjectDnPatterns); |
| 746 | + |
713 | 747 | return requestData; |
714 | 748 | } |
715 | 749 |
|
|
0 commit comments