KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > hardtoken > profiles > HardTokenProfile


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.core.model.hardtoken.profiles;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.ejbca.core.model.UpgradeableDataHashMap;
20
21
22 /**
23  * HardTokenProfile is a basic class that should be inherited by all types
24  * of hardtokenprofiles in the system.
25  *
26  * It used to customize the information generated on hard tokens when they are
27  * processed. This information could be PIN-type number of certificates,
28  * certificate profiles and so on.
29  *
30  * @version $Id: HardTokenProfile.java,v 1.1 2006/01/17 20:31:52 anatom Exp $
31  */

32 public abstract class HardTokenProfile extends UpgradeableDataHashMap implements Serializable JavaDoc, Cloneable JavaDoc {
33     // Default Values
34

35
36     public static final String JavaDoc TRUE = "true";
37     public static final String JavaDoc FALSE = "false";
38
39     public static final int PINTYPE_ASCII_NUMERIC = 1;
40     public static final int PINTYPE_UTF8 = 2;
41     public static final int PINTYPE_ISO9564_1 = 4;
42
43     // Protected Constants.
44
public static final String JavaDoc TYPE = "type";
45     
46     protected static final String JavaDoc NUMBEROFCOPIES = "numberofcopies";
47     protected static final String JavaDoc EREASABLETOKEN = "ereasabletoken";
48     protected static final String JavaDoc HARDTOKENPREFIX = "hardtokenprefix";
49     protected static final String JavaDoc PINTYPE = "pintype";
50     protected static final String JavaDoc MINIMUMPINLENGTH = "minimumpinlength";
51     protected static final String JavaDoc GENERATEIDENTICALPINFORCOPIES = "generateidenticalpinforcopies";
52     // Public Methods
53

54     /**
55      * Creates a new instance of CertificateProfile
56      */

57     public HardTokenProfile() {
58       setNumberOfCopies(1);
59       setEreasableToken(true);
60       setHardTokenSNPrefix("000000");
61       setGenerateIdenticalPINForCopies(true);
62     }
63
64     // Public Methods mostly used by PrimeCard
65
/**
66      * Number of Copies indicates how many card for the samt user that should be generated.
67      * Generally this means, the PIN and PUK codes and encryption keys are identical. This
68      * doesn't mean that the toekns are exact copies.
69      */

70     public int getNumberOfCopies(){return ((Integer JavaDoc)data.get(NUMBEROFCOPIES)).intValue();}
71
72     /**
73      * Indicates if the same pin code should be used for all copies of the token or if a
74      * new one should be generated.
75      */

76
77     public boolean getGenerateIdenticalPINForCopies(){return ((Boolean JavaDoc) data.get(GENERATEIDENTICALPINFORCOPIES)).booleanValue();}
78
79     /**
80      * Indicaties if the generaded token should be ereasable or not,
81      *
82      * @return true if the card should be ereasable
83      */

84     public boolean getEreasableToken(){ return ((Boolean JavaDoc)data.get(EREASABLETOKEN)).booleanValue(); }
85     
86     /**
87      * Returns the hardtoken serialnumber prefix that is intended to identify the organization
88      * issuing the cards.
89      *
90      * @return the serial number prefix.
91      */

92     
93     public String JavaDoc getHardTokenSNPrefix(){ return (String JavaDoc) data.get(HARDTOKENPREFIX); }
94     
95
96
97     /**
98      * Given a token identification string the method determines if the token
99      * supports the structure of this profile.
100      *
101      * @return true if it's possible to create a token accoringly to the profile.
102      */

103     public abstract boolean isTokenSupported(String JavaDoc tokenidentificationstring);
104     // Public Methods mostly used by EJBCA
105

106     public void setNumberOfCopies(int numberofcopies) { data.put(NUMBEROFCOPIES,new Integer JavaDoc(numberofcopies));}
107
108     public void setEreasableToken(boolean ereasabletoken) {data.put(EREASABLETOKEN, Boolean.valueOf(ereasabletoken));}
109     
110     public void setHardTokenSNPrefix(String JavaDoc hardtokensnprefix){ data.put(HARDTOKENPREFIX,hardtokensnprefix); }
111     
112     public void setGenerateIdenticalPINForCopies(boolean generate){ data.put(GENERATEIDENTICALPINFORCOPIES, Boolean.valueOf(generate));}
113     
114     /**
115      * Retrieves what type of pin code that should be generated for
116      * tokens with this profile.
117      *
118      * @param certusage the should be one of the CERTUSAGE_ constants.
119      * @return a pintype with a value of one of the PINTYPE_ constants
120      */

121     public int getPINType(int certusage){
122       return ((Integer JavaDoc) ((List JavaDoc) data.get(PINTYPE)).get(certusage)).intValue();
123     }
124     
125     public void setPINType(int certusage, int pintype){
126         ((List JavaDoc) data.get(PINTYPE)).set(certusage, new Integer JavaDoc(pintype));
127     }
128     
129     /**
130      * Retrieves the minimum pin length that should be generated for
131      * tokens with this profile.
132      *
133      * @param certusage the should be one of the CERTUSAGE_ constants.
134      * @return a length of chars between 0 - 8.
135      */

136     public int getMinimumPINLength(int certusage){
137       return ((Integer JavaDoc) ((List JavaDoc) data.get(MINIMUMPINLENGTH)).get(certusage)).intValue();
138     }
139     
140     public void setMinimumPINLength(int certusage, int length){
141         ((List JavaDoc) data.get(MINIMUMPINLENGTH)).set(certusage, new Integer JavaDoc(length));
142     }
143
144     public abstract Object JavaDoc clone() throws CloneNotSupportedException JavaDoc;
145
146     
147     public abstract float getLatestVersion();
148
149     
150     public void upgrade(){
151         // Performing upgrade rutines
152
}
153     
154     // Protected methods
155
protected boolean isTokenSupported(String JavaDoc[] supportedtokens, String JavaDoc tokenidentificationstring){
156       boolean returnval = false;
157       for(int i=0; i<supportedtokens.length; i++){
158         if(supportedtokens[i].equals(tokenidentificationstring))
159           returnval=true;
160       }
161       
162       return returnval;
163     }
164     
165
166
167 }
168
Popular Tags