KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > V2AttributeCertificateInfoGenerator


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.asn1.x509;
19
20 import org.apache.geronimo.util.asn1.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
22 import org.apache.geronimo.util.asn1.DERInteger;
23 import org.apache.geronimo.util.asn1.DERObjectIdentifier;
24 import org.apache.geronimo.util.asn1.DERSequence;
25 import org.apache.geronimo.util.asn1.DERGeneralizedTime;
26 import org.apache.geronimo.util.asn1.DERBitString;
27 import org.apache.geronimo.util.asn1.DERSet;
28
29 /**
30  * Generator for Version 2 AttributeCertificateInfo
31  * <pre>
32  * AttributeCertificateInfo ::= SEQUENCE {
33  * version AttCertVersion -- version is v2,
34  * holder Holder,
35  * issuer AttCertIssuer,
36  * signature AlgorithmIdentifier,
37  * serialNumber CertificateSerialNumber,
38  * attrCertValidityPeriod AttCertValidityPeriod,
39  * attributes SEQUENCE OF Attribute,
40  * issuerUniqueID UniqueIdentifier OPTIONAL,
41  * extensions Extensions OPTIONAL
42  * }
43  * </pre>
44  *
45  */

46 public class V2AttributeCertificateInfoGenerator
47 {
48     private DERInteger version;
49     private Holder holder;
50     private AttCertIssuer issuer;
51     private AlgorithmIdentifier signature;
52     private DERInteger serialNumber;
53     private AttCertValidityPeriod attrCertValidityPeriod;
54     private ASN1EncodableVector attributes;
55     private DERBitString issuerUniqueID;
56     private X509Extensions extensions;
57     private DERGeneralizedTime startDate, endDate;
58
59     public V2AttributeCertificateInfoGenerator()
60     {
61         this.version = new DERInteger(1);
62         attributes = new ASN1EncodableVector();
63     }
64
65     public void setHolder(Holder holder)
66     {
67         this.holder = holder;
68     }
69
70     public void addAttribute(String JavaDoc oid, ASN1Encodable value)
71     {
72         attributes.add(new Attribute(new DERObjectIdentifier(oid), new DERSet(value)));
73     }
74
75     /**
76      * @param attribute
77      */

78     public void addAttribute(Attribute attribute)
79     {
80         attributes.add(attribute);
81     }
82
83     public void setSerialNumber(
84         DERInteger serialNumber)
85     {
86         this.serialNumber = serialNumber;
87     }
88
89     public void setSignature(
90         AlgorithmIdentifier signature)
91     {
92         this.signature = signature;
93     }
94
95     public void setIssuer(
96         AttCertIssuer issuer)
97     {
98         this.issuer = issuer;
99     }
100
101     public void setStartDate(
102         DERGeneralizedTime startDate)
103     {
104         this.startDate = startDate;
105     }
106
107     public void setEndDate(
108         DERGeneralizedTime endDate)
109     {
110         this.endDate = endDate;
111     }
112
113     public void setIssuerUniqueID(
114         DERBitString issuerUniqueID)
115     {
116         this.issuerUniqueID = issuerUniqueID;
117     }
118
119     public void setExtensions(
120         X509Extensions extensions)
121     {
122         this.extensions = extensions;
123     }
124
125     public AttributeCertificateInfo generateAttributeCertificateInfo()
126     {
127         if ((serialNumber == null) || (signature == null)
128             || (issuer == null) || (startDate == null) || (endDate == null)
129             || (holder == null) || (attributes == null))
130         {
131             throw new IllegalStateException JavaDoc("not all mandatory fields set in V2 AttributeCertificateInfo generator");
132         }
133
134         ASN1EncodableVector v = new ASN1EncodableVector();
135
136         v.add(version);
137         v.add(holder);
138         v.add(issuer);
139         v.add(signature);
140         v.add(serialNumber);
141
142         //
143
// before and after dates => AttCertValidityPeriod
144
//
145
AttCertValidityPeriod validity = new AttCertValidityPeriod(startDate, endDate);
146         v.add(validity);
147
148         // Attributes
149
v.add(new DERSequence(attributes));
150
151         if (issuerUniqueID != null)
152         {
153             v.add(issuerUniqueID);
154         }
155
156         if (extensions != null)
157         {
158             v.add(extensions);
159         }
160
161         return new AttributeCertificateInfo(new DERSequence(v));
162     }
163 }
164
Popular Tags