From b1c8641a63a67e3c64d948f9e8dce5c01e11e2dd Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 5 May 2010 15:29:01 +0000 Subject: Merged feature branch mocca-1.2.13-id@r724 back to trunk. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@725 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../egiz/idlink/CompressedIdentityLinkFactory.java | 1 - .../at/gv/egiz/idlink/IdentityLinkFactory.java | 11 +- .../at/gv/egiz/idlink/IdentityLinkTransformer.java | 188 ++++++++++----------- 3 files changed, 97 insertions(+), 103 deletions(-) (limited to 'utils/src/main/java/at/gv/egiz/idlink') diff --git a/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java b/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java index 31e5163a..5df8657f 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java +++ b/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java @@ -52,7 +52,6 @@ import at.gv.egiz.idlink.ans1.IdentityLink; import at.gv.egiz.idlink.ans1.PersonData; import at.gv.egiz.idlink.ans1.PhysicalPersonData; import at.gv.egiz.marshal.MarshallerFactory; -import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import at.gv.egiz.xmldsig.KeyTypeNotSupportedException; import at.gv.egiz.xmldsig.KeyValueFactory; diff --git a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java index 38597446..30fa0777 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java +++ b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java @@ -70,14 +70,15 @@ import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import oasis.names.tc.saml._1_0.assertion.AnyType; import oasis.names.tc.saml._1_0.assertion.AssertionType; import oasis.names.tc.saml._1_0.assertion.AttributeStatementType; import oasis.names.tc.saml._1_0.assertion.AttributeType; import oasis.names.tc.saml._1_0.assertion.SubjectConfirmationType; import oasis.names.tc.saml._1_0.assertion.SubjectType; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -88,14 +89,12 @@ import at.gv.e_government.reference.namespace.persondata._20020228_.PhysicalPers import at.gv.e_government.reference.namespace.persondata._20020228_.IdentificationType.Value; import at.gv.e_government.reference.namespace.persondata._20020228_.PersonNameType.FamilyName; import at.gv.egiz.marshal.MarshallerFactory; -import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import at.gv.egiz.xmldsig.KeyTypeNotSupportedException; import at.gv.egiz.xmldsig.KeyValueFactory; -import oasis.names.tc.saml._1_0.assertion.AnyType; public class IdentityLinkFactory { - private static Log log = LogFactory.getLog(IdentityLinkFactory.class); + private final Logger log = LoggerFactory.getLogger(IdentityLinkFactory.class); /** * The instance returned by {@link #getInstance()}. @@ -380,7 +379,7 @@ public class IdentityLinkFactory { log.debug(writer.toString()); } catch (Exception e) { - log.debug(e); + log.debug("Logging assertion failed.", e); } } diff --git a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java index 8bee5fa4..a5b97a87 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java +++ b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.idlink; - +package at.gv.egiz.idlink; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -28,11 +29,12 @@ import javax.xml.transform.Templates; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamSource; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -41,98 +43,93 @@ import org.w3c.dom.Text; import at.gv.egiz.bku.utils.urldereferencer.StreamData; import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; - + public class IdentityLinkTransformer { - protected static Log log = LogFactory.getLog(IdentityLinkTransformer.class); - - /** - * The transformer factory. - */ - private static SAXTransformerFactory factory; - - /** - * The instance to be returned by {@link #getInstance()}. - */ - private static IdentityLinkTransformer instance; - - /** - * Returns an instance of this IdentityLinkTransfomer. - * - * @return an instance of this IdentityLinkTransformer - */ - public static IdentityLinkTransformer getInstance() { - if (instance == null) { - instance = new IdentityLinkTransformer(); - factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - } - return instance; - } - - /** - * Sets the given domainIdentifier on the corresponding - * node of the given idLink. - *

This method may be used to cope with a flaw in the IssuerTemplate-Stylesheets - * used to transform a CompressedIdentitiyLink into an - * IdentityLink. Some IssuerTemplate-Stylesheets do not - * consider the pr:Type element value of the - * CompressedIdentityLink and render a pr:Type - * element value of urn:publicid:gv.at:baseid - * into the IdentityLink structure. This method allows to - * set the pr:Type element value on the given idLink - * after the transformation. - *

- * - * @param idLink the IdentityLink element or one of it's ancestors. - * Must not be null. - * - * @param domainIdentifier the value to be set for the pr:Type element - * - * @throws NullPointerException if idLink is null. - */ - public static void setDomainIdentifier(Node idLink, String domainIdentifier) { - - Element element; - if (idLink instanceof Element) { - element = (Element) idLink; - } else if (idLink instanceof Document) { - element = ((Document) idLink).getDocumentElement(); - } else if (idLink != null) { - Document document = idLink.getOwnerDocument(); - element = document.getDocumentElement(); - } else { - throw new NullPointerException("Parameter 'idLink' must no be null."); - } - - NodeList nodeList = element.getElementsByTagNameNS( - "http://reference.e-government.gv.at/namespace/persondata/20020228#", - "Type"); - - for (int i = 0; i < nodeList.getLength(); i++) { - if (nodeList.item(i) instanceof Element) { - Element typeElement = (Element) nodeList.item(i); - NodeList children = typeElement.getChildNodes(); - for (int j = 0; j < children.getLength(); j++) { - if (children.item(j) instanceof Text) { - ((Text) children.item(j)).setNodeValue(domainIdentifier); - } - } - } - } - - } - + private final Logger log = LoggerFactory.getLogger(IdentityLinkTransformer.class); + /** - * Mapping of issuer template URIs to transformation templates. + * The transformer factory. + */ + private TransformerFactory factory = SAXTransformerFactory.newInstance(); + + /** + * The URLDereferencer used to dereference style-sheet URLs. + */ + private URLDereferencer urlDereferencer; + + /** + * @return the urlDereferencer + */ + public URLDereferencer getUrlDereferencer() { + return urlDereferencer; + } + + /** + * @param urlDereferencer the urlDereferencer to set */ - private Map templates = new HashMap(); - - /** - * Private constructor. - */ - private IdentityLinkTransformer() { + public void setUrlDereferencer(URLDereferencer urlDereferencer) { + this.urlDereferencer = urlDereferencer; } + /** + * Sets the given domainIdentifier on the corresponding + * node of the given idLink. + *

This method may be used to cope with a flaw in the IssuerTemplate-Stylesheets + * used to transform a CompressedIdentitiyLink into an + * IdentityLink. Some IssuerTemplate-Stylesheets do not + * consider the pr:Type element value of the + * CompressedIdentityLink and render a pr:Type + * element value of urn:publicid:gv.at:baseid + * into the IdentityLink structure. This method allows to + * set the pr:Type element value on the given idLink + * after the transformation. + *

+ * + * @param idLink the IdentityLink element or one of it's ancestors. + * Must not be null. + * + * @param domainIdentifier the value to be set for the pr:Type element + * + * @throws NullPointerException if idLink is null. + */ + public static void setDomainIdentifier(Node idLink, String domainIdentifier) { + + Element element; + if (idLink instanceof Element) { + element = (Element) idLink; + } else if (idLink instanceof Document) { + element = ((Document) idLink).getDocumentElement(); + } else if (idLink != null) { + Document document = idLink.getOwnerDocument(); + element = document.getDocumentElement(); + } else { + throw new NullPointerException("Parameter 'idLink' must no be null."); + } + + NodeList nodeList = element.getElementsByTagNameNS( + "http://reference.e-government.gv.at/namespace/persondata/20020228#", + "Type"); + + for (int i = 0; i < nodeList.getLength(); i++) { + if (nodeList.item(i) instanceof Element) { + Element typeElement = (Element) nodeList.item(i); + NodeList children = typeElement.getChildNodes(); + for (int j = 0; j < children.getLength(); j++) { + if (children.item(j) instanceof Text) { + ((Text) children.item(j)).setNodeValue(domainIdentifier); + } + } + } + } + + } + + /** + * Mapping of issuer template URIs to transformation templates. + */ + private Map templates = Collections.synchronizedMap(new HashMap()); + /** * Transforms an identity link source to result with * the given issuer template from the stylesheetURL. @@ -154,7 +151,7 @@ public class IdentityLinkTransformer { * stylesheet fails. * @throws TransformerException * if transforming the identity link fails. - */ + */ public void transformIdLink(String stylesheetURL, Source source, Result result) throws IOException, TransformerException { Templates templ = templates.get(stylesheetURL); @@ -168,8 +165,7 @@ public class IdentityLinkTransformer { throw new MalformedURLException("Protocol " + url.getProtocol() + " not supported for IssuerTemplate URL."); } - URLDereferencer dereferencer = URLDereferencer.getInstance(); - StreamData data = dereferencer.dereference(url.toExternalForm(), null); + StreamData data = urlDereferencer.dereference(url.toExternalForm()); log.trace("Trying to create issuer template."); templ = factory.newTemplates(new StreamSource(data.getStream())); @@ -183,6 +179,6 @@ public class IdentityLinkTransformer { transformer.transform(source, result); - } - -} + } + +} -- cgit v1.2.3