Source Code Cross Referenced for TestHardTokenProfile.java in  » Authentication-Authorization » ejbca » se » anatom » ejbca » hardtoken » 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 » se.anatom.ejbca.hardtoken 
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 se.anatom.ejbca.hardtoken;
013:
014:        import java.util.Arrays;
015:
016:        import javax.naming.Context;
017:        import javax.naming.NamingException;
018:
019:        import junit.framework.TestCase;
020:
021:        import org.apache.log4j.Logger;
022:        import org.ejbca.core.ejb.hardtoken.IHardTokenSessionHome;
023:        import org.ejbca.core.ejb.hardtoken.IHardTokenSessionRemote;
024:        import org.ejbca.core.model.hardtoken.HardTokenProfileExistsException;
025:        import org.ejbca.core.model.hardtoken.profiles.EnhancedEIDProfile;
026:        import org.ejbca.core.model.hardtoken.profiles.HardTokenProfile;
027:        import org.ejbca.core.model.hardtoken.profiles.SwedishEIDProfile;
028:        import org.ejbca.core.model.hardtoken.profiles.TurkishEIDProfile;
029:        import org.ejbca.core.model.log.Admin;
030:        import org.ejbca.util.CertTools;
031:
032:        /**
033:         * Tests the hard token profile entity bean.
034:         *
035:         * @version $Id: TestHardTokenProfile.java,v 1.4 2006/11/14 08:42:08 anatom Exp $
036:         */
037:        public class TestHardTokenProfile extends TestCase {
038:            private static Logger log = Logger
039:                    .getLogger(TestHardTokenProfile.class);
040:            private IHardTokenSessionRemote cacheAdmin;
041:
042:            private static int SVGFILESIZE = 512 * 1024; // 1/2 Mega char
043:
044:            private static IHardTokenSessionHome cacheHome;
045:
046:            private static final Admin admin = new Admin(
047:                    Admin.TYPE_INTERNALUSER);
048:
049:            /**
050:             * Creates a new TestHardTokenProfile object.
051:             *
052:             * @param name name
053:             */
054:            public TestHardTokenProfile(String name) {
055:                super (name);
056:            }
057:
058:            protected void setUp() throws Exception {
059:
060:                log.debug(">setUp()");
061:                CertTools.installBCProvider();
062:
063:                if (cacheAdmin == null) {
064:                    if (cacheHome == null) {
065:                        Context jndiContext = getInitialContext();
066:                        Object obj1 = jndiContext.lookup("HardTokenSession");
067:                        cacheHome = (IHardTokenSessionHome) javax.rmi.PortableRemoteObject
068:                                .narrow(obj1, IHardTokenSessionHome.class);
069:
070:                    }
071:
072:                    cacheAdmin = cacheHome.create();
073:                }
074:
075:                log.debug("<setUp()");
076:            }
077:
078:            protected void tearDown() throws Exception {
079:            }
080:
081:            private Context getInitialContext() throws NamingException {
082:                log.debug(">getInitialContext");
083:
084:                Context ctx = new javax.naming.InitialContext();
085:                log.debug("<getInitialContext");
086:
087:                return ctx;
088:            }
089:
090:            /**
091:             * adds a profile to the database
092:             *
093:             * @throws Exception error
094:             */
095:            public void test01AddHardTokenProfile() throws Exception {
096:                log.debug(">test01AddHardTokenProfile()");
097:                boolean ret = false;
098:                try {
099:                    SwedishEIDProfile profile = new SwedishEIDProfile();
100:                    EnhancedEIDProfile profile2 = new EnhancedEIDProfile();
101:                    TurkishEIDProfile turprofile = new TurkishEIDProfile();
102:
103:                    String svgdata = createSVGData();
104:                    profile.setPINEnvelopeData(svgdata);
105:                    profile2.setIsKeyRecoverable(
106:                            EnhancedEIDProfile.CERTUSAGE_ENC, true);
107:
108:                    cacheAdmin.addHardTokenProfile(admin, "SWETEST", profile);
109:                    cacheAdmin.addHardTokenProfile(admin, "ENHTEST", profile2);
110:                    cacheAdmin
111:                            .addHardTokenProfile(admin, "TURTEST", turprofile);
112:
113:                    SwedishEIDProfile profile3 = (SwedishEIDProfile) cacheAdmin
114:                            .getHardTokenProfile(admin, "SWETEST");
115:                    EnhancedEIDProfile profile4 = (EnhancedEIDProfile) cacheAdmin
116:                            .getHardTokenProfile(admin, "ENHTEST");
117:                    TurkishEIDProfile turprofile2 = (TurkishEIDProfile) cacheAdmin
118:                            .getHardTokenProfile(admin, "TURTEST");
119:
120:                    String svgdata2 = profile3.getPINEnvelopeData();
121:
122:                    assertTrue("Saving SVG Data failed", svgdata
123:                            .equals(svgdata2));
124:                    assertTrue(
125:                            "Saving Hard Token Profile failed",
126:                            profile4
127:                                    .getIsKeyRecoverable(EnhancedEIDProfile.CERTUSAGE_ENC));
128:                    assertTrue("Saving Turkish Hard Token Profile failed",
129:                            (turprofile2 != null));
130:
131:                    ret = true;
132:                } catch (HardTokenProfileExistsException pee) {
133:                }
134:
135:                assertTrue("Creating Hard Token Profile failed", ret);
136:                log.debug("<test01AddHardTokenProfile()");
137:            }
138:
139:            /**
140:             * renames profile
141:             *
142:             * @throws Exception error
143:             */
144:            public void test02RenameHardTokenProfile() throws Exception {
145:                log.debug(">test02RenameHardTokenProfile()");
146:
147:                boolean ret = false;
148:                try {
149:                    cacheAdmin.renameHardTokenProfile(admin, "SWETEST",
150:                            "SWETEST2");
151:                    ret = true;
152:                } catch (HardTokenProfileExistsException pee) {
153:                }
154:                assertTrue("Renaming Hard Token Profile failed", ret);
155:
156:                log.debug("<test02RenameHardTokenProfile()");
157:            }
158:
159:            /**
160:             * clones profile
161:             *
162:             * @throws Exception error
163:             */
164:            public void test03CloneHardTokenProfile() throws Exception {
165:                log.debug(">test03CloneHardTokenProfile()");
166:
167:                boolean ret = false;
168:                try {
169:                    cacheAdmin.cloneHardTokenProfile(admin, "SWETEST2",
170:                            "SWETEST");
171:                    ret = true;
172:                } catch (HardTokenProfileExistsException pee) {
173:                }
174:                assertTrue("Cloning Hard Token Profile failed", ret);
175:
176:                log.debug("<test03CloneHardTokenProfile()");
177:            }
178:
179:            /**
180:             * edits profile
181:             *
182:             * @throws Exception error
183:             */
184:            public void test04EditHardTokenProfile() throws Exception {
185:                log.debug(">test04EditHardTokenProfile()");
186:
187:                boolean ret = false;
188:
189:                HardTokenProfile profile = cacheAdmin.getHardTokenProfile(
190:                        admin, "ENHTEST");
191:
192:                profile.setHardTokenSNPrefix("11111");
193:
194:                cacheAdmin.changeHardTokenProfile(admin, "ENHTEST", profile);
195:                ret = true;
196:
197:                assertTrue("Editing HardTokenProfile failed", ret);
198:
199:                log.debug("<test04EditHardTokenProfile()");
200:            }
201:
202:            /**
203:             * removes all profiles
204:             *
205:             * @throws Exception error
206:             */
207:            public void test05removeHardTokenProfiles() throws Exception {
208:                log.debug(">test05removeHardTokenProfiles()");
209:                boolean ret = false;
210:                try {
211:                    // Remove all except ENHTEST
212:                    cacheAdmin.removeHardTokenProfile(admin, "SWETEST");
213:                    cacheAdmin.removeHardTokenProfile(admin, "SWETEST2");
214:                    cacheAdmin.removeHardTokenProfile(admin, "ENHTEST");
215:                    cacheAdmin.removeHardTokenProfile(admin, "TURTEST");
216:                    ret = true;
217:                } catch (Exception pee) {
218:                }
219:                assertTrue("Removing Hard Token Profile failed", ret);
220:
221:                log.debug("<test05removeHardTokenProfiles()");
222:            }
223:
224:            private String createSVGData() {
225:                char[] chararray = new char[SVGFILESIZE];
226:                Arrays.fill(chararray, 'a');
227:
228:                return new String(chararray);
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.