Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B8AE49327 for ; Tue, 24 Apr 2012 19:04:17 +0000 (UTC) Received: (qmail 62061 invoked by uid 500); 24 Apr 2012 19:04:17 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 62017 invoked by uid 500); 24 Apr 2012 19:04:17 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 62010 invoked by uid 99); 24 Apr 2012 19:04:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2012 19:04:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2012 19:04:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 303CD238897D; Tue, 24 Apr 2012 19:03:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1329945 [2/4] - in /cxf/sandbox/fediz: fediz-core/.settings/ fediz-core/src/main/java/org/apache/cxf/fediz/core/ fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ fediz-core/src/main/java/org/apache/cxf/fediz/core/exception/ fediz... Date: Tue, 24 Apr 2012 19:03:41 -0000 To: commits@cxf.apache.org From: owulff@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120424190344.303CD238897D@eris.apache.org> Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ObjectFactory.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ObjectFactory.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ObjectFactory.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ObjectFactory.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,301 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.03.28 at 02:33:06 PM CEST +// + +package org.apache.cxf.fediz.core.config; + +import java.math.BigInteger; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + +/** + * This object contains factory methods for each Java content interface and Java + * element interface generated in the org.apache.cxf.fediz.core.config package. + *

+ * An ObjectFactory allows you to programatically construct new instances of the + * Java representation for XML content. The Java representation of XML content + * can consist of schema derived interfaces and classes representing the binding + * of schema type definitions, element declarations and model groups. Factory + * methods for each of these are provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _RoleURI_QNAME = new QName("", "roleURI"); + private final static QName _Protocol_QNAME = new QName("", "protocol"); + private final static QName _CertificateValidation_QNAME = new QName("", + "certificateValidation"); + private final static QName _MaximumClockSkew_QNAME = new QName("", + "maximumClockSkew"); + private final static QName _TrustedIssuerItem_QNAME = new QName("", + "trustedIssuerItem"); + private final static QName _ServiceCertificate_QNAME = new QName("", + "serviceCertificate"); + private final static QName _RoleDelimiter_QNAME = new QName("", + "roleDelimiter"); + private final static QName _Issuer_QNAME = new QName("", "issuer"); + private final static QName _SecurityTokenValidators_QNAME = new QName("", + "securityTokenValidators"); + private final static QName _Realm_QNAME = new QName("", "realm"); + private final static QName _Request_QNAME = new QName("", "request"); + private final static QName _Reply_QNAME = new QName("", "reply"); + private final static QName _Freshness_QNAME = new QName("", "freshness"); + private final static QName _AudienceItem_QNAME = new QName("", + "audienceItem"); + + /** + * Create a new ObjectFactory that can be used to create new instances of + * schema derived classes for package: org.apache.cxf.fediz.core.config + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link ContextConfig } + * + */ + public ContextConfig createContextConfig() { + return new ContextConfig(); + } + + /** + * Create an instance of {@link AudienceUris } + * + */ + public AudienceUris createAudienceUris() { + return new AudienceUris(); + } + + /** + * Create an instance of {@link TrustedIssuers } + * + */ + public TrustedIssuers createTrustedIssuers() { + return new TrustedIssuers(); + } + + /** + * Create an instance of {@link TrustManagersType } + * + */ + public TrustManagersType createTrustManagersType() { + return new TrustManagersType(); + } + + /** + * Create an instance of {@link HomeRealm } + * + */ + public HomeRealm createHomeRealm() { + return new HomeRealm(); + } + + /** + * Create an instance of {@link AuthenticationType } + * + */ + public AuthenticationType createAuthenticationType() { + return new AuthenticationType(); + } + + /** + * Create an instance of {@link ClaimTypesRequested } + * + */ + public ClaimTypesRequested createClaimTypesRequested() { + return new ClaimTypesRequested(); + } + + /** + * Create an instance of {@link ClaimType } + * + */ + public ClaimType createClaimType() { + return new ClaimType(); + } + + /** + * Create an instance of {@link FedizConfig } + * + */ + public FedizConfig createFedizConfig() { + return new FedizConfig(); + } + + /** + * Create an instance of {@link CertStoreType } + * + */ + public CertStoreType createCertStoreType() { + return new CertStoreType(); + } + + /** + * Create an instance of {@link KeyStoreType } + * + */ + public KeyStoreType createKeyStoreType() { + return new KeyStoreType(); + } + + /** + * Create an instance of {@link FederationProtocolType } + * + */ + public FederationProtocolType createFederationProtocolType() { + return new FederationProtocolType(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "roleURI") + public JAXBElement createRoleURI(String value) { + return new JAXBElement(_RoleURI_QNAME, String.class, null, + value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link ProtocolType } + * {@code >} + * + */ + @XmlElementDecl(namespace = "", name = "protocol") + public JAXBElement createProtocol(ProtocolType value) { + return new JAXBElement(_Protocol_QNAME, + ProtocolType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link ValidationType } + * {@code >} + * + */ + @XmlElementDecl(namespace = "", name = "certificateValidation") + public JAXBElement createCertificateValidation( + ValidationType value) { + return new JAXBElement(_CertificateValidation_QNAME, + ValidationType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link BigInteger } + * {@code >} + * + */ + @XmlElementDecl(namespace = "", name = "maximumClockSkew") + public JAXBElement createMaximumClockSkew(BigInteger value) { + return new JAXBElement(_MaximumClockSkew_QNAME, + BigInteger.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <} + * {@link TrustManagersType }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "trustedIssuerItem") + public JAXBElement createTrustedIssuerItem( + TrustManagersType value) { + return new JAXBElement(_TrustedIssuerItem_QNAME, + TrustManagersType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <} + * {@link TrustManagersType }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "serviceCertificate") + public JAXBElement createServiceCertificate( + TrustManagersType value) { + return new JAXBElement(_ServiceCertificate_QNAME, + TrustManagersType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "roleDelimiter") + public JAXBElement createRoleDelimiter(String value) { + return new JAXBElement(_RoleDelimiter_QNAME, String.class, + null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "issuer") + public JAXBElement createIssuer(String value) { + return new JAXBElement(_Issuer_QNAME, String.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "securityTokenValidators") + public JAXBElement createSecurityTokenValidators(String value) { + return new JAXBElement(_SecurityTokenValidators_QNAME, + String.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "realm") + public JAXBElement createRealm(String value) { + return new JAXBElement(_Realm_QNAME, String.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "request") + public JAXBElement createRequest(String value) { + return new JAXBElement(_Request_QNAME, String.class, null, + value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "reply") + public JAXBElement createReply(String value) { + return new JAXBElement(_Reply_QNAME, String.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "freshness") + public JAXBElement createFreshness(String value) { + return new JAXBElement(_Freshness_QNAME, String.class, null, + value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * + */ + @XmlElementDecl(namespace = "", name = "audienceItem") + public JAXBElement createAudienceItem(String value) { + return new JAXBElement(_AudienceItem_QNAME, String.class, null, + value); + } + +} Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ProtocolType.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ProtocolType.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ProtocolType.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ProtocolType.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,39 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.03.28 at 02:33:06 PM CEST +// + +package org.apache.cxf.fediz.core.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlType; + +/** + *

+ * Java class for protocolType complex type. + * + *

+ * The following schema fragment specifies the expected content contained within + * this class. + * + *

+ * <complexType name="protocolType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "protocolType") +@XmlSeeAlso({ FederationProtocolType.class }) +public abstract class ProtocolType { + +} Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustManagersType.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustManagersType.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustManagersType.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustManagersType.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,140 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.03.28 at 02:33:06 PM CEST +// + +package org.apache.cxf.fediz.core.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; + +/** + * + * This structure contains the specification of JSSE TrustManagers for a single + * Keystore used for trusted certificates. + * + * + *

+ * Java class for TrustManagersType complex type. + * + *

+ * The following schema fragment specifies the expected content contained within + * this class. + * + *

+ * <complexType name="TrustManagersType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <choice>
+ *         <element name="keyStore" type="{}KeyStoreType" minOccurs="0"/>
+ *         <element name="certStore" type="{}CertStoreType" minOccurs="0"/>
+ *       </choice>
+ *       <attribute name="provider" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="factoryAlgorithm" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "TrustManagersType", propOrder = { "keyStore", "certStore" }) +public class TrustManagersType { + + protected KeyStoreType keyStore; + protected CertStoreType certStore; + @XmlAttribute(name = "provider") + protected String provider; + @XmlAttribute(name = "factoryAlgorithm") + protected String factoryAlgorithm; + + /** + * Gets the value of the keyStore property. + * + * @return possible object is {@link KeyStoreType } + * + */ + public KeyStoreType getKeyStore() { + return keyStore; + } + + /** + * Sets the value of the keyStore property. + * + * @param value + * allowed object is {@link KeyStoreType } + * + */ + public void setKeyStore(KeyStoreType value) { + this.keyStore = value; + } + + /** + * Gets the value of the certStore property. + * + * @return possible object is {@link CertStoreType } + * + */ + public CertStoreType getCertStore() { + return certStore; + } + + /** + * Sets the value of the certStore property. + * + * @param value + * allowed object is {@link CertStoreType } + * + */ + public void setCertStore(CertStoreType value) { + this.certStore = value; + } + + /** + * Gets the value of the provider property. + * + * @return possible object is {@link String } + * + */ + public String getProvider() { + return provider; + } + + /** + * Sets the value of the provider property. + * + * @param value + * allowed object is {@link String } + * + */ + public void setProvider(String value) { + this.provider = value; + } + + /** + * Gets the value of the factoryAlgorithm property. + * + * @return possible object is {@link String } + * + */ + public String getFactoryAlgorithm() { + return factoryAlgorithm; + } + + /** + * Sets the value of the factoryAlgorithm property. + * + * @param value + * allowed object is {@link String } + * + */ + public void setFactoryAlgorithm(String value) { + this.factoryAlgorithm = value; + } + +} Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustedIssuers.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustedIssuers.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustedIssuers.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/TrustedIssuers.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,78 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.03.28 at 02:33:06 PM CEST +// + +package org.apache.cxf.fediz.core.config; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within + * this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence maxOccurs="unbounded">
+ *         <element ref="{}trustedIssuerItem"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "trustedIssuerItem" }) +@XmlRootElement(name = "trustedIssuers") +public class TrustedIssuers { + + @XmlElement(required = true) + protected List trustedIssuerItem; + + /** + * Gets the value of the trustedIssuerItem property. + * + *

+ * This accessor method returns a reference to the live list, not a + * snapshot. Therefore any modification you make to the returned list will + * be present inside the JAXB object. This is why there is not a + * set method for the trustedIssuerItem property. + * + *

+ * For example, to add a new item, do as follows: + * + *

+     * getTrustedIssuerItem().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link TrustManagersType } + * + * + */ + public List getTrustedIssuerItem() { + if (trustedIssuerItem == null) { + trustedIssuerItem = new ArrayList(); + } + return this.trustedIssuerItem; + } + +} Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ValidationType.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ValidationType.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ValidationType.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/config/ValidationType.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,59 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.03.28 at 02:33:06 PM CEST +// + +package org.apache.cxf.fediz.core.config; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + +/** + *

+ * Java class for validationType. + * + *

+ * The following schema fragment specifies the expected content contained within + * this class. + *

+ * + *

+ * <simpleType name="validationType">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="PeerTrust"/>
+ *     <enumeration value="ChainTrust"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "validationType") +@XmlEnum +public enum ValidationType { + + @XmlEnumValue("PeerTrust") + PEER_TRUST("PeerTrust"), @XmlEnumValue("ChainTrust") + CHAIN_TRUST("ChainTrust"); + private final String value; + + ValidationType(String v) { + value = v; + } + + public String value() { + return value; + } + + public static ValidationType fromValue(String v) { + for (ValidationType c : ValidationType.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +} Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/exception/IllegalConfigurationException.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/exception/IllegalConfigurationException.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/exception/IllegalConfigurationException.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/exception/IllegalConfigurationException.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,21 @@ +package org.apache.cxf.fediz.core.exception; + +public class IllegalConfigurationException extends RuntimeException { + + public IllegalConfigurationException() { + super(); + } + + public IllegalConfigurationException(String message, Throwable cause) { + super(message, cause); + } + + public IllegalConfigurationException(String message) { + super(message); + } + + public IllegalConfigurationException(Throwable cause) { + super(cause); + } + +} Modified: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/CertConstraintsParser.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/CertConstraintsParser.java?rev=1329945&r1=1329944&r2=1329945&view=diff ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/CertConstraintsParser.java (original) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/CertConstraintsParser.java Tue Apr 24 19:03:39 2012 @@ -24,21 +24,20 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; - /** - * This class provides the functionality to match a given X509Certificate against a list of - * regular expressions. + * This class provides the functionality to match a given X509Certificate + * against a list of regular expressions. */ public class CertConstraintsParser { - + /** * a collection of compiled regular expression patterns for the subject DN */ private Collection subjectDNPatterns = new ArrayList(); - + /** - * Set a list of Strings corresponding to regular expression constraints on the subject DN - * of a certificate + * Set a list of Strings corresponding to regular expression constraints on + * the subject DN of a certificate */ public void setSubjectConstraints(List constraints) { if (constraints != null) { @@ -47,25 +46,23 @@ public class CertConstraintsParser { try { subjectDNPatterns.add(Pattern.compile(constraint.trim())); } catch (PatternSyntaxException ex) { - //LOG.severe(ex.getMessage()); + // LOG.severe(ex.getMessage()); throw ex; } } } } - + /** - * @return true if the certificate's SubjectDN matches the constraints defined in the - * subject DNConstraints; false, otherwise. The certificate subject DN only - * has to match ONE of the subject cert constraints (not all). + * @return true if the certificate's SubjectDN matches the constraints + * defined in the subject DNConstraints; false, otherwise. The + * certificate subject DN only has to match ONE of the subject cert + * constraints (not all). */ - public boolean - matches( - final java.security.cert.X509Certificate cert - ) { + public boolean matches(final java.security.cert.X509Certificate cert) { if (!subjectDNPatterns.isEmpty()) { if (cert == null) { - //LOG.fine("The certificate is null so no constraints matching was possible"); + // LOG.fine("The certificate is null so no constraints matching was possible"); return false; } String subjectName = cert.getSubjectX500Principal().getName(); @@ -73,7 +70,8 @@ public class CertConstraintsParser { for (Pattern subjectDNPattern : subjectDNPatterns) { final Matcher matcher = subjectDNPattern.matcher(subjectName); if (matcher.matches()) { - //LOG.fine("Subject DN " + subjectName + " matches with pattern " + subjectDNPattern); + // LOG.fine("Subject DN " + subjectName + + // " matches with pattern " + subjectDNPattern); subjectMatch = true; break; } @@ -82,7 +80,7 @@ public class CertConstraintsParser { return false; } } - + return true; } } Modified: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/SAMLTokenValidator.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/SAMLTokenValidator.java?rev=1329945&r1=1329944&r2=1329945&view=diff ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/SAMLTokenValidator.java (original) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/saml/SAMLTokenValidator.java Tue Apr 24 19:03:39 2012 @@ -22,22 +22,20 @@ import java.net.URI; import java.net.URISyntaxException; import java.security.cert.X509Certificate; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Properties; import java.util.StringTokenizer; - import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.UnsupportedCallbackException; import org.apache.cxf.fediz.core.Claim; import org.apache.cxf.fediz.core.ClaimCollection; -import org.apache.cxf.fediz.core.FederationConfiguration; import org.apache.cxf.fediz.core.TokenValidator; import org.apache.cxf.fediz.core.TokenValidatorResponse; +import org.apache.cxf.fediz.core.config.FederationContext; import org.apache.ws.security.SAMLTokenPrincipal; import org.apache.ws.security.WSDocInfo; import org.apache.ws.security.WSPasswordCallback; @@ -58,10 +56,10 @@ import org.w3c.dom.Element; public class SAMLTokenValidator implements TokenValidator { - private static final Logger LOG = LoggerFactory.getLogger(SAMLTokenValidator.class); - + private static final Logger LOG = LoggerFactory + .getLogger(SAMLTokenValidator.class); - //[TODO] make sure we answer true only for cases we actually can handle + // [TODO] make sure we answer true only for cases we actually can handle @Override public boolean canHandleTokenType(String tokenType) { return true; @@ -72,29 +70,31 @@ public class SAMLTokenValidator implemen return true; } - @Override - public TokenValidatorResponse validateAndProcessToken(Element token, FederationConfiguration config) { + public TokenValidatorResponse validateAndProcessToken(Element token, + FederationContext config) { try { - Properties sigProperties = createCryptoProviderProperties(config.getTrustStoreFile(), config.getTrustStorePassword()); + Properties sigProperties = createCryptoProviderProperties( + config.getTrustStoreFile(), config.getTrustStorePassword()); Crypto sigCrypto = CryptoFactory.getInstance(sigProperties); RequestData requestData = new RequestData(); requestData.setSigCrypto(sigCrypto); WSSConfig wssConfig = WSSConfig.getNewInstance(); requestData.setWssConfig(wssConfig); - //not needed as no private key must be read - //requestData.setCallbackHandler(new PasswordCallbackHandler(password)); + // not needed as no private key must be read + // requestData.setCallbackHandler(new + // PasswordCallbackHandler(password)); AssertionWrapper assertion = new AssertionWrapper(token); if (!assertion.isSigned()) { - throw new RuntimeException("The received assertion is not signed, and therefore not trusted"); + throw new RuntimeException( + "The received assertion is not signed, and therefore not trusted"); } // Verify the signature - assertion.verifySignature( - requestData, new WSDocInfo(token.getOwnerDocument()) - ); + assertion.verifySignature(requestData, + new WSDocInfo(token.getOwnerDocument())); // Now verify trust on the signature Credential trustCredential = new Credential(); @@ -107,28 +107,32 @@ public class SAMLTokenValidator implemen String assertionIssuer = assertion.getIssuerString(); - // Finally check that subject DN of the signing certificate matches a known constraint + // Finally check that subject DN of the signing certificate matches + // a known constraint X509Certificate cert = null; if (trustCredential.getCertificates() != null) { cert = trustCredential.getCertificates()[0]; } - List subjectConstraints = Arrays.asList(config.getTrustedIssuer()); + // List subjectConstraints = + // Arrays.asList(config.getTrustedIssuer()); + List subjectConstraints = config.getTrustedIssuersNames(); CertConstraintsParser certConstraints = new CertConstraintsParser(); certConstraints.setSubjectConstraints(subjectConstraints); if (!certConstraints.matches(cert)) { - throw new RuntimeException("Issuer '" + assertionIssuer + "' not trusted"); + throw new RuntimeException("Issuer '" + assertionIssuer + + "' not trusted"); } - String audience = null; List claims = null; if (assertion.getSamlVersion().equals(SAMLVersion.VERSION_20)) { claims = parseClaimsInAssertion(assertion.getSaml2()); audience = getAudienceRestriction(assertion.getSaml2()); - } else if (assertion.getSamlVersion().equals(SAMLVersion.VERSION_11)) { + } else if (assertion.getSamlVersion() + .equals(SAMLVersion.VERSION_11)) { claims = parseClaimsInAssertion(assertion.getSaml1()); audience = getAudienceRestriction(assertion.getSaml1()); } @@ -137,11 +141,14 @@ public class SAMLTokenValidator implemen URI roleURI = config.getRoleURI(); String delim = config.getRoleDelimiter(); if (roleURI != null) { - for (Claim c: claims) { - URI claimURI = URI.create(c.getNamespace() + "/" + c.getClaimType()); + for (Claim c : claims) { + URI claimURI = URI.create(c.getNamespace() + "/" + + c.getClaimType()); if (roleURI.equals(claimURI)) { - if (delim == null) { delim = ","; } - roles = parseRoles(c.getValue(), delim); + if (delim == null) { + delim = ","; + } + roles = parseRoles(c.getValue(), delim); claims.remove(c); break; } @@ -151,29 +158,25 @@ public class SAMLTokenValidator implemen SAMLTokenPrincipal p = new SAMLTokenPrincipal(assertion); TokenValidatorResponse response = new TokenValidatorResponse( - assertion.getId(), - p.getName(), - assertionIssuer, - roles, - claims, - audience); + assertion.getId(), p.getName(), assertionIssuer, roles, + claims, audience); return response; } catch (WSSecurityException ex) { - //[TODO] proper exception handling + // [TODO] proper exception handling throw new RuntimeException(ex); } } - - protected List parseClaimsInAssertion(org.opensaml.saml1.core.Assertion assertion) { - List attributeStatements = - assertion.getAttributeStatements(); + protected List parseClaimsInAssertion( + org.opensaml.saml1.core.Assertion assertion) { + List attributeStatements = assertion + .getAttributeStatements(); if (attributeStatements == null || attributeStatements.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("No attribute statements found"); - } + } return Collections.emptyList(); } ClaimCollection collection = new ClaimCollection(); @@ -183,10 +186,12 @@ public class SAMLTokenValidator implemen LOG.debug("parsing statement: " + statement.getElementQName()); } - List attributes = statement.getAttributes(); + List attributes = statement + .getAttributes(); for (org.opensaml.saml1.core.Attribute attribute : attributes) { if (LOG.isDebugEnabled()) { - LOG.debug("parsing attribute: " + attribute.getAttributeName()); + LOG.debug("parsing attribute: " + + attribute.getAttributeName()); } Claim c = new Claim(); c.setIssuer(assertion.getIssuer()); @@ -194,7 +199,8 @@ public class SAMLTokenValidator implemen try { c.setClaimType(new URI(attribute.getAttributeName())); } catch (URISyntaxException e) { - LOG.warn("Invalid attribute name in attributestatement: " + e.getMessage()); + LOG.warn("Invalid attribute name in attributestatement: " + + e.getMessage()); continue; } for (XMLObject attributeValue : attribute.getAttributeValues()) { @@ -205,16 +211,17 @@ public class SAMLTokenValidator implemen } c.setValue(value); collection.add(c); - break; + break; } } } return collection; } - protected List parseClaimsInAssertion(org.opensaml.saml2.core.Assertion assertion) { - List attributeStatements = - assertion.getAttributeStatements(); + protected List parseClaimsInAssertion( + org.opensaml.saml2.core.Assertion assertion) { + List attributeStatements = assertion + .getAttributeStatements(); if (attributeStatements == null || attributeStatements.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("No attribute statements found"); @@ -228,7 +235,8 @@ public class SAMLTokenValidator implemen if (LOG.isDebugEnabled()) { LOG.debug("parsing statement: " + statement.getElementQName()); } - List attributes = statement.getAttributes(); + List attributes = statement + .getAttributes(); for (org.opensaml.saml2.core.Attribute attribute : attributes) { if (LOG.isDebugEnabled()) { LOG.debug("parsing attribute: " + attribute.getName()); @@ -262,20 +270,25 @@ public class SAMLTokenValidator implemen return roles; } - protected String getAudienceRestriction(org.opensaml.saml1.core.Assertion assertion) { + protected String getAudienceRestriction( + org.opensaml.saml1.core.Assertion assertion) { String audience = null; try { - audience = assertion.getConditions().getAudienceRestrictionConditions().get(0).getAudiences().get(0).getUri(); + audience = assertion.getConditions() + .getAudienceRestrictionConditions().get(0).getAudiences() + .get(0).getUri(); } catch (Exception ex) { LOG.warn("Failed to read audience" + ex.getMessage()); } - return audience; + return audience; } - protected String getAudienceRestriction(org.opensaml.saml2.core.Assertion assertion) { + protected String getAudienceRestriction( + org.opensaml.saml2.core.Assertion assertion) { String audience = null; try { - audience = assertion.getConditions().getAudienceRestrictions().get(0).getAudiences().get(0).getAudienceURI(); + audience = assertion.getConditions().getAudienceRestrictions() + .get(0).getAudiences().get(0).getAudienceURI(); } catch (Exception ex) { LOG.warn("Failed to read audience" + ex.getMessage()); } @@ -283,37 +296,39 @@ public class SAMLTokenValidator implemen } - protected Properties createCryptoProviderProperties(String truststoreFile, String truststorePassword) { + protected Properties createCryptoProviderProperties(String truststoreFile, + String truststorePassword) { Properties p = new Properties(); - p.put("org.apache.ws.security.crypto.provider", "org.apache.ws.security.components.crypto.Merlin"); + p.put("org.apache.ws.security.crypto.provider", + "org.apache.ws.security.components.crypto.Merlin"); p.put("org.apache.ws.security.crypto.merlin.keystore.type", "jks"); - p.put("org.apache.ws.security.crypto.merlin.keystore.password", truststorePassword); - p.put("org.apache.ws.security.crypto.merlin.keystore.file", truststoreFile); + p.put("org.apache.ws.security.crypto.merlin.keystore.password", + truststorePassword); + p.put("org.apache.ws.security.crypto.merlin.keystore.file", + truststoreFile); return p; } - // A sample MyHandler class - class PasswordCallbackHandler implements CallbackHandler - { + class PasswordCallbackHandler implements CallbackHandler { private String password; - private PasswordCallbackHandler() {} + private PasswordCallbackHandler() { + } public PasswordCallbackHandler(String password) { this.password = password; } - public void handle(Callback[] callbacks) throws - IOException, UnsupportedCallbackException - { + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof WSPasswordCallback) { - WSPasswordCallback nc = (WSPasswordCallback)callbacks[i]; + WSPasswordCallback nc = (WSPasswordCallback) callbacks[i]; nc.setPassword(this.password); } else { throw new UnsupportedCallbackException(callbacks[i], - "Unrecognized Callback"); + "Unrecognized Callback"); } } } Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/AbstractServletCallback.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/AbstractServletCallback.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/AbstractServletCallback.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/AbstractServletCallback.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,23 @@ +package org.apache.cxf.fediz.core.spi; + +import javax.security.auth.callback.Callback; +import javax.servlet.http.HttpServletRequest; + +public abstract class AbstractServletCallback implements Callback { + + protected HttpServletRequest request = null; + + public AbstractServletCallback(HttpServletRequest request) { + super(); + this.request = request; + } + + public HttpServletRequest getRequest() { + return request; + } + + public void setRequest(HttpServletRequest request) { + this.request = request; + } + +} Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/IDPCallback.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/IDPCallback.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/IDPCallback.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/IDPCallback.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,39 @@ +package org.apache.cxf.fediz.core.spi; + +import java.net.URL; + +import javax.servlet.http.HttpServletRequest; + +public class IDPCallback extends AbstractServletCallback { + + private URL issuerUrl = null; + private String trustedIssuer = null; + + public IDPCallback(HttpServletRequest request) { + super(request); + } + + /*public IDPCallback(HttpServletRequest request, URL issuerUrl, + String trustedIssuer) { + this(request); + this.issuerUrl = issuerUrl; + this.trustedIssuer = trustedIssuer; + }*/ + + public URL getIssuerUrl() { + return issuerUrl; + } + + public void setIssuerUrl(URL issuerUrl) { + this.issuerUrl = issuerUrl; + } + + public String getTrustedIssuer() { + return trustedIssuer; + } + + public void setTrustedIssuer(String trustedIssuer) { + this.trustedIssuer = trustedIssuer; + } + +} Added: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/WAuthCallback.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/WAuthCallback.java?rev=1329945&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/WAuthCallback.java (added) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/spi/WAuthCallback.java Tue Apr 24 19:03:39 2012 @@ -0,0 +1,27 @@ +package org.apache.cxf.fediz.core.spi; + +import javax.servlet.http.HttpServletRequest; + +public class WAuthCallback extends AbstractServletCallback { + + private String wauth = null; + + public WAuthCallback(HttpServletRequest request) { + super(request); + } +/* + public WAuthCallback(HttpServletRequest request, String wauth) { + this(request); + this.wauth = wauth; + } + */ + + public String getWAuth() { + return wauth; + } + + public void setWAuth(String wauth) { + this.wauth = wauth; + } + +} Modified: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java?rev=1329945&r1=1329944&r2=1329945&view=diff ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java (original) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java Tue Apr 24 19:03:39 2012 @@ -54,7 +54,8 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** - * Few simple utils to read DOM. This is originally from the Jakarta Commons Modeler. + * Few simple utils to read DOM. This is originally from the Jakarta Commons + * Modeler. * * @author Costin Manolache */ @@ -62,12 +63,13 @@ public final class DOMUtils { private static final String XMLNAMESPACE = "xmlns"; private static final Map DOCUMENT_BUILDERS = Collections - .synchronizedMap(new WeakHashMap()); + .synchronizedMap(new WeakHashMap()); private DOMUtils() { } - private static DocumentBuilder getBuilder() throws ParserConfigurationException { + private static DocumentBuilder getBuilder() + throws ParserConfigurationException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = DOMUtils.class.getClassLoader(); @@ -84,13 +86,15 @@ public final class DOMUtils { } /** - * This function is much like getAttribute, but returns null, not "", for a nonexistent attribute. + * This function is much like getAttribute, but returns null, not "", for a + * nonexistent attribute. * * @param e * @param attributeName * @return */ - public static String getAttributeValueEmptyNull(Element e, String attributeName) { + public static String getAttributeValueEmptyNull(Element e, + String attributeName) { Attr node = e.getAttributeNode(attributeName); if (node == null) { return null; @@ -122,11 +126,11 @@ public final class DOMUtils { while (n1 != null) { if (n1.getNodeType() == Node.TEXT_NODE) { if (b != null) { - b.append(((Text)n1).getNodeValue()); + b.append(((Text) n1).getNodeValue()); } else if (s == null) { - s = ((Text)n1).getNodeValue(); + s = ((Text) n1).getNodeValue(); } else { - b = new StringBuilder(s).append(((Text)n1).getNodeValue()); + b = new StringBuilder(s).append(((Text) n1).getNodeValue()); s = null; } } @@ -141,8 +145,10 @@ public final class DOMUtils { /** * Get the first element child. * - * @param parent lookup direct childs - * @param name name of the element. If null return the first element. + * @param parent + * lookup direct childs + * @param name + * name of the element. If null return the first element. */ public static Node getChild(Node parent, String name) { if (parent == null) { @@ -187,7 +193,8 @@ public final class DOMUtils { if (StringUtils.isEmpty(attName.getNamespaceURI())) { attr = element.getAttributeNode(attName.getLocalPart()); } else { - attr = element.getAttributeNodeNS(attName.getNamespaceURI(), attName.getLocalPart()); + attr = element.getAttributeNodeNS(attName.getNamespaceURI(), + attName.getLocalPart()); } return attr == null ? null : attr.getValue(); } @@ -222,21 +229,29 @@ public final class DOMUtils { * Find the first direct child with a given attribute. * * @param parent - * @param elemName name of the element, or null for any - * @param attName attribute we're looking for - * @param attVal attribute value or null if we just want any + * @param elemName + * name of the element, or null for any + * @param attName + * attribute we're looking for + * @param attVal + * attribute value or null if we just want any */ - public static Node findChildWithAtt(Node parent, String elemName, String attName, String attVal) { + public static Node findChildWithAtt(Node parent, String elemName, + String attName, String attVal) { Node child = DOMUtils.getChild(parent, Node.ELEMENT_NODE); if (attVal == null) { - while (child != null && (elemName == null || elemName.equals(child.getNodeName())) - && DOMUtils.getAttribute(child, attName) != null) { + while (child != null + && (elemName == null || elemName + .equals(child.getNodeName())) + && DOMUtils.getAttribute(child, attName) != null) { child = getNext(child, elemName, Node.ELEMENT_NODE); } } else { - while (child != null && (elemName == null || elemName.equals(child.getNodeName())) - && !attVal.equals(DOMUtils.getAttribute(child, attName))) { + while (child != null + && (elemName == null || elemName + .equals(child.getNodeName())) + && !attVal.equals(DOMUtils.getAttribute(child, attName))) { child = getNext(child, elemName, Node.ELEMENT_NODE); } } @@ -276,14 +291,14 @@ public final class DOMUtils { if (n == null) { return null; } - return (Element)n; + return (Element) n; } public static Element getNextElement(Element el) { Node nd = el.getNextSibling(); while (nd != null) { if (nd.getNodeType() == Node.ELEMENT_NODE) { - return (Element)nd; + return (Element) nd; } nd = nd.getNextSibling(); } @@ -311,11 +326,13 @@ public final class DOMUtils { * @param lp * @return */ - public static Element getFirstChildWithName(Element parent, String ns, String lp) { + public static Element getFirstChildWithName(Element parent, String ns, + String lp) { for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) { if (n instanceof Element) { - Element e = (Element)n; - String ens = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI(); + Element e = (Element) n; + String ens = (e.getNamespaceURI() == null) ? "" : e + .getNamespaceURI(); if (ns.equals(ens) && lp.equals(e.getLocalName())) { return e; } @@ -332,12 +349,14 @@ public final class DOMUtils { * @param localName * @return */ - public static List getChildrenWithName(Element parent, String ns, String localName) { + public static List getChildrenWithName(Element parent, String ns, + String localName) { List r = new ArrayList(); for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) { if (n instanceof Element) { - Element e = (Element)n; - String eNs = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI(); + Element e = (Element) n; + String eNs = (e.getNamespaceURI() == null) ? "" : e + .getNamespaceURI(); if (ns.equals(eNs) && localName.equals(e.getLocalName())) { r.add(e); } @@ -345,20 +364,24 @@ public final class DOMUtils { } return r; } - + /** * Returns all child elements with specified namespace. * - * @param parent the element to search under - * @param ns the namespace to find elements in + * @param parent + * the element to search under + * @param ns + * the namespace to find elements in * @return all child elements with specified namespace */ - public static List getChildrenWithNamespace(Element parent, String ns) { + public static List getChildrenWithNamespace(Element parent, + String ns) { List r = new ArrayList(); for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) { if (n instanceof Element) { - Element e = (Element)n; - String eNs = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI(); + Element e = (Element) n; + String eNs = (e.getNamespaceURI() == null) ? "" : e + .getNamespaceURI(); if (ns.equals(eNs)) { r.add(e); } @@ -420,7 +443,8 @@ public final class DOMUtils { } public static class NullResolver implements EntityResolver { - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { return new InputSource(new StringReader("")); } } @@ -428,8 +452,8 @@ public final class DOMUtils { /** * Read XML as DOM. */ - public static Document readXml(InputStream is) throws SAXException, IOException, - ParserConfigurationException { + public static Document readXml(InputStream is) throws SAXException, + IOException, ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); @@ -448,7 +472,8 @@ public final class DOMUtils { return db.parse(is); } - public static Document readXml(Reader is) throws SAXException, IOException, ParserConfigurationException { + public static Document readXml(Reader is) throws SAXException, IOException, + ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); @@ -467,8 +492,8 @@ public final class DOMUtils { return db.parse(ips); } - public static Document readXml(StreamSource is) throws SAXException, IOException, - ParserConfigurationException { + public static Document readXml(StreamSource is) throws SAXException, + IOException, ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); @@ -492,7 +517,8 @@ public final class DOMUtils { return db.parse(is2); } - public static void writeXml(Node n, OutputStream os) throws TransformerException { + public static void writeXml(Node n, OutputStream os) + throws TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); // identity Transformer t = tf.newTransformer(); @@ -519,7 +545,7 @@ public final class DOMUtils { public static String getPrefixRecursive(Element el, String ns) { String prefix = getPrefix(el, ns); if (prefix == null && el.getParentNode() instanceof Element) { - prefix = getPrefixRecursive((Element)el.getParentNode(), ns); + prefix = getPrefixRecursive((Element) el.getParentNode(), ns); } return prefix; } @@ -530,7 +556,8 @@ public final class DOMUtils { Node node = atts.item(i); String name = node.getNodeName(); if (ns.equals(node.getNodeValue()) - && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) { + && (name != null && (XMLNAMESPACE.equals(name) || name + .startsWith(XMLNAMESPACE + ":")))) { return node.getLocalName(); } } @@ -544,11 +571,12 @@ public final class DOMUtils { * @param namespaceUri * @param prefixes */ - public static void getPrefixesRecursive(Element element, String namespaceUri, List prefixes) { + public static void getPrefixesRecursive(Element element, + String namespaceUri, List prefixes) { getPrefixes(element, namespaceUri, prefixes); Node parent = element.getParentNode(); if (parent instanceof Element) { - getPrefixesRecursive((Element)parent, namespaceUri, prefixes); + getPrefixesRecursive((Element) parent, namespaceUri, prefixes); } } @@ -559,13 +587,15 @@ public final class DOMUtils { * @param namespaceUri * @param prefixes */ - public static void getPrefixes(Element element, String namespaceUri, List prefixes) { + public static void getPrefixes(Element element, String namespaceUri, + List prefixes) { NamedNodeMap atts = element.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Node node = atts.item(i); String name = node.getNodeName(); if (namespaceUri.equals(node.getNodeValue()) - && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) { + && (name != null && (XMLNAMESPACE.equals(name) || name + .startsWith(XMLNAMESPACE + ":")))) { prefixes.add(node.getPrefix()); } } @@ -583,11 +613,13 @@ public final class DOMUtils { } /** - * Starting from a node, find the namespace declaration for a prefix. for a matching namespace - * declaration. + * Starting from a node, find the namespace declaration for a prefix. for a + * matching namespace declaration. * - * @param node search up from here to search for namespace definitions - * @param searchPrefix the prefix we are searching for + * @param node + * search up from here to search for namespace definitions + * @param searchPrefix + * the prefix we are searching for * @return the namespace if found. */ public static String getNamespace(Node node, String searchPrefix) { @@ -596,56 +628,62 @@ public final class DOMUtils { while (!(node instanceof Element)) { node = node.getParentNode(); } - el = (Element)node; + el = (Element) node; NamedNodeMap atts = el.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Node currentAttribute = atts.item(i); String currentLocalName = currentAttribute.getLocalName(); String currentPrefix = currentAttribute.getPrefix(); - if (searchPrefix.equals(currentLocalName) && XMLNAMESPACE.equals(currentPrefix)) { + if (searchPrefix.equals(currentLocalName) + && XMLNAMESPACE.equals(currentPrefix)) { return currentAttribute.getNodeValue(); - } else if (StringUtils.isEmpty(searchPrefix) && XMLNAMESPACE.equals(currentLocalName) - && StringUtils.isEmpty(currentPrefix)) { + } else if (StringUtils.isEmpty(searchPrefix) + && XMLNAMESPACE.equals(currentLocalName) + && StringUtils.isEmpty(currentPrefix)) { return currentAttribute.getNodeValue(); } } Node parent = el.getParentNode(); if (parent instanceof Element) { - return getNamespace((Element)parent, searchPrefix); + return getNamespace((Element) parent, searchPrefix); } return null; } - public static List findAllElementsByTagNameNS(Element elem, String nameSpaceURI, - String localName) { + public static List findAllElementsByTagNameNS(Element elem, + String nameSpaceURI, String localName) { List ret = new LinkedList(); findAllElementsByTagNameNS(elem, nameSpaceURI, localName, ret); return ret; } - private static void findAllElementsByTagNameNS(Element el, String nameSpaceURI, String localName, - List elementList) { + private static void findAllElementsByTagNameNS(Element el, + String nameSpaceURI, String localName, List elementList) { - if (localName.equals(el.getLocalName()) && nameSpaceURI.contains(el.getNamespaceURI())) { + if (localName.equals(el.getLocalName()) + && nameSpaceURI.contains(el.getNamespaceURI())) { elementList.add(el); } Element elem = getFirstElement(el); while (elem != null) { - findAllElementsByTagNameNS(elem, nameSpaceURI, localName, elementList); + findAllElementsByTagNameNS(elem, nameSpaceURI, localName, + elementList); elem = getNextElement(elem); } } - public static List findAllElementsByTagName(Element elem, String tagName) { + public static List findAllElementsByTagName(Element elem, + String tagName) { List ret = new LinkedList(); findAllElementsByTagName(elem, tagName, ret); return ret; } - private static void findAllElementsByTagName(Element el, String tagName, List elementList) { + private static void findAllElementsByTagName(Element el, String tagName, + List elementList) { if (tagName.equals(el.getTagName())) { elementList.add(el); @@ -656,6 +694,7 @@ public final class DOMUtils { elem = getNextElement(elem); } } + public static boolean hasElementInNS(Element el, String namespace) { if (namespace.equals(el.getNamespaceURI())) { @@ -670,22 +709,26 @@ public final class DOMUtils { } return false; } + /** - * Set a namespace/prefix on an element if it is not set already. First off, it searches for the element - * for the prefix associated with the specified namespace. If the prefix isn't null, then this is - * returned. Otherwise, it creates a new attribute using the namespace/prefix passed as parameters. + * Set a namespace/prefix on an element if it is not set already. First off, + * it searches for the element for the prefix associated with the specified + * namespace. If the prefix isn't null, then this is returned. Otherwise, it + * creates a new attribute using the namespace/prefix passed as parameters. * * @param element * @param namespace * @param prefix * @return the prefix associated with the set namespace */ - public static String setNamespace(Element element, String namespace, String prefix) { + public static String setNamespace(Element element, String namespace, + String prefix) { String pre = getPrefixRecursive(element, namespace); if (pre != null) { return pre; } - element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespace); + element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + + prefix, namespace); return prefix; } @@ -696,7 +739,9 @@ public final class DOMUtils { * @param namespaceUri * @param prefix */ - public static void addNamespacePrefix(Element element, String namespaceUri, String prefix) { - element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespaceUri); + public static void addNamespacePrefix(Element element, String namespaceUri, + String prefix) { + element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + + prefix, namespaceUri); } } Modified: cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/StringUtils.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/StringUtils.java?rev=1329945&r1=1329944&r2=1329945&view=diff ============================================================================== --- cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/StringUtils.java (original) +++ cxf/sandbox/fediz/fediz-core/src/main/java/org/apache/cxf/fediz/core/util/StringUtils.java Tue Apr 24 19:03:39 2012 @@ -34,7 +34,8 @@ public final class StringUtils { private StringUtils() { } - public static String extract(String string, String startToken, String endToken) { + public static String extract(String string, String startToken, + String endToken) { int start = string.indexOf(startToken) + startToken.length(); int end = string.lastIndexOf(endToken); @@ -45,7 +46,8 @@ public final class StringUtils { return string.substring(start, end); } - public static String wrapper(String string, String startToken, String endToken) { + public static String wrapper(String string, String startToken, + String endToken) { StringBuilder sb = new StringBuilder(); sb.append(startToken); sb.append(string); @@ -80,7 +82,7 @@ public final class StringUtils { } return true; } - + public static boolean isEmpty(List list) { if (list == null || list.size() == 0) { return true; @@ -93,16 +95,17 @@ public final class StringUtils { public static boolean isEqualUri(String uri1, String uri2) { - if (uri1.substring(uri1.length() - 1).equals("/") && !uri2.substring(uri2.length() - 1).equals("/")) { + if (uri1.substring(uri1.length() - 1).equals("/") + && !uri2.substring(uri2.length() - 1).equals("/")) { return uri1.substring(0, uri1.length() - 1).equals(uri2); } else if (uri2.substring(uri2.length() - 1).equals("/") - && !uri1.substring(uri1.length() - 1).equals("/")) { + && !uri1.substring(uri1.length() - 1).equals("/")) { return uri2.substring(0, uri2.length() - 1).equals(uri1); } else { return uri1.equals(uri2); } } - + public static String diff(String str1, String str2) { int index = str1.lastIndexOf(str2); if (index > -1) { @@ -110,7 +113,7 @@ public final class StringUtils { } return str1; } - + public static List getParts(String str, String sperator) { List ret = new ArrayList(); List parts = Arrays.asList(str.split("/")); @@ -121,7 +124,7 @@ public final class StringUtils { } return ret; } - + public static String getFirstNotEmpty(String str, String sperator) { List parts = Arrays.asList(str.split("/")); for (String part : parts) { @@ -131,7 +134,7 @@ public final class StringUtils { } return str; } - + public static String getFirstNotEmpty(List list) { if (isEmpty(list)) { return null; @@ -139,11 +142,11 @@ public final class StringUtils { for (String item : list) { if (!isEmpty(item)) { return item; - } + } } return null; } - + public static List getFound(String contents, String regex) { if (isEmpty(regex) || isEmpty(contents)) { return null; @@ -151,7 +154,7 @@ public final class StringUtils { List results = new ArrayList(); Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE); Matcher matcher = pattern.matcher(contents); - + while (matcher.find()) { if (matcher.groupCount() > 0) { results.add(matcher.group(1)); @@ -160,8 +163,8 @@ public final class StringUtils { } } return results; - } - + } + public static String getFirstFound(String contents, String regex) { List founds = getFound(contents, regex); if (isEmpty(founds)) { @@ -169,20 +172,22 @@ public final class StringUtils { } return founds.get(0); } - + public static String formatVersionNumber(String target) { - List found = StringUtils.getFound(target, "\\d+\\.\\d+\\.?\\d*"); + List found = StringUtils + .getFound(target, "\\d+\\.\\d+\\.?\\d*"); if (isEmpty(found)) { return target; } return getFirstNotEmpty(found); } - + public static String addDefaultPortIfMissing(String urlString) { return addDefaultPortIfMissing(urlString, "80"); } - - public static String addDefaultPortIfMissing(String urlString, String defaultPort) { + + public static String addDefaultPortIfMissing(String urlString, + String defaultPort) { URL url = null; try { url = new URL(urlString); @@ -192,19 +197,21 @@ public final class StringUtils { if (url.getPort() != -1) { return urlString; } - String regex = "http://([^/]+)"; + String regex = "http://([^/]+)"; String found = StringUtils.getFirstFound(urlString, regex); String replacer = "http://" + found + ":" + defaultPort; - + if (!StringUtils.isEmpty(found)) { urlString = urlString.replaceFirst(regex, replacer); - } + } return urlString; } - + /** * Return input string with first character in upper case. - * @param name input string. + * + * @param name + * input string. * @return capitalized form. */ public static String capitalize(String name) { @@ -215,14 +222,13 @@ public final class StringUtils { chars[0] = Character.toUpperCase(chars[0]); return new String(chars); } - + public static String uncapitalize(String str) { if (str == null || str.length() == 0) { return str; } return new StringBuilder(str.length()) - .append(Character.toLowerCase(str.charAt(0))) - .append(str.substring(1)) - .toString(); - } + .append(Character.toLowerCase(str.charAt(0))) + .append(str.substring(1)).toString(); + } }