jdk/src/share/classes/sun/security/x509/X500Name.java
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
child 10355 a976ff46116b
child 10370 5db0cf452a50
equal deleted inserted replaced
10335:3c7eda3ab2f5 10336:0bb1999251f8
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    25 
    25 
    26 package sun.security.x509;
    26 package sun.security.x509;
    27 
    27 
    28 import java.lang.reflect.*;
    28 import java.lang.reflect.*;
    29 import java.io.IOException;
    29 import java.io.IOException;
    30 import java.io.StringReader;
       
    31 import java.security.PrivilegedExceptionAction;
    30 import java.security.PrivilegedExceptionAction;
    32 import java.security.AccessController;
    31 import java.security.AccessController;
    33 import java.security.Principal;
    32 import java.security.Principal;
    34 import java.util.*;
    33 import java.util.*;
    35 
    34 
    36 import sun.security.util.*;
    35 import sun.security.util.*;
    37 import sun.security.pkcs.PKCS9Attribute;
       
    38 import javax.security.auth.x500.X500Principal;
    36 import javax.security.auth.x500.X500Principal;
    39 
    37 
    40 /**
    38 /**
    41  * Note:  As of 1.4, the public class,
    39  * Note:  As of 1.4, the public class,
    42  * javax.security.auth.x500.X500Principal,
    40  * javax.security.auth.x500.X500Principal,
  1369     }
  1367     }
  1370 
  1368 
  1371     /**
  1369     /**
  1372      * Constructor object for use by asX500Principal().
  1370      * Constructor object for use by asX500Principal().
  1373      */
  1371      */
  1374     private static final Constructor principalConstructor;
  1372     private static final Constructor<X500Principal> principalConstructor;
  1375 
  1373 
  1376     /**
  1374     /**
  1377      * Field object for use by asX500Name().
  1375      * Field object for use by asX500Name().
  1378      */
  1376      */
  1379     private static final Field principalField;
  1377     private static final Field principalField;
  1384      */
  1382      */
  1385     static {
  1383     static {
  1386         PrivilegedExceptionAction<Object[]> pa =
  1384         PrivilegedExceptionAction<Object[]> pa =
  1387                 new PrivilegedExceptionAction<Object[]>() {
  1385                 new PrivilegedExceptionAction<Object[]>() {
  1388             public Object[] run() throws Exception {
  1386             public Object[] run() throws Exception {
  1389                 Class pClass = X500Principal.class;
  1387                 Class<X500Principal> pClass = X500Principal.class;
  1390                 Class[] args = new Class[] {X500Name.class};
  1388                 Class<?>[] args = new Class<?>[] { X500Name.class };
  1391                 Constructor cons = ((Class<?>)pClass).getDeclaredConstructor(args);
  1389                 Constructor<X500Principal> cons = pClass.getDeclaredConstructor(args);
  1392                 cons.setAccessible(true);
  1390                 cons.setAccessible(true);
  1393                 Field field = pClass.getDeclaredField("thisX500Name");
  1391                 Field field = pClass.getDeclaredField("thisX500Name");
  1394                 field.setAccessible(true);
  1392                 field.setAccessible(true);
  1395                 return new Object[] {cons, field};
  1393                 return new Object[] {cons, field};
  1396             }
  1394             }
  1397         };
  1395         };
  1398         try {
  1396         try {
  1399             Object[] result = AccessController.doPrivileged(pa);
  1397             Object[] result = AccessController.doPrivileged(pa);
  1400             principalConstructor = (Constructor)result[0];
  1398             @SuppressWarnings("unchecked")
       
  1399             Constructor<X500Principal> constr =
       
  1400                     (Constructor<X500Principal>)result[0];
       
  1401             principalConstructor = constr;
  1401             principalField = (Field)result[1];
  1402             principalField = (Field)result[1];
  1402         } catch (Exception e) {
  1403         } catch (Exception e) {
  1403             throw (InternalError)new InternalError("Could not obtain "
  1404             throw (InternalError)new InternalError("Could not obtain "
  1404                 + "X500Principal access").initCause(e);
  1405                 + "X500Principal access").initCause(e);
  1405         }
  1406         }
  1413      */
  1414      */
  1414     public X500Principal asX500Principal() {
  1415     public X500Principal asX500Principal() {
  1415         if (x500Principal == null) {
  1416         if (x500Principal == null) {
  1416             try {
  1417             try {
  1417                 Object[] args = new Object[] {this};
  1418                 Object[] args = new Object[] {this};
  1418                 x500Principal =
  1419                 x500Principal = principalConstructor.newInstance(args);
  1419                         (X500Principal)principalConstructor.newInstance(args);
       
  1420             } catch (Exception e) {
  1420             } catch (Exception e) {
  1421                 throw new RuntimeException("Unexpected exception", e);
  1421                 throw new RuntimeException("Unexpected exception", e);
  1422             }
  1422             }
  1423         }
  1423         }
  1424         return x500Principal;
  1424         return x500Principal;