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.security.cert.X509Certificate; 24 25 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 26 import com.sun.org.apache.xml.internal.security.utils.Constants; 27 import com.sun.org.apache.xml.internal.security.utils.RFC2253Parser; 28 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; 29 import org.w3c.dom.Document; 30 import org.w3c.dom.Element; 31 32 /** 33 * 34 * @author $Author: mullan $ 35 */ 36 public class XMLX509SubjectName extends SignatureElementProxy 37 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 59 super(doc); 60 61 this.addText(X509SubjectNameString); 62 } 63 64 /** 65 * Constructor XMLX509SubjectName 66 * 67 * @param doc 68 * @param x509certificate 69 */ 70 public XMLX509SubjectName(Document doc, X509Certificate x509certificate) { 71 this(doc, 72 RFC2253Parser.normalize(x509certificate.getSubjectDN().getName())); 73 } 74 75 /** 76 * Method getSubjectName 77 * 78 * 79 * @return the subject name 80 */ 81 public String getSubjectName() { 82 return RFC2253Parser.normalize(this.getTextFromTextChild()); 83 } 84 85 /** @inheritDoc */ 86 public boolean equals(Object obj) { 87 if (obj == null) { 88 return false; 89 } 90 91 if (!this.getClass().getName().equals(obj.getClass().getName())) { 92 return false; 93 } 94 95 XMLX509SubjectName other = (XMLX509SubjectName) obj; 96 String otherSubject = other.getSubjectName(); 97 String thisSubject = this.getSubjectName(); 98 99 return thisSubject.equals(otherSubject); 100 } 101 102 /** @inheritDoc */ 103 public String getBaseLocalName() { 104 return Constants._TAG_X509SUBJECTNAME; 105 } 106 } | 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 } |