當前位置: 首頁>>代碼示例>>Java>>正文


Java X500Principal.getName方法代碼示例

本文整理匯總了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"));
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:CertificateUtilTest.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:22,代碼來源:CertificateUtilTest.java

示例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) + "'");
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:NameFormat.java

示例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));
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:EscapedChars.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:DistinguishedNameParser.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:DistinguishedNameParser.java

示例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());
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:38,代碼來源:CertificateUtilTest.java

示例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;
}
 
開發者ID:akashdeepsingh9988,項目名稱:Cybernet-VPN,代碼行數:33,代碼來源:X509Utils.java

示例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);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:InternalX500DNHandler.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:P11KeyStore.java

示例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++;
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:RFC4514.java

示例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();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:34,代碼來源:PolicyFile.java

示例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;
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:65,代碼來源:X509ServletFilterBase.java

示例14: DistinguishedNameParser

import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public DistinguishedNameParser(X500Principal principal) {
    this.dn = principal.getName("RFC2253");
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:4,代碼來源:DistinguishedNameParser.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:39,代碼來源:TrustAnchor.java


注:本文中的javax.security.auth.x500.X500Principal.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。