Some refactoring of the keys package
git-svn-id: https://svn.apache.org/repos/asf/santuario/xml-security-java/trunk@1877569 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/xml/security/keys/ContentHandlerAlreadyRegisteredException.java b/src/main/java/org/apache/xml/security/keys/ContentHandlerAlreadyRegisteredException.java
deleted file mode 100644
index 0af58e1..0000000
--- a/src/main/java/org/apache/xml/security/keys/ContentHandlerAlreadyRegisteredException.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.xml.security.keys;
-
-import org.apache.xml.security.exceptions.XMLSecurityException;
-
-public class ContentHandlerAlreadyRegisteredException extends XMLSecurityException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor ContentHandlerAlreadyRegisteredException
- *
- */
- public ContentHandlerAlreadyRegisteredException() {
- super();
- }
-
- /**
- * Constructor ContentHandlerAlreadyRegisteredException
- *
- * @param msgID
- */
- public ContentHandlerAlreadyRegisteredException(String msgID) {
- super(msgID);
- }
-
- /**
- * Constructor ContentHandlerAlreadyRegisteredException
- *
- * @param msgID
- * @param exArgs
- */
- public ContentHandlerAlreadyRegisteredException(String msgID, Object[] exArgs) {
- super(msgID, exArgs);
- }
-
- /**
- * Constructor ContentHandlerAlreadyRegisteredException
- *
- * @param originalException
- * @param msgID
- */
- public ContentHandlerAlreadyRegisteredException(Exception originalException, String msgID) {
- super(originalException, msgID);
- }
-
- @Deprecated
- public ContentHandlerAlreadyRegisteredException(String msgID, Exception originalException) {
- this(originalException, msgID);
- }
-
- /**
- * Constructor ContentHandlerAlreadyRegisteredException
- *
- * @param originalException
- * @param msgID
- * @param exArgs
- */
- public ContentHandlerAlreadyRegisteredException(
- Exception originalException, String msgID, Object[] exArgs
- ) {
- super(originalException, msgID, exArgs);
- }
-
- @Deprecated
- public ContentHandlerAlreadyRegisteredException(String msgID, Object[] exArgs, Exception originalException) {
- this(originalException, msgID, exArgs);
- }
-
-}
diff --git a/src/main/java/org/apache/xml/security/keys/KeyUtils.java b/src/main/java/org/apache/xml/security/keys/KeyUtils.java
deleted file mode 100644
index 68d75f2..0000000
--- a/src/main/java/org/apache/xml/security/keys/KeyUtils.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.xml.security.keys;
-
-import java.io.PrintStream;
-import java.security.PublicKey;
-
-import org.apache.xml.security.exceptions.XMLSecurityException;
-import org.apache.xml.security.keys.content.KeyName;
-import org.apache.xml.security.keys.content.KeyValue;
-import org.apache.xml.security.keys.content.MgmtData;
-import org.apache.xml.security.keys.content.X509Data;
-
-/**
- * Utility class for {@code org.apache.xml.security.keys} package.
- *
- */
-public final class KeyUtils {
-
- private KeyUtils() {
- // no instantiation
- }
-
- /**
- * Method prinoutKeyInfo
- *
- * @param ki
- * @param os
- * @throws XMLSecurityException
- */
- public static void prinoutKeyInfo(KeyInfo ki, PrintStream os)
- throws XMLSecurityException {
-
- for (int i = 0; i < ki.lengthKeyName(); i++) {
- KeyName x = ki.itemKeyName(i);
-
- os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
- }
-
- for (int i = 0; i < ki.lengthKeyValue(); i++) {
- KeyValue x = ki.itemKeyValue(i);
- PublicKey pk = x.getPublicKey();
-
- os.println("KeyValue Nr. " + i);
- os.println(pk);
- }
-
- for (int i = 0; i < ki.lengthMgmtData(); i++) {
- MgmtData x = ki.itemMgmtData(i);
-
- os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
- }
-
- for (int i = 0; i < ki.lengthX509Data(); i++) {
- X509Data x = ki.itemX509Data(i);
-
- os.println("X509Data(" + i + ")=\"" + (x.containsCertificate()
- ? "Certificate " : "") + (x.containsIssuerSerial()
- ? "IssuerSerial " : "") + "\"");
- }
- }
-}
diff --git a/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java b/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java
index ae7ede8..aba90e1 100644
--- a/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java
+++ b/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java
@@ -89,30 +89,30 @@
return cert.getPublicKey();
}
return null;
- }
- Element e = obtainReferenceElement(resource, secureValidation);
+ }
+ Element e = obtainReferenceElement(resource, secureValidation);
- // Check to make sure that the reference is not to another RetrievalMethod
- // which points to this element
- if (XMLUtils.elementIsInSignatureSpace(e, Constants._TAG_RETRIEVALMETHOD)) {
- if (secureValidation) {
- if (LOG.isDebugEnabled()) {
- String error = "Error: It is forbidden to have one RetrievalMethod "
- + "point to another with secure validation";
- LOG.debug(error);
- }
- return null;
- }
- RetrievalMethod rm2 = new RetrievalMethod(e, baseURI);
- XMLSignatureInput resource2 = resolveInput(rm2, baseURI, secureValidation);
- Element e2 = obtainReferenceElement(resource2, secureValidation);
- if (e2 == element) {
- LOG.debug("Error: Can't have RetrievalMethods pointing to each other");
- return null;
- }
- }
+ // Check to make sure that the reference is not to another RetrievalMethod
+ // which points to this element
+ if (XMLUtils.elementIsInSignatureSpace(e, Constants._TAG_RETRIEVALMETHOD)) {
+ if (secureValidation) {
+ if (LOG.isDebugEnabled()) {
+ String error = "Error: It is forbidden to have one RetrievalMethod "
+ + "point to another with secure validation";
+ LOG.debug(error);
+ }
+ return null;
+ }
+ RetrievalMethod rm2 = new RetrievalMethod(e, baseURI);
+ XMLSignatureInput resource2 = resolveInput(rm2, baseURI, secureValidation);
+ Element e2 = obtainReferenceElement(resource2, secureValidation);
+ if (e2 == element) {
+ LOG.debug("Error: Can't have RetrievalMethods pointing to each other");
+ return null;
+ }
+ }
- return resolveKey(e, baseURI, storage, secureValidation);
+ return resolveKey(e, baseURI, storage, secureValidation);
} catch (XMLSecurityException ex) {
LOG.debug("XMLSecurityException", ex);
} catch (CertificateException ex) {
diff --git a/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java b/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java
index 594e8c5..719a824 100644
--- a/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java
+++ b/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java
@@ -68,10 +68,10 @@
private URL systemId;
private boolean skipEvents = false;
- Map<URI, Document> uriDocMap = new HashMap<>();
+ private final Map<URI, Document> uriDocMap;
public XIncludeHandler(ContentHandler contentHandler) {
- this.contentHandler = contentHandler;
+ this(contentHandler, new HashMap<>());
}
private XIncludeHandler(ContentHandler contentHandler, Map<URI, Document> uriDocMap) {