KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > jce > X509Principal


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.jce;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.io.ByteArrayOutputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.security.Principal JavaDoc;
24 import java.util.Hashtable JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import org.apache.geronimo.util.asn1.ASN1InputStream;
28 import org.apache.geronimo.util.asn1.ASN1Sequence;
29 import org.apache.geronimo.util.asn1.DEROutputStream;
30 import org.apache.geronimo.util.asn1.x509.X509Name;
31
32 public class X509Principal
33     extends X509Name
34     implements Principal JavaDoc
35 {
36     /**
37      * Constructor from an encoded byte array.
38      */

39     public X509Principal(
40         byte[] bytes)
41         throws IOException JavaDoc
42     {
43         super((ASN1Sequence)(new ASN1InputStream(new ByteArrayInputStream JavaDoc(bytes)).readObject()));
44     }
45
46     /**
47      * Constructor from an X509Name object.
48      */

49     public X509Principal(
50         X509Name name)
51     {
52         super((ASN1Sequence)name.getDERObject());
53     }
54
55     /**
56      * constructor from a table of attributes.
57      * <p>
58      * it's is assumed the table contains OID/String pairs.
59      */

60     public X509Principal(
61         Hashtable JavaDoc attributes)
62     {
63         super(attributes);
64     }
65
66     /**
67      * constructor from a table of attributes and a vector giving the
68      * specific ordering required for encoding or conversion to a string.
69      * <p>
70      * it's is assumed the table contains OID/String pairs.
71      */

72     public X509Principal(
73         Vector JavaDoc ordering,
74         Hashtable JavaDoc attributes)
75     {
76         super(ordering, attributes);
77     }
78
79     /**
80      * constructor from a vector of attribute values and a vector of OIDs.
81      */

82     public X509Principal(
83         Vector JavaDoc oids,
84         Vector JavaDoc values)
85     {
86         super(oids, values);
87     }
88
89     /**
90      * takes an X509 dir name as a string of the format "C=AU,ST=Victoria", or
91      * some such, converting it into an ordered set of name attributes.
92      */

93     public X509Principal(
94         String JavaDoc dirName)
95     {
96         super(dirName);
97     }
98
99     /**
100      * Takes an X509 dir name as a string of the format "C=AU,ST=Victoria", or
101      * some such, converting it into an ordered set of name attributes. If reverse
102      * is false the dir name will be encoded in the order of the (name, value) pairs
103      * presented, otherwise the encoding will start with the last (name, value) pair
104      * and work back.
105      */

106     public X509Principal(
107         boolean reverse,
108         String JavaDoc dirName)
109     {
110         super(reverse, dirName);
111     }
112
113     /**
114      * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or
115      * some such, converting it into an ordered set of name attributes. lookUp
116      * should provide a table of lookups, indexed by lowercase only strings and
117      * yielding a DERObjectIdentifier, other than that OID. and numeric oids
118      * will be processed automatically.
119      * <p>
120      * If reverse is true, create the encoded version of the sequence starting
121      * from the last element in the string.
122      */

123     public X509Principal(
124         boolean reverse,
125         Hashtable JavaDoc lookUp,
126         String JavaDoc dirName)
127     {
128         super(reverse, lookUp, dirName);
129     }
130
131     public String JavaDoc getName()
132     {
133         return this.toString();
134     }
135
136     /**
137      * return a DER encoded byte array representing this object
138      */

139     public byte[] getEncoded()
140     {
141         ByteArrayOutputStream JavaDoc bOut = new ByteArrayOutputStream JavaDoc();
142         DEROutputStream dOut = new DEROutputStream(bOut);
143
144         try
145         {
146             dOut.writeObject(this);
147         }
148         catch (IOException JavaDoc e)
149         {
150             throw new RuntimeException JavaDoc(e.toString());
151         }
152
153         return bOut.toByteArray();
154     }
155 }
156
Popular Tags