public class X500NameUtils extends Object
Constructor and Description |
---|
X500NameUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
equal(String rfc2253dn1,
String rfc2253dn2)
Convenience method, based on the standard JDK algorithm for DNs comparison.
|
static boolean |
equal(X500Principal dn,
String rfc2253dn2)
Convenience method for DN comparison.
|
static Set<ASN1ObjectIdentifier> |
getAttributeNames(String srcDn)
Returns a set with all attribute identifiers which are present in the passed DN.
|
static Set<ASN1ObjectIdentifier> |
getAttributeNames(X500Principal srcDn)
Returns a set with all attribute identifiers which are present in the passed DN.
|
static String[] |
getAttributeValues(String srcDn,
ASN1ObjectIdentifier attribute)
Returns an array of values of a provided attribute from the DN.
|
static String[] |
getAttributeValues(X500Principal srcDn,
ASN1ObjectIdentifier attribute)
Returns an array of values of a provided attribute from the DN.
|
static String |
getComparableForm(String srcDn)
Returns a form of the source DN in RFC 2253 form (or similar - some
minor format violations are properly handled) which is suitable for string comparison.
|
static String |
getPortableRFC2253Form(String srcDn)
Returns a form of the source DN in RFC 2253 form (or similar - some
minor format violations are properly handled) which is strictly RFC2253
and is guaranteed to be correctly parsed by the JDK methods.
|
static String |
getReadableForm(String srcDn)
Returns a human-readable representation of this DN.
|
static String |
getReadableForm(X500Principal srcDn)
Returns a human-readable representation of this DN.
|
static X500Principal |
getX500Principal(String rfcDn)
Constructs a
X500Principal object from a RFC 2253 string. |
static boolean |
rfc3280Equal(X500Principal dn,
X500Principal dn2)
Uses the strict RFC 3280 algorithm to compare two DNs.
|
public static boolean equal(String rfc2253dn1, String rfc2253dn2) throws IllegalArgumentException
rfc2253dn1
- to be compared (need not to strictly follow the RFC encoding)rfc2253dn2
- to be compared (need not to strictly follow the RFC encoding)IllegalArgumentException
- if at least one of the DNs can not be parsedpublic static boolean equal(X500Principal dn, String rfc2253dn2) throws IllegalArgumentException
equal(String, String)
, after retrieving a String representation of
the first argument.dn
- to be comparedrfc2253dn2
- to be comparedIllegalArgumentException
- if the String DN can not be parsedpublic static boolean rfc3280Equal(X500Principal dn, X500Principal dn2)
Note 1: that in certain situations it is possible to get a false answer when comparing DNs with this method, while other DN equality tests from this class (operating on String DN representations) return true.
Note 2: it is nearly always wrong to convert a string representation of a DN to the X500Principal object and then to compare it against another using this method. In such a case always use the other equal methods from this class with one or two String arguments.
Note 3: this implementation is actually delegating to the JDK's X500Principal
equals method, which seems to follow (one of the versions of) the rules of the RFC.
dn
- to be compareddn2
- to be comparedpublic static String getReadableForm(String srcDn) throws IllegalArgumentException
Note: it may happen that output of this method won't be parseable by the X500Principal constructor.
srcDn
- to be outputIllegalArgumentException
- if the source DN can not be parsedpublic static String getReadableForm(X500Principal srcDn)
Note: it may happen that output of this method won't be parseable by the X500Principal constructor.
srcDn
- to be outputpublic static String getPortableRFC2253Form(String srcDn)
srcDn
- to be reformattedpublic static String getComparableForm(String srcDn)
srcDn
- input to be reformattedpublic static String[] getAttributeValues(String srcDn, ASN1ObjectIdentifier attribute) throws IllegalArgumentException
srcDn
- DN to be parsed in RFC 2253 formattribute
- to be retrieved. JavaAndBCStyle
class and its parent
contain useful constants.IllegalArgumentException
- if the provided DN can not be parsedpublic static String[] getAttributeValues(X500Principal srcDn, ASN1ObjectIdentifier attribute)
getAttributeValues(String, ASN1ObjectIdentifier)
for details.srcDn
- DN to be parsed in RFC 2253 formattribute
- to be retrieved JavaAndBCStyle
class and its parent contain
useful constants.public static Set<ASN1ObjectIdentifier> getAttributeNames(String srcDn)
srcDn
- DN to be examinedpublic static Set<ASN1ObjectIdentifier> getAttributeNames(X500Principal srcDn)
srcDn
- DN to be examinedpublic static X500Principal getX500Principal(String rfcDn) throws IOException
X500Principal
object from a RFC 2253 string. This
method can handle DNs with attributes not supported by the X500Principal
constructor.rfcDn
- RFC 2253 DNIOException
- IO exceptionCopyright © 2012-2017 European Middleware Initiative. All Rights Reserved.