View Javadoc
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.security.cert.X509Certificate;
26  
27  import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
28  import com.sun.org.apache.xml.internal.security.utils.Constants;
29  import com.sun.org.apache.xml.internal.security.utils.RFC2253Parser;
30  import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
31  import org.w3c.dom.Document;
32  import org.w3c.dom.Element;
33  
34  /**
35   * @author $Author: coheigea $
36   */
37  public class XMLX509SubjectName extends SignatureElementProxy implements XMLX509DataContent {
38  
39      /**
40       * Constructor X509SubjectName
41       *
42       * @param element
43       * @param BaseURI
44       * @throws XMLSecurityException
45       */
46      public XMLX509SubjectName(Element element, String BaseURI)
47          throws XMLSecurityException {
48          super(element, BaseURI);
49      }
50  
51      /**
52       * Constructor X509SubjectName
53       *
54       * @param doc
55       * @param X509SubjectNameString
56       */
57      public XMLX509SubjectName(Document doc, String X509SubjectNameString) {
58          super(doc);
59  
60          this.addText(X509SubjectNameString);
61      }
62  
63      /**
64       * Constructor XMLX509SubjectName
65       *
66       * @param doc
67       * @param x509certificate
68       */
69      public XMLX509SubjectName(Document doc, X509Certificate x509certificate) {
70          this(doc, x509certificate.getSubjectX500Principal().getName());
71      }
72  
73      /**
74       * Method getSubjectName
75       *
76       *
77       * @return the subject name
78       */
79      public String getSubjectName() {
80          return RFC2253Parser.normalize(this.getTextFromTextChild());
81      }
82  
83      /** @inheritDoc */
84      public boolean equals(Object obj) {
85          if (!(obj instanceof XMLX509SubjectName)) {
86              return false;
87          }
88  
89          XMLX509SubjectName other = (XMLX509SubjectName) obj;
90          String otherSubject = other.getSubjectName();
91          String thisSubject = this.getSubjectName();
92  
93          return thisSubject.equals(otherSubject);
94      }
95  
96      public int hashCode() {
97          int result = 17;
98          result = 31 * result + this.getSubjectName().hashCode();
99          return result;
100     }
101 
102     /** @inheritDoc */
103     public String getBaseLocalName() {
104         return Constants._TAG_X509SUBJECTNAME;
105     }
106 }