Class X500Name
- java.lang.Object
-
- org.mozilla.jss.netscape.security.x509.X500Name
-
- All Implemented Interfaces:
java.io.Serializable,java.security.Principal,GeneralNameInterface
public class X500Name extends java.lang.Object implements java.security.Principal, GeneralNameInterface
X.500 names are used to identify entities, such as those which are identified by X.509 certificates. They are world-wide, hierarchical, and descriptive. Entities can be identified by attributes, and in some systems can be searched for according to those attributes.This class exposes only partial X.500 name functionality. Most notably, it works best if Relative Distinguished Names only have one (unique) attribute each, and if only the most common attributes need to be visible to applications. This limitation, and others, will be lifted over time.
- See Also:
GeneralName,GeneralNames,GeneralNameInterface,RDN,AVA,LdapDNStrConverter, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ObjectIdentifiercommonName_oidOID for the "CN=" attribute, denoting a person's common name.static ObjectIdentifiercountryName_oidOID for the "C=" attribute, denoting a country.static ObjectIdentifieremail_oidOID for the "E=" attribute, denoting a person's email address.static ObjectIdentifieripAddress_oidOID for "IP=" IP address attributes, used with SKIP.static ObjectIdentifierlocalityName_oidOID for the "L=" attribute, denoting a locality (such as a city)static ObjectIdentifierorgName_oidOID for the "O=" attribute, denoting an organization namestatic ObjectIdentifierorgUnitName_oidOID for the "OU=" attribute, denoting an organizational unit namestatic ObjectIdentifierstateName_oidOID for the "S=" attribute, denoting a state (such as Delaware)static ObjectIdentifierstreetAddress_oidOID for the "STREET=" attribute, denoting a street address.static ObjectIdentifiertitle_oidOID for the "T=" attribute, denoting a person's title.static ObjectIdentifieruidName_oidOID for the "UID=" attribute, denoting a person's ID.-
Fields inherited from interface org.mozilla.jss.netscape.security.x509.GeneralNameInterface
NAME_ANY, NAME_DIRECTORY, NAME_DNS, NAME_EDI, NAME_IP, NAME_OID, NAME_RFC822, NAME_URI, NAME_X400
-
-
Constructor Summary
Constructors Constructor Description X500Name(byte[] name)Constructs a name from an ASN.1 encoded byte array.X500Name(java.lang.String ldapDNString)Constructs a name from a Ldap DN string, such as "CN=Dave, OU=JavaSoft, O=Sun Microsystems, C=US".X500Name(java.lang.String ldapDNString, byte[] tags)X500Name(java.lang.String commonName, java.lang.String organizationUnit, java.lang.String organizationName, java.lang.String country)Constructs a X500Name from fields common in enterprise application environments.X500Name(java.lang.String commonName, java.lang.String organizationUnit, java.lang.String organizationName, java.lang.String localityName, java.lang.String stateName, java.lang.String country)Constructs a X500Name from fields common in Internet application environments.X500Name(java.lang.String ldapDNString, LdapDNStrConverter ldapDNStrConverter)Constructs a X500Name from a Ldap DN String using the specified LdapDNStrConverter.X500Name(java.lang.String ldapDNString, LdapDNStrConverter ldapDNStrConverter, byte[] tags)Constructs a X500Name from a Ldap DN String using the specified LdapDNStrConverter.X500Name(java.util.Vector<RDN> rdnVector)convenience method.X500Name(DerInputStream in)Constructs a name from an ASN.1 encoded input stream.X500Name(DerValue value)Constructs a name from an ASN.1 encoded value.X500Name(RDN[] rdns)Constructs a X500Name from array of RDN.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidencode(DerOutputStream out)Encodes the name in DER-encoded form.booleanequals(java.lang.Object obj)java.util.List<java.lang.String>getAttributesForOid(ObjectIdentifier oid)Return a list of attributes of the given type.java.lang.StringgetCommonName()Returns a "Common Name" component.java.lang.StringgetCountry()Returns a "Country" name component.java.lang.StringgetEmail()Returns a "Email" name component.byte[]getEncoded()Gets the name in DER-encoded form.java.lang.StringgetLocality()Returns a "Locality" name component.java.lang.StringgetName()Returns the value of toString().RDN[]getNames()Returns an array of RDN in the X500Name.intgetNamesLength()Returns the number of RDNs in the X500Name.java.lang.StringgetOrganization()Returns an "Organization" name component.java.lang.StringgetOrganizationalUnit()Returns an "Organizational Unit" name component.java.util.Enumeration<RDN>getRDNs()Returns an enumerator of RDNs in the X500Name.java.lang.StringgetState()Returns a "State" name component.intgetType()Return type of GeneralName.java.lang.StringgetUserID()Returns a "UID" component.inthashCode()java.lang.StringtoLdapDNString()Returns a Ldap DN String from the X500Name using the global default LdapDNStrConverterjava.lang.StringtoLdapDNString(LdapDNStrConverter ldapDNStrConverter)Returns a Ldap DN String from the X500Name using the specified LdapDNStrconverter.java.lang.StringtoString()Returns a Ldap DN string, using the global default LdapDNStrConverter or null if an error occurs in the conversion.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.mozilla.jss.netscape.security.x509.GeneralNameInterface
validSingle, validSubtree
-
-
-
-
Field Detail
-
commonName_oid
public static final ObjectIdentifier commonName_oid
OID for the "CN=" attribute, denoting a person's common name.
-
uidName_oid
public static final ObjectIdentifier uidName_oid
OID for the "UID=" attribute, denoting a person's ID.
-
countryName_oid
public static final ObjectIdentifier countryName_oid
OID for the "C=" attribute, denoting a country.
-
localityName_oid
public static final ObjectIdentifier localityName_oid
OID for the "L=" attribute, denoting a locality (such as a city)
-
orgName_oid
public static final ObjectIdentifier orgName_oid
OID for the "O=" attribute, denoting an organization name
-
orgUnitName_oid
public static final ObjectIdentifier orgUnitName_oid
OID for the "OU=" attribute, denoting an organizational unit name
-
stateName_oid
public static final ObjectIdentifier stateName_oid
OID for the "S=" attribute, denoting a state (such as Delaware)
-
streetAddress_oid
public static final ObjectIdentifier streetAddress_oid
OID for the "STREET=" attribute, denoting a street address.
-
title_oid
public static final ObjectIdentifier title_oid
OID for the "T=" attribute, denoting a person's title.
-
email_oid
public static final ObjectIdentifier email_oid
OID for the "E=" attribute, denoting a person's email address.
-
ipAddress_oid
public static final ObjectIdentifier ipAddress_oid
OID for "IP=" IP address attributes, used with SKIP.
-
-
Constructor Detail
-
X500Name
public X500Name(java.lang.String ldapDNString) throws java.io.IOExceptionConstructs a name from a Ldap DN string, such as "CN=Dave, OU=JavaSoft, O=Sun Microsystems, C=US". The older "/C=US/O=Sun Microsystems, Inc/OU=JavaSoft/CN=Dave" syntax is not currently supported. (The former is RFC 1779 style.)- Parameters:
ldapDNString- a Ldap DN String e.g. as defined in RFC1779- Throws:
java.io.IOException
-
X500Name
public X500Name(java.lang.String ldapDNString, LdapDNStrConverter ldapDNStrConverter, byte[] tags) throws java.io.IOExceptionConstructs a X500Name from a Ldap DN String using the specified LdapDNStrConverter. Also use the input tags.- Parameters:
ldapDNString- a Ldap DN String e.g. as defined in RFC1779.ldapDNStrConverter- A LdapDNStrConverter- Throws:
java.io.IOException- See Also:
LdapDNStrConverter
-
X500Name
public X500Name(java.lang.String ldapDNString, byte[] tags) throws java.io.IOException- Throws:
java.io.IOException
-
X500Name
public X500Name(java.lang.String ldapDNString, LdapDNStrConverter ldapDNStrConverter) throws java.io.IOExceptionConstructs a X500Name from a Ldap DN String using the specified LdapDNStrConverter.- Parameters:
ldapDNString- a Ldap DN String e.g. as defined in RFC1779.ldapDNStrConverter- A LdapDNStrConverter- Throws:
java.io.IOException- See Also:
LdapDNStrConverter
-
X500Name
public X500Name(java.lang.String commonName, java.lang.String organizationUnit, java.lang.String organizationName, java.lang.String country) throws java.io.IOExceptionConstructs a X500Name from fields common in enterprise application environments.- Parameters:
commonName- common name of a person, e.g. "Vivette Davis"organizationUnit- small organization name, e.g. "Purchasing"organizationName- large organization name, e.g. "Onizuka, Inc."country- two letter country code, e.g. "CH"- Throws:
java.io.IOException
-
X500Name
public X500Name(java.lang.String commonName, java.lang.String organizationUnit, java.lang.String organizationName, java.lang.String localityName, java.lang.String stateName, java.lang.String country) throws java.io.IOExceptionConstructs a X500Name from fields common in Internet application environments.- Parameters:
commonName- common name of a person, e.g. "Vivette Davis"organizationUnit- small organization name, e.g. "Purchasing"organizationName- large organization name, e.g. "Onizuka, Inc."localityName- locality (city) name, e.g. "Palo Alto"stateName- state name, e.g. "California"country- two letter country code, e.g. "CH"- Throws:
java.io.IOException
-
X500Name
public X500Name(DerValue value) throws java.io.IOException
Constructs a name from an ASN.1 encoded value. The encoding of the name in the stream uses DER (a BER/1 subset).- Parameters:
value- a DER-encoded value holding an X.500 name.- Throws:
java.io.IOException
-
X500Name
public X500Name(DerInputStream in) throws java.io.IOException
Constructs a name from an ASN.1 encoded input stream. The encoding of the name in the stream uses DER (a BER/1 subset).- Parameters:
in- DER-encoded data holding an X.500 name.- Throws:
java.io.IOException
-
X500Name
public X500Name(byte[] name) throws java.io.IOExceptionConstructs a name from an ASN.1 encoded byte array.- Parameters:
name- DER-encoded byte array holding an X.500 name.- Throws:
java.io.IOException
-
X500Name
public X500Name(RDN[] rdns) throws java.io.IOException
Constructs a X500Name from array of RDN. The RDNs are expected to be in big endian order i.e. most significant first.- Parameters:
rdns- an array of RDN.- Throws:
java.io.IOException
-
X500Name
public X500Name(java.util.Vector<RDN> rdnVector) throws java.io.IOException
convenience method.- Parameters:
rdnVector- a vector of rdns.- Throws:
java.io.IOException
-
-
Method Detail
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.security.Principal- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equalsin interfacejava.security.Principal- Overrides:
equalsin classjava.lang.Object
-
getType
public int getType()
Return type of GeneralName.- Specified by:
getTypein interfaceGeneralNameInterface
-
getCountry
public java.lang.String getCountry() throws java.io.IOExceptionReturns a "Country" name component. If more than one such attribute exists, the topmost one is returned.- Returns:
- "C=" component of the name, if any.
- Throws:
java.io.IOException
-
getOrganization
public java.lang.String getOrganization() throws java.io.IOExceptionReturns an "Organization" name component. If more than one such attribute exists, the topmost one is returned.- Returns:
- "O=" component of the name, if any.
- Throws:
java.io.IOException
-
getOrganizationalUnit
public java.lang.String getOrganizationalUnit() throws java.io.IOExceptionReturns an "Organizational Unit" name component. If more than one such attribute exists, the topmost one is returned.- Returns:
- "OU=" component of the name, if any.
- Throws:
java.io.IOException
-
getCommonName
public java.lang.String getCommonName() throws java.io.IOExceptionReturns a "Common Name" component. If more than one such attribute exists, the topmost one is returned.- Returns:
- "CN=" component of the name, if any.
- Throws:
java.io.IOException
-
getUserID
public java.lang.String getUserID() throws java.io.IOExceptionReturns a "UID" component. If more than one such attribute exists, the topmost one is returned.- Returns:
- "UID=" component of the name, if any.
- Throws:
java.io.IOException
-
getLocality
public java.lang.String getLocality() throws java.io.IOExceptionReturns a "Locality" name component. If more than one such component exists, the topmost one is returned.- Returns:
- "L=" component of the name, if any.
- Throws:
java.io.IOException
-
getState
public java.lang.String getState() throws java.io.IOExceptionReturns a "State" name component. If more than one such component exists, the topmost one is returned.- Returns:
- "S=" component of the name, if any.
- Throws:
java.io.IOException
-
getEmail
public java.lang.String getEmail() throws java.io.IOExceptionReturns a "Email" name component. If more than one such component exists, the topmost one is returned.- Returns:
- "E=" component of the name, if any.
- Throws:
java.io.IOException
-
toLdapDNString
public java.lang.String toLdapDNString() throws java.io.IOExceptionReturns a Ldap DN String from the X500Name using the global default LdapDNStrConverter- Returns:
- Ldap DN string of this X500Name using the default converter.
- Throws:
java.io.IOException- See Also:
LdapDNStrConverter
-
getAttributesForOid
public java.util.List<java.lang.String> getAttributesForOid(ObjectIdentifier oid) throws java.io.IOException
Return a list of attributes of the given type. The "most specific" value comes last. If there are no name attributes of the given type, an empty list is returned.- Throws:
java.io.IOException
-
toLdapDNString
public java.lang.String toLdapDNString(LdapDNStrConverter ldapDNStrConverter) throws java.io.IOException
Returns a Ldap DN String from the X500Name using the specified LdapDNStrconverter. For example, RFC1779String converter can be passed to convert the DN to RFC1779 string syntax.- Parameters:
ldapDNStrConverter- a LdapDNStrConverter- Returns:
- Ldap DN string of the X500Name
- Throws:
java.io.IOException- See Also:
LdapDNStrConverter
-
toString
public java.lang.String toString()
Returns a Ldap DN string, using the global default LdapDNStrConverter or null if an error occurs in the conversion.- Specified by:
toStringin interfacejava.security.Principal- Overrides:
toStringin classjava.lang.Object
-
getName
public java.lang.String getName()
Returns the value of toString(). This call is needed to implement the java.security.Principal interface.- Specified by:
getNamein interfacejava.security.Principal
-
getRDNs
public java.util.Enumeration<RDN> getRDNs()
Returns an enumerator of RDNs in the X500Name.- Returns:
- enumeration of rdns in this X500Name.
-
getNames
public RDN[] getNames()
Returns an array of RDN in the X500Name.- Returns:
- array of RDN in this X500name.
-
getNamesLength
public int getNamesLength()
Returns the number of RDNs in the X500Name.- Returns:
- number of RDNs in this X500Name.
-
encode
public void encode(DerOutputStream out) throws java.io.IOException
Encodes the name in DER-encoded form.- Specified by:
encodein interfaceGeneralNameInterface- Parameters:
out- where to put the DER-encoded X.500 name- Throws:
java.io.IOException- thrown if the GeneralName could not be encoded.
-
getEncoded
public byte[] getEncoded() throws java.io.IOExceptionGets the name in DER-encoded form.- Returns:
- the DER encoded byte array of this name, null if no names are present.
- Throws:
java.io.IOException
-
-