Source Code Cross Referenced for StandardFileHardTokenImporter.java in  » Authentication-Authorization » ejbca » org » ejbca » ui » cli » hardtoken » importer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Authentication Authorization » ejbca » org.ejbca.ui.cli.hardtoken.importer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*************************************************************************
002:         *                                                                       *
003:         *  EJBCA: The OpenSource Certificate Authority                          *
004:         *                                                                       *
005:         *  This software is free software; you can redistribute it and/or       *
006:         *  modify it under the terms of the GNU Lesser General Public           *
007:         *  License as published by the Free Software Foundation; either         *
008:         *  version 2.1 of the License, or any later version.                    *
009:         *                                                                       *
010:         *  See terms of license at gnu.org.                                     *
011:         *                                                                       *
012:         *************************************************************************/package org.ejbca.ui.cli.hardtoken.importer;
013:
014:        import java.io.IOException;
015:        import java.util.Date;
016:        import java.util.Properties;
017:
018:        import org.ejbca.core.model.SecConst;
019:        import org.ejbca.core.model.hardtoken.HardTokenData;
020:        import org.ejbca.core.model.hardtoken.types.EnhancedEIDHardToken;
021:        import org.ejbca.core.model.hardtoken.types.HardToken;
022:        import org.ejbca.core.model.hardtoken.types.SwedishEIDHardToken;
023:
024:        /**
025:         * The standard file hard token importer, reading the a textfile line by line.
026:         * 
027:         * The Importer have the following properties:
028:         * separator   : indicates which column separator that should be used.
029:         * 
030:         * columnorder : A list of columnnames separated by ',' of how the columns
031:         * are ordered. Valid values are 'tokensn', 'pin1', 'pin2', 'bothpin', 'puk1', 'puk2', 'bothpuk'
032:         * Example the line: 'columnorder=tokensn, pin1, pin2, bothpuk' will generate a
033:         * hardtokendata with the tokensn from first column, basicpin from the secondcolumn, 
034:         * signaturepin from third and finally both puk codes from the forth column.
035:         * 
036:         * tokentype : either 'enhancedeid' or 'swedisheid'. And inidcates what type of token that will be created.
037:         * 
038:         * 
039:         * @author Philip Vendil 2007 apr 23
040:         *
041:         * @version $Id: StandardFileHardTokenImporter.java,v 1.3 2007/05/07 11:58:55 herrvendil Exp $
042:         */
043:
044:        public class StandardFileHardTokenImporter extends
045:                FileReadHardTokenImporter {
046:
047:            public static final String PROPERTY_SEPARATOR = "separator";
048:            public static final String PROPERTY_COLUMNORDER = "columnorder";
049:            public static final String PROPERTY_TOKENTYPE = "tokentype";
050:
051:            private static final int COLUMN_TOKENSN = 1;
052:            private static final int COLUMN_PIN1 = 2;
053:            private static final int COLUMN_PIN2 = 3;
054:            private static final int COLUMN_BOTHPIN = 4;
055:            private static final int COLUMN_PUK1 = 5;
056:            private static final int COLUMN_PUK2 = 6;
057:            private static final int COLUMN_BOTHPUK = 7;
058:
059:            private String columnSeparator;
060:            private int[] columns = null;
061:            private String hardTokenType = null;
062:
063:            public void startImport(Properties props) throws IOException {
064:                super .startImport(props);
065:
066:                getColumns(props);
067:
068:                if (props.getProperty(PROPERTY_SEPARATOR) == null) {
069:                    throw new IOException("Error property "
070:                            + PROPERTY_SEPARATOR + " not set.");
071:                }
072:                columnSeparator = props.getProperty(PROPERTY_SEPARATOR);
073:
074:                if (props.getProperty(PROPERTY_TOKENTYPE) == null) {
075:                    throw new IOException("Error property "
076:                            + PROPERTY_TOKENTYPE + " not set.");
077:                }
078:                hardTokenType = props.getProperty(PROPERTY_TOKENTYPE);
079:                if (!hardTokenType.equalsIgnoreCase("enhancedeid")
080:                        && !hardTokenType.equalsIgnoreCase("swedisheid")) {
081:                    throw new IOException(
082:                            "Error property "
083:                                    + PROPERTY_TOKENTYPE
084:                                    + " must have either the value 'enhancedeid' or 'swedisheid'.");
085:                }
086:            }
087:
088:            private void getColumns(Properties props) throws IOException {
089:                if (props.getProperty("columnorder") == null) {
090:                    throw new IOException(
091:                            "Error the required property 'columnorder' isn't set.");
092:                }
093:
094:                String[] c = props.getProperty(PROPERTY_COLUMNORDER).split(",");
095:                columns = new int[c.length];
096:                for (int i = 0; i < c.length; i++) {
097:                    columns[i] = getColumn(c[i].trim());
098:                }
099:
100:            }
101:
102:            private int getColumn(String column) throws IOException {
103:                if (column.equalsIgnoreCase("tokensn")) {
104:                    return COLUMN_TOKENSN;
105:                }
106:                if (column.equalsIgnoreCase("pin1")) {
107:                    return COLUMN_PIN1;
108:                }
109:                if (column.equalsIgnoreCase("pin2")) {
110:                    return COLUMN_PIN2;
111:                }
112:                if (column.equalsIgnoreCase("bothpin")) {
113:                    return COLUMN_BOTHPIN;
114:                }
115:                if (column.equalsIgnoreCase("puk1")) {
116:                    return COLUMN_PUK1;
117:                }
118:                if (column.equalsIgnoreCase("puk2")) {
119:                    return COLUMN_PUK2;
120:                }
121:                if (column.equalsIgnoreCase("bothpuk")) {
122:                    return COLUMN_BOTHPUK;
123:                }
124:                throw new IOException("Error illegal column " + column
125:                        + " in the " + PROPERTY_COLUMNORDER + " property.");
126:            }
127:
128:            /**
129:             * @see org.ejbca.ui.cli.hardtoken.importer.FileReadHardTokenImporter#readHardTokenData()
130:             */
131:            public HardTokenData readHardTokenData() throws IOException {
132:                HardTokenData retval = null;
133:
134:                String line = bufferedReader.readLine();
135:                if (line != null) {
136:                    String basicPIN = "";
137:                    String signaturePIN = "";
138:                    String basicPUK = "";
139:                    String signaturePUK = "";
140:                    String tokenSN = "";
141:
142:                    String[] lineColumns = line.split(columnSeparator);
143:                    for (int i = 0; i < lineColumns.length; i++) {
144:                        lineColumns[i] = lineColumns[i].trim();
145:                        switch (columns[i]) {
146:                        case COLUMN_TOKENSN:
147:                            tokenSN = lineColumns[i];
148:                            break;
149:                        case COLUMN_PIN1:
150:                            basicPIN = lineColumns[i];
151:                            break;
152:                        case COLUMN_PIN2:
153:                            signaturePIN = lineColumns[i];
154:                            break;
155:                        case COLUMN_BOTHPIN:
156:                            basicPIN = lineColumns[i];
157:                            signaturePIN = lineColumns[i];
158:                            break;
159:                        case COLUMN_PUK1:
160:                            basicPUK = lineColumns[i];
161:                            break;
162:                        case COLUMN_PUK2:
163:                            signaturePUK = lineColumns[i];
164:                            break;
165:                        case COLUMN_BOTHPUK:
166:                            basicPUK = lineColumns[i];
167:                            signaturePUK = lineColumns[i];
168:                            break;
169:                        default:
170:                            throw new IOException("Error reading column + " + i
171:                                    + " of hard token import data.");
172:                        }
173:                    }
174:                    int tokenType = SecConst.TOKEN_SWEDISHEID;
175:                    if (hardTokenType.equalsIgnoreCase("enhancedeid")) {
176:                        tokenType = SecConst.TOKEN_ENHANCEDEID;
177:                    }
178:                    HardToken ht = getHardTokenType(basicPIN, basicPUK,
179:                            signaturePIN, signaturePUK);
180:                    retval = new HardTokenData(tokenSN, null, new Date(),
181:                            new Date(), tokenType, null, ht, null, null);
182:                }
183:
184:                return retval;
185:            }
186:
187:            private HardToken getHardTokenType(String basicPIN,
188:                    String basicPUK, String signaturePIN, String signaturePUK) {
189:                if (hardTokenType.equalsIgnoreCase("enhancedeid")) {
190:                    return new EnhancedEIDHardToken(signaturePIN, signaturePUK,
191:                            basicPIN, basicPUK, false, 0);
192:                }
193:                return new SwedishEIDHardToken(basicPIN, basicPUK,
194:                        signaturePIN, signaturePUK, 0);
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.