src/share/classes/com/sun/org/apache/xml/internal/security/keys/content/x509/XMLX509IssuerSerial.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright  1999-2004 The Apache Software Foundation.
   7  *
   8  *  Licensed under the Apache License, Version 2.0 (the "License");
   9  *  you may not use this file except in compliance with the License.
  10  *  You may obtain a copy of the License at


  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  *  Unless required by applicable law or agreed to in writing, software
  15  *  distributed under the License is distributed on an "AS IS" BASIS,
  16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  *  See the License for the specific language governing permissions and
  18  *  limitations under the License.
  19  *
  20  */
  21 package com.sun.org.apache.xml.internal.security.keys.content.x509;
  22 
  23 import java.math.BigInteger;
  24 import java.security.cert.X509Certificate;
  25 
  26 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
  27 import com.sun.org.apache.xml.internal.security.utils.Constants;
  28 import com.sun.org.apache.xml.internal.security.utils.RFC2253Parser;
  29 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
  30 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
  31 import org.w3c.dom.Document;
  32 import org.w3c.dom.Element;
  33 
  34 /**
  35  *
  36  * @author $Author: mullan $
  37  */
  38 public class XMLX509IssuerSerial extends SignatureElementProxy
  39         implements XMLX509DataContent {
  40 
  41     /** {@link java.util.logging} logging facility */
  42     static java.util.logging.Logger log =
  43         java.util.logging.Logger.getLogger(
  44                     XMLX509IssuerSerial.class.getName());
  45 
  46     /**
  47      * Constructor XMLX509IssuerSerial
  48      *
  49      * @param element
  50      * @param baseURI
  51      * @throws XMLSecurityException
  52      */
  53     public XMLX509IssuerSerial(Element element, String baseURI)
  54            throws XMLSecurityException {
  55         super(element, baseURI);
  56     }
  57 
  58     /**
  59      * Constructor XMLX509IssuerSerial
  60      *
  61      * @param doc
  62      * @param x509IssuerName
  63      * @param x509SerialNumber
  64      */
  65     public XMLX509IssuerSerial(Document doc, String x509IssuerName,
  66                                BigInteger x509SerialNumber) {
  67 
  68         super(doc);
  69         XMLUtils.addReturnToElement(this._constructionElement);
  70         addTextElement(x509IssuerName, Constants._TAG_X509ISSUERNAME);
  71         addTextElement(x509SerialNumber.toString(), Constants._TAG_X509SERIALNUMBER);
  72     }
  73 
  74     /**
  75      * Constructor XMLX509IssuerSerial
  76      *
  77      * @param doc
  78      * @param x509IssuerName
  79      * @param x509SerialNumber
  80      */
  81     public XMLX509IssuerSerial(Document doc, String x509IssuerName,
  82                                String x509SerialNumber) {
  83         this(doc, x509IssuerName, new BigInteger(x509SerialNumber));
  84     }
  85 
  86     /**
  87      * Constructor XMLX509IssuerSerial
  88      *
  89      * @param doc
  90      * @param x509IssuerName
  91      * @param x509SerialNumber
  92      */
  93     public XMLX509IssuerSerial(Document doc, String x509IssuerName,
  94                                int x509SerialNumber) {
  95         this(doc, x509IssuerName,
  96              new BigInteger(Integer.toString(x509SerialNumber)));
  97     }
  98 
  99     /**
 100      * Constructor XMLX509IssuerSerial
 101      *
 102      * @param doc
 103      * @param x509certificate
 104      */
 105     public XMLX509IssuerSerial(Document doc, X509Certificate x509certificate) {
 106 
 107         this(doc,
 108              RFC2253Parser.normalize(x509certificate.getIssuerDN().getName()),
 109              x509certificate.getSerialNumber());

 110     }
 111 
 112     /**
 113      * Method getSerialNumber
 114      *
 115      * @return the serial number
 116      */
 117     public BigInteger getSerialNumber() {
 118 
 119         String text = this.getTextFromChildElement
 120             (Constants._TAG_X509SERIALNUMBER, Constants.SignatureSpecNS);
 121         if (log.isLoggable(java.util.logging.Level.FINE))
 122             log.log(java.util.logging.Level.FINE, "X509SerialNumber text: " + text);

 123 
 124         return new BigInteger(text);
 125     }
 126 
 127     /**
 128      * Method getSerialNumberInteger
 129      *
 130      * @return the serial number as plain int
 131      */
 132     public int getSerialNumberInteger() {
 133         return this.getSerialNumber().intValue();
 134     }
 135 
 136     /**
 137      * Method getIssuerName
 138      *
 139      * @return the issuer name
 140      */
 141     public String getIssuerName()  {
 142 
 143         return RFC2253Parser
 144            .normalize(this
 145               .getTextFromChildElement(Constants._TAG_X509ISSUERNAME,
 146                                        Constants.SignatureSpecNS));
 147     }
 148 
 149     /** @inheritDoc */
 150     public boolean equals(Object obj) {
 151 
 152         if (obj == null) {
 153             return false;
 154         }
 155         if (!this.getClass().getName().equals(obj.getClass().getName())) {
 156             return false;
 157         }
 158 
 159         XMLX509IssuerSerial other = (XMLX509IssuerSerial) obj;
 160 
 161         return this.getSerialNumber().equals(other.getSerialNumber())
 162                && this.getIssuerName().equals(other.getIssuerName());







 163     }
 164 
 165     /** @inheritDoc */
 166     public String getBaseLocalName() {
 167         return Constants._TAG_X509ISSUERSERIAL;
 168     }
 169 }
   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /**
   6  * Licensed to the Apache Software Foundation (ASF) under one
   7  * or more contributor license agreements. See the NOTICE file
   8  * distributed with this work for additional information
   9  * regarding copyright ownership. The ASF licenses this file
  10  * to you under the Apache License, Version 2.0 (the
  11  * "License"); you may not use this file except in compliance
  12  * with the License. You may obtain a copy of the License at
  13  *
  14  * http://www.apache.org/licenses/LICENSE-2.0
  15  *
  16  * Unless required by applicable law or agreed to in writing,
  17  * software distributed under the License is distributed on an
  18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19  * KIND, either express or implied. See the License for the
  20  * specific language governing permissions and limitations
  21  * under the License.
  22  */
  23 package com.sun.org.apache.xml.internal.security.keys.content.x509;
  24 
  25 import java.math.BigInteger;
  26 import java.security.cert.X509Certificate;
  27 
  28 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
  29 import com.sun.org.apache.xml.internal.security.utils.Constants;
  30 import com.sun.org.apache.xml.internal.security.utils.RFC2253Parser;
  31 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
  32 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
  33 import org.w3c.dom.Document;
  34 import org.w3c.dom.Element;
  35 
  36 public class XMLX509IssuerSerial extends SignatureElementProxy implements XMLX509DataContent {





  37 
  38     /** {@link org.apache.commons.logging} logging facility */
  39     private static java.util.logging.Logger log = 
  40         java.util.logging.Logger.getLogger(XMLX509IssuerSerial.class.getName());

  41 
  42     /**
  43      * Constructor XMLX509IssuerSerial
  44      *
  45      * @param element
  46      * @param baseURI
  47      * @throws XMLSecurityException
  48      */
  49     public XMLX509IssuerSerial(Element element, String baseURI) throws XMLSecurityException {

  50         super(element, baseURI);
  51     }
  52 
  53     /**
  54      * Constructor XMLX509IssuerSerial
  55      *
  56      * @param doc
  57      * @param x509IssuerName
  58      * @param x509SerialNumber
  59      */
  60     public XMLX509IssuerSerial(Document doc, String x509IssuerName, BigInteger x509SerialNumber) {


  61         super(doc);
  62         XMLUtils.addReturnToElement(this.constructionElement);
  63         addTextElement(x509IssuerName, Constants._TAG_X509ISSUERNAME);
  64         addTextElement(x509SerialNumber.toString(), Constants._TAG_X509SERIALNUMBER);
  65     }
  66 
  67     /**
  68      * Constructor XMLX509IssuerSerial
  69      *
  70      * @param doc
  71      * @param x509IssuerName
  72      * @param x509SerialNumber
  73      */
  74     public XMLX509IssuerSerial(Document doc, String x509IssuerName, String x509SerialNumber) {

  75         this(doc, x509IssuerName, new BigInteger(x509SerialNumber));
  76     }
  77 
  78     /**
  79      * Constructor XMLX509IssuerSerial
  80      *
  81      * @param doc
  82      * @param x509IssuerName
  83      * @param x509SerialNumber
  84      */
  85     public XMLX509IssuerSerial(Document doc, String x509IssuerName, int x509SerialNumber) {
  86         this(doc, x509IssuerName, new BigInteger(Integer.toString(x509SerialNumber)));


  87     }
  88 
  89     /**
  90      * Constructor XMLX509IssuerSerial
  91      *
  92      * @param doc
  93      * @param x509certificate
  94      */
  95     public XMLX509IssuerSerial(Document doc, X509Certificate x509certificate) {
  96         this(
  97             doc,
  98             x509certificate.getIssuerX500Principal().getName(),
  99             x509certificate.getSerialNumber()
 100         );
 101     }
 102 
 103     /**
 104      * Method getSerialNumber
 105      *
 106      * @return the serial number
 107      */
 108     public BigInteger getSerialNumber() {
 109         String text = 
 110             this.getTextFromChildElement(Constants._TAG_X509SERIALNUMBER, Constants.SignatureSpecNS);
 111         if (log.isLoggable(java.util.logging.Level.FINE)) {

 112             log.log(java.util.logging.Level.FINE, "X509SerialNumber text: " + text);
 113         }
 114 
 115         return new BigInteger(text);
 116     }
 117 
 118     /**
 119      * Method getSerialNumberInteger
 120      *
 121      * @return the serial number as plain int
 122      */
 123     public int getSerialNumberInteger() {
 124         return this.getSerialNumber().intValue();
 125     }
 126 
 127     /**
 128      * Method getIssuerName
 129      *
 130      * @return the issuer name
 131      */
 132     public String getIssuerName()  {
 133         return RFC2253Parser.normalize(
 134             this.getTextFromChildElement(Constants._TAG_X509ISSUERNAME, Constants.SignatureSpecNS)
 135         );


 136     }
 137 
 138     /** @inheritDoc */
 139     public boolean equals(Object obj) {
 140         if (!(obj instanceof XMLX509IssuerSerial)) {




 141             return false;
 142         }
 143 
 144         XMLX509IssuerSerial other = (XMLX509IssuerSerial) obj;
 145 
 146         return this.getSerialNumber().equals(other.getSerialNumber())
 147             && this.getIssuerName().equals(other.getIssuerName());
 148     }
 149 
 150     public int hashCode() {
 151         int result = 17;
 152         result = 31 * result + getSerialNumber().hashCode();
 153         result = 31 * result + getIssuerName().hashCode();
 154         return result;
 155     }
 156 
 157     /** @inheritDoc */
 158     public String getBaseLocalName() {
 159         return Constants._TAG_X509ISSUERSERIAL;
 160     }
 161 }