J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 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 | |
| 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 | * |
| 36 | * @author $Author: raul $ |
| 37 | */ |
| 38 | public class XMLX509SubjectName 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(XMLX509SubjectName.class.getName()); |
| 44 | |
| 45 | /** |
| 46 | * Constructor X509SubjectName |
| 47 | * |
| 48 | * @param element |
| 49 | * @param BaseURI |
| 50 | * @throws XMLSecurityException |
| 51 | */ |
| 52 | public XMLX509SubjectName(Element element, String BaseURI) |
| 53 | throws XMLSecurityException { |
| 54 | super(element, BaseURI); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Constructor X509SubjectName |
| 59 | * |
| 60 | * @param doc |
| 61 | * @param X509SubjectNameString |
| 62 | */ |
| 63 | public XMLX509SubjectName(Document doc, String X509SubjectNameString) { |
| 64 | |
| 65 | super(doc); |
| 66 | |
| 67 | this.addText(X509SubjectNameString); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Constructor XMLX509SubjectName |
| 72 | * |
| 73 | * @param doc |
| 74 | * @param x509certificate |
| 75 | */ |
| 76 | public XMLX509SubjectName(Document doc, X509Certificate x509certificate) { |
| 77 | this(doc, |
| 78 | RFC2253Parser.normalize(x509certificate.getSubjectDN().getName())); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Method getSubjectName |
| 83 | * |
| 84 | * |
| 85 | * @return the subject name |
| 86 | */ |
| 87 | public String getSubjectName() { |
| 88 | return RFC2253Parser.normalize(this.getTextFromTextChild()); |
| 89 | } |
| 90 | |
| 91 | /** @inheritDoc */ |
| 92 | public boolean equals(Object obj) { |
| 93 | |
| 94 | if (!obj.getClass().getName().equals(this.getClass().getName())) { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | XMLX509SubjectName other = (XMLX509SubjectName) obj; |
| 99 | String otherSubject = other.getSubjectName(); |
| 100 | String thisSubject = this.getSubjectName(); |
| 101 | |
| 102 | if (otherSubject.equals(thisSubject)) { |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | return false; |
| 107 | |
| 108 | } |
| 109 | |
| 110 | /** @inheritDoc */ |
| 111 | public String getBaseLocalName() { |
| 112 | return Constants._TAG_X509SUBJECTNAME; |
| 113 | } |
| 114 | } |