本文整理匯總了Java中javax.security.auth.x500.X500Principal.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java X500Principal.getName方法的具體用法?Java X500Principal.getName怎麽用?Java X500Principal.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.security.auth.x500.X500Principal
的用法示例。
在下文中一共展示了X500Principal.getName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetCN
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
@Test
public void testGetCN(@Mocked X500Principal aX500Principal, @Mocked MyX509Certificate myX509Certificate) {
new Expectations() {
{
aX500Principal.getName();
result = "CN=Test1234";
myX509Certificate.getSubjectX500Principal();
result = aX500Principal;
}
};
MyX509Certificate xxmyX509Certificate = new MyX509Certificate();
Set<String> strExpect = CertificateUtil.getCN(xxmyX509Certificate);
Assert.assertEquals(true, strExpect.contains("Test1234"));
}
示例2: testGetCNException
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
@Test
public void testGetCNException(@Mocked X500Principal aX500Principal,
@Mocked MyX509Certificate myX509Certificate) {
new Expectations() {
{
aX500Principal.getName();
result = "NOCN=Test1234";
myX509Certificate.getSubjectX500Principal();
result = aX500Principal;
}
};
MyX509Certificate xxmyX509Certificate = new MyX509Certificate();
try {
Set<String> strExpect = CertificateUtil.getCN(xxmyX509Certificate);
Assert.assertEquals(strExpect.size(), 0);
} catch (IllegalArgumentException e) {
Assert.assertNotNull(null);
}
}
示例3: testName
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public static void testName(String in, String outFormat,
String expect, int n)
throws Exception {
X500Principal p = new X500Principal(in);
if (outFormat.equalsIgnoreCase("toString")) {
if (p.toString().equals(expect)) {
System.out.println("test " + n + " succeeded");
} else {
throw new SecurityException("test " + n + " failed:\n" +
"expected '" + expect + "'\n" +
"got '" + p.toString() + "'");
}
} else {
if (p.getName(outFormat).equals(expect)) {
System.out.println("test " + n + " succeeded");
} else {
throw new SecurityException("test " + n + " failed:\n" +
"expected '" + expect + "'\n" +
"got '" + p.getName(outFormat) + "'");
}
}
}
示例4: main
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String dn="CN=\\#user";
X500Principal xp = new X500Principal(dn);
System.out.println("RFC2253 DN is " +
xp.getName(X500Principal.RFC2253));
System.out.println("CANONICAL DN is is " +
xp.getName(X500Principal.CANONICAL));
String dn1 = xp.getName(X500Principal.CANONICAL);
if (!(dn1.substring(3,5).equals("\\#")))
throw new Exception("Leading # not escaped");
X500Principal xp1 = new X500Principal(dn1);
System.out.println("CANONICAL DN is " +
xp1.getName(X500Principal.CANONICAL));
}
示例5: DistinguishedNameParser
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public DistinguishedNameParser(X500Principal principal) {
// RFC2253 is used to ensure we get attributes in the reverse
// order of the underlying ASN.1 encoding, so that the most
// significant values of repeated attributes occur first.
this.dn = principal.getName(X500Principal.RFC2253);
this.length = this.dn.length();
}
示例6: DistinguishedNameParser
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
DistinguishedNameParser(X500Principal principal) {
// RFC2253 is used to ensure we get attributes in the reverse
// order of the underlying ASN.1 encoding, so that the most
// significant values of repeated attributes occur first.
this.dn = principal.getName(X500Principal.RFC2253);
this.length = this.dn.length();
}
示例7: testFindRootCAException
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
@Test
public void testFindRootCAException(@Mocked X500Principal aX500Principal1, @Mocked X500Principal aX500Principal2,
@Mocked MyX509Certificate myX509Certificate) {
new Expectations() {
{
aX500Principal1.getName();
result = "Huawei1";
}
{
aX500Principal2.getName();
result = "Huawei3";
}
{
myX509Certificate.getSubjectX500Principal();
result = aX500Principal1;
myX509Certificate.getIssuerX500Principal();
result = aX500Principal2;
}
};
MyX509Certificate myX509Certificate1 = new MyX509Certificate();
MyX509Certificate myX509Certificate2 = new MyX509Certificate();
MyX509Certificate[] xxmyX509Certificate = new MyX509Certificate[2];
xxmyX509Certificate[0] = myX509Certificate1;
xxmyX509Certificate[1] = myX509Certificate2;
try {
X509Certificate aX509Certificate = CertificateUtil.findOwner(xxmyX509Certificate);
Assert.assertNull(aX509Certificate);
} catch (IllegalArgumentException e) {
Assert.assertEquals("bad certificate chain: no root CA.", e.getMessage());
}
}
示例8: getCertificateFriendlyName
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public static String getCertificateFriendlyName(X509Certificate cert) {
X500Principal principal = cert.getSubjectX500Principal();
byte[] encodedSubject = principal.getEncoded();
String friendlyName = null;
/* Hack so we do not have to ship a whole Spongy/bouncycastle */
Exception exp = null;
try {
Class X509NameClass = Class.forName("com.android.org.bouncycastle.asn1.x509.X509Name");
Method getInstance = X509NameClass.getMethod("getInstance", Object.class);
Hashtable defaultSymbols = (Hashtable) X509NameClass.getField("DefaultSymbols").get(X509NameClass);
if (!defaultSymbols.containsKey("1.2.840.113549.1.9.1")) defaultSymbols.put("1.2.840.113549.1.9.1", "eMail");
Object subjectName = getInstance.invoke(X509NameClass, encodedSubject);
Method toString = X509NameClass.getMethod("toString", boolean.class, Hashtable.class);
friendlyName = (String) toString.invoke(subjectName, true, defaultSymbols);
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | NoSuchFieldException e) {
exp = e;
}
if (exp != null) VpnStatus.logException("Getting X509 Name from certificate", exp);
/* Fallback if the reflection method did not work */
if (friendlyName == null) friendlyName = principal.getName();
// Really evil hack to decode email address
// See: http://code.google.com/p/android/issues/detail?id=21531
String[] parts = friendlyName.split(",");
for (int i = 0; i < parts.length; i++) {
String part = parts[i];
if (part.startsWith("1.2.840.113549.1.9.1=#16")) {
parts[i] = "email=" + ia5decode(part.replace("1.2.840.113549.1.9.1=#16", ""));
}
}
friendlyName = TextUtils.join(",", parts);
return friendlyName;
}
示例9: getName
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
/** {@inheritDoc} */
public String getName(X500Principal principal, String format) {
if (principal == null) {
throw new NullPointerException("X500Principal may not be null");
}
return principal.getName(format);
}
示例10: getID
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
/**
* build [alias + issuer + serialNumber] string from a cert
*/
private String getID(String alias, X509Certificate cert) {
X500Principal issuer = cert.getIssuerX500Principal();
BigInteger serialNum = cert.getSerialNumber();
return alias +
ALIAS_SEP +
issuer.getName(X500Principal.CANONICAL) +
ALIAS_SEP +
serialNum.toString();
}
示例11: parse
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public void parse(String dnString) throws Exception {
System.out.println("Parsing " + dnString);
X500Principal dn = new X500Principal(dnString);
String dnString2 = dn.getName();
X500Principal dn2 = new X500Principal(dnString2);
if (dn.equals(dn2)) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
failed++;
}
}
示例12: getDN
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
private String getDN(String alias, KeyStore keystore) {
Certificate cert = null;
try {
cert = keystore.getCertificate(alias);
} catch (Exception e) {
if (debug != null) {
debug.println(" Error retrieving certificate for '" +
alias +
"': " +
e.toString());
}
return null;
}
if (cert == null || !(cert instanceof X509Certificate)) {
if (debug != null) {
debug.println(" -- No certificate for '" +
alias +
"' - ignoring entry");
}
return null;
} else {
X509Certificate x509Cert = (X509Certificate)cert;
// 4702543: X500 names with an EmailAddress
// were encoded incorrectly. create new
// X500Principal name with correct encoding
X500Principal p = new X500Principal
(x509Cert.getSubjectX500Principal().toString());
return p.getName();
}
}
示例13: validCert
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
private boolean validCert(X509Certificate[] certs)
{
/*
* If the cert is null then the it's not valid.
*/
if(certs == null)
{
return false;
}
/*
* Get the first certificate in the chain. The first certificate is the client certificate.
*/
X509Certificate cert = certs[0];
try
{
/*
* check the certificate has not expired.
*/
if(logger.isDebugEnabled())
{
logger.debug("Checking cert is valid");
}
cert.checkValidity();
}
catch (Exception e)
{
logger.error("Cert is invalid", e);
return false;
}
X500Principal x500Principal = cert.getSubjectX500Principal();
String name = x500Principal.getName();
/*
* Cert contains is an optional check
*/
if(this.certContains == null)
{
return true;
}
/*
* Check that the cert contains the specified value.
*/
if(name.contains(this.certContains))
{
if(logger.isDebugEnabled())
{
logger.debug("Cert: "+ name + " contains: "+ this.certContains);
}
return true;
}
else
{
logger.error("Cert: " + name + " does not contain: " + this.certContains);
return false;
}
}
示例14: DistinguishedNameParser
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public DistinguishedNameParser(X500Principal principal) {
this.dn = principal.getName("RFC2253");
}
示例15: TrustAnchor
import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
/**
* Creates an instance of {@code TrustAnchor} where the
* most-trusted CA is specified as an X500Principal and public key.
* Name constraints are an optional parameter, and are intended to be used
* as additional constraints when validating an X.509 certification path.
* <p>
* The name constraints are specified as a byte array. This byte array
* contains the DER encoded form of the name constraints, as they
* would appear in the NameConstraints structure defined in RFC 3280
* and X.509. The ASN.1 notation for this structure is supplied in the
* documentation for
* {@link #TrustAnchor(X509Certificate, byte[])
* TrustAnchor(X509Certificate trustedCert, byte[] nameConstraints) }.
* <p>
* Note that the name constraints byte array supplied here is cloned to
* protect against subsequent modifications.
*
* @param caPrincipal the name of the most-trusted CA as X500Principal
* @param pubKey the public key of the most-trusted CA
* @param nameConstraints a byte array containing the ASN.1 DER encoding of
* a NameConstraints extension to be used for checking name constraints.
* Only the value of the extension is included, not the OID or criticality
* flag. Specify {@code null} to omit the parameter.
* @throws NullPointerException if the specified {@code caPrincipal} or
* {@code pubKey} parameter is {@code null}
* @since 1.5
*/
public TrustAnchor(X500Principal caPrincipal, PublicKey pubKey,
byte[] nameConstraints) {
if ((caPrincipal == null) || (pubKey == null)) {
throw new NullPointerException();
}
this.trustedCert = null;
this.caPrincipal = caPrincipal;
this.caName = caPrincipal.getName();
this.pubKey = pubKey;
setNameConstraints(nameConstraints);
}