Source Code Cross Referenced for SecureID.java in  » J2EE » Sofia » com » salmonllc » secureid » 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 » J2EE » Sofia » com.salmonllc.secureid 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        // Copyright (C) 1999 - 2002, Salmon LLC
004:        //
005:        // This program is free software; you can redistribute it and/or
006:        // modify it under the terms of the GNU General Public License version 2
007:        // as published by the Free Software Foundation;
008:        // 
009:        // This program is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        // GNU General Public License for more details.
013:        // 
014:        // You should have received a copy of the GNU General Public License
015:        // along with this program; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:        // 
018:        // For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:        package com.salmonllc.secureid;
021:
022:        /////////////////////////
023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/secureid/SecureID.java $
024:        //$Author: Dan $ 
025:        //$Revision: 20 $ 
026:        //$Modtime: 6/11/03 4:28p $ 
027:        /////////////////////////
028:
029:        import java.io.*;
030:
031:        /**
032:         * This class is used to communicate with secureid server, requires sdClient.dll in Path & ACE Client S/W installed.
033:         */
034:        public class SecureID implements  Runnable {
035:
036:            public final static int ACM_OK = 0;
037:            public final static int ACM_ACCESS_DENIED = 1;
038:            public final static int ACM_NEXT_CODE_REQUIRED = 2;
039:            public final static int ACM_NEW_PIN_REQUIRED = 5;
040:            public final static int ACM_NEW_PIN_ACCEPTED = 6;
041:            public final static int ACM_NEW_PIN_REJECTED = 7;
042:            public final static int ACM_UNABLE_TO_INITIALIZE = 100;
043:            public final static int ACM_BUSY = 150;
044:            private static boolean _isLoaded = false;
045:            private String sResponse;
046:            private byte[] baSdClientStruct;
047:            private int acmRet;
048:            private int _action;
049:            private String _username, _password, _newpin, _nexttoken;
050:            private boolean bRetValue;
051:
052:            /**
053:             * Constructs a SecureID object for communication with SecureID Server.
054:             */
055:            public SecureID() {
056:                baSdClientStruct = new byte[getSDClientSize()];
057:            }
058:
059:            /**
060:             * Use this method to Authenticate a New Pin with SecureID Server
061:             * @param sNewPin A Users New Pin to be used with SecureID card.
062:             */
063:            public boolean authenticateNewPin(String sNewPin) throws Exception {
064:                _action = 2;
065:                _newpin = sNewPin;
066:                Thread t = new Thread(this );
067:                t.start();
068:                while (t.isAlive())
069:                    Thread.yield();
070:                return bRetValue;
071:            }
072:
073:            /**
074:             * Use this method to Authenticate a user with SecureID Server
075:             * @param sUserName A Users SecureID Username.
076:             * @param sPassCode Concatenation of a Users Pin & Passcode on a SecureID card.
077:             */
078:            public boolean authenticateNewUser(String sUserName,
079:                    String sPassCode) throws Exception {
080:                _action = 1;
081:                _username = sUserName;
082:                _password = sPassCode;
083:                Thread t = new Thread(this );
084:                t.start();
085:                while (t.isAlive())
086:                    Thread.yield();
087:                return bRetValue;
088:
089:            }
090:
091:            /**
092:             * Use this method to Authenticate Next Token with SecureID Server for Next Token mode.
093:             * @param sPassCode A Users Passcode on a SecureID card.
094:             */
095:            public boolean authenticateNextToken(String sPassCode)
096:                    throws Exception {
097:                _action = 3;
098:                _nexttoken = sPassCode;
099:                Thread t = new Thread(this );
100:                t.start();
101:                while (t.isAlive())
102:                    Thread.yield();
103:                return bRetValue;
104:            }
105:
106:            /**
107:             * Use this method to Authenticate a New Pin with SecureID Server
108:             * @param sNewPin A Users New Pin to be used with SecureID card.
109:             */
110:            private static synchronized boolean authorizeNewPin(SecureID sid,
111:                    String sNewPin) {
112:                boolean bRetValue = false;
113:                int acmRet = setNewPin(sNewPin, (byte) 0, sid
114:                        .getSDClientStructure());
115:                sid.setReturnCode(acmRet);
116:                switch (acmRet) {
117:                case ACM_NEW_PIN_ACCEPTED:
118:                    sid.setResponse("New Pin Accepted");
119:                    System.out.println(sid.getResponse());
120:                    bRetValue = true;
121:                    close();
122:                    break;
123:                case ACM_NEW_PIN_REJECTED:
124:                    sid.setResponse("New Pin Rejected");
125:                    System.out.println(sid.getResponse());
126:                    close();
127:                    break;
128:                }
129:                return bRetValue;
130:            }
131:
132:            /**
133:             * Use this method to Authenticate a user with SecureID Server
134:             * @param sUserName A Users SecureID Username.
135:             * @param sPassCode Concatenation of a Users Pin & Passcode on a SecureID card.
136:             */
137:            private static synchronized boolean authorizeNewUser(SecureID sid,
138:                    String sUserName, String sPassCode) {
139:                boolean bRetValue = false;
140:                int acmRet = -1;
141:                try {
142:                    System.err.println("WILL CALL THE NATIVES ");
143:                    acmRet = initSecureID(sid.getSDClientStructure());
144:                    System.err
145:                            .println("In SecureID.authenticateNewUser after initSecureID return code  ==== "
146:                                    + acmRet);
147:                } catch (Error err) {
148:                    System.err.println(err);
149:                    //throw (new Exception(err.toString()));
150:                }
151:                if (acmRet != ACM_OK) {
152:                    System.err
153:                            .println("Unable to Initialize Client/Server Communication. Returned "
154:                                    + acmRet);
155:                    sid.setReturnCode(acmRet);
156:                    return false;
157:                    //throw (new Exception("Unable to Initialize Client/Server Communication. Returned "+acmRet));
158:                }
159:
160:                acmRet = -1;
161:
162:                try {
163:                    System.err
164:                            .println("In SecureID.authenticateNewUser before checkSecureID");
165:                    acmRet = checkSecureID(sPassCode, sUserName, sid
166:                            .getSDClientStructure());
167:                    System.err
168:                            .println("In SecureID.authenticateNewUser after checkSecureID return code  ==== "
169:                                    + acmRet);
170:                } catch (Error err) {
171:                    System.out.println(err);
172:                }
173:                sid.setReturnCode(acmRet);
174:                switch (acmRet) {
175:                case ACM_OK:
176:                    sid.setResponse("User Authenticated");
177:                    System.out.println(sid.getResponse());
178:                    bRetValue = true;
179:                    close();
180:                    break;
181:                case ACM_ACCESS_DENIED:
182:                    sid.setResponse("User Denied");
183:                    System.out.println(sid.getResponse());
184:                    close();
185:                    break;
186:                case ACM_NEXT_CODE_REQUIRED:
187:                    sid.setResponse("User Requires New PassCode");
188:                    System.out.println(sid.getResponse());
189:                    break;
190:                case ACM_NEW_PIN_REQUIRED:
191:                    sid.setResponse("User Requires New Pin");
192:                    System.out.println(sid.getResponse());
193:                    break;
194:                default:
195:                    sid.setResponse("Unknown Response");
196:                    System.out.println(sid.getResponse());
197:                    close();
198:                    break;
199:                }
200:                return bRetValue;
201:            }
202:
203:            /**
204:             * Use this method to Authenticate Next Token with SecureID Server for Next Token mode.
205:             * @param sPassCode A Users Passcode on a SecureID card.
206:             */
207:            private static synchronized boolean authorizeNextToken(
208:                    SecureID sid, String sPassCode) {
209:                boolean bRetValue = false;
210:                int acmRet = -1;
211:                try {
212:                    acmRet = checkNextToken(sPassCode, sid
213:                            .getSDClientStructure());
214:                } catch (Error err) {
215:                    System.out.println(err);
216:                }
217:                sid.setReturnCode(acmRet);
218:                switch (acmRet) {
219:                case ACM_OK:
220:                    sid.setResponse("User Authenticated");
221:                    System.out.println(sid.getResponse());
222:                    bRetValue = true;
223:                    close();
224:                    break;
225:                case ACM_ACCESS_DENIED:
226:                    sid.setResponse("User Denied");
227:                    System.out.println(sid.getResponse());
228:                    close();
229:                    break;
230:                default:
231:                    sid.setResponse("Unknown Response");
232:                    System.out.println(sid.getResponse());
233:                    close();
234:                    break;
235:                }
236:                return bRetValue;
237:            }
238:
239:            private static native int checkNextToken(String nextcode,
240:                    byte[] sdclient);
241:
242:            private static native int checkSecureID(String passcode,
243:                    String username, byte[] sdclient);
244:
245:            /**
246:             * Use this method to end Communication with SecureID Server. Normally at end of Application.
247:             */
248:            private static native void close();
249:
250:            /**
251:             * This method will return the return code from the SecureID Server from executing the above methods.
252:             */
253:            public int getAcmReturnCode() {
254:                return acmRet;
255:            }
256:
257:            /**
258:             * This method will return the response of the above methods.
259:             */
260:            public String getResponse() {
261:                return sResponse;
262:            }
263:
264:            private static native int getSDClientSize();
265:
266:            private byte[] getSDClientStructure() {
267:                return baSdClientStruct;
268:            }
269:
270:            private static native void initialize();
271:
272:            private static native int initSecureID(byte[] sdclient);
273:
274:            /**
275:             * Returns whether the Secure ID dll is loaded or not.
276:             * @return boolean Indicates whether Secure ID dll is loaded.
277:             */
278:            public static boolean isLoaded() {
279:                return _isLoaded;
280:            }
281:
282:            /**
283:             * This method specifies the JNI Secure ID dll to use.
284:             * @param sLibrary The name of the dll to be loaded.
285:             */
286:            public static synchronized void loadJNILibrary(String sLibrary) {
287:                try {
288:                    System.err.println("Start to load the library");
289:                    System.loadLibrary(sLibrary);
290:                    initialize();
291:                    System.err.println("Library loaded");
292:                    _isLoaded = true;
293:                } catch (Error err) {
294:                    System.out.println(err);
295:                }
296:            }
297:
298:            /**
299:             * This is a main method for testing purposes. Recommended to leave in class.
300:             */
301:            public static void main(String args[]) {
302:                try {
303:                    SecureID.loadJNILibrary("sdClient");
304:                    SecureID sd = new SecureID();
305:                    SecureID sd2 = new SecureID();
306:                    String sResponse;
307:                    int acmRet = 999;
308:                    sd.authenticateNewUser(args[0], args[1]);
309:                    if (args.length > 3) {
310:                        if (args[2] != null && args[3] != null)
311:                            sd2.authenticateNewUser(args[2], args[3]);
312:                    }
313:                    acmRet = sd.getAcmReturnCode();
314:                    switch (acmRet) {
315:                    case SecureID.ACM_OK:
316:                        sResponse = "User Authenticated";
317:                        System.out.println(sResponse);
318:                        break;
319:                    case SecureID.ACM_ACCESS_DENIED:
320:                        sResponse = "User Denied";
321:                        System.out.println(sResponse);
322:                        break;
323:                    case SecureID.ACM_NEXT_CODE_REQUIRED:
324:                        sResponse = "User Requires New PassCode";
325:                        System.out.println(sResponse);
326:                        System.out.print("Enter New PassCode: ");
327:                        InputStreamReader isr = new InputStreamReader(System.in);
328:                        BufferedReader br = new BufferedReader(isr);
329:                        String sPassCode = br.readLine();
330:                        sd.authenticateNextToken(sPassCode);
331:                        acmRet = sd.getAcmReturnCode();
332:                        br.close();
333:                        isr.close();
334:                        break;
335:                    case SecureID.ACM_NEW_PIN_REQUIRED:
336:                        sResponse = "User Requires New Pin";
337:                        System.out.println(sResponse);
338:                        System.out.print("Enter New Pin: ");
339:                        isr = new InputStreamReader(System.in);
340:                        br = new BufferedReader(isr);
341:                        String sPin = br.readLine();
342:                        sd.authenticateNewPin(sPin);
343:                        acmRet = sd.getAcmReturnCode();
344:                        br.close();
345:                        isr.close();
346:                        break;
347:                    default:
348:                        sResponse = "Unknown Response " + acmRet;
349:                        System.out.println(sResponse);
350:                        break;
351:                    }
352:                    sResponse = "ACM Return Code " + acmRet;
353:                    System.out.println(sResponse);
354:                } catch (Exception e) {
355:                    System.out.println("Exception: " + e);
356:                } catch (Error err) {
357:                    System.out.println(err);
358:                }
359:
360:            }
361:
362:            public void run() {
363:                switch (_action) {
364:                case 1:
365:                    bRetValue = authorizeNewUser(this , _username, _password);
366:                    break;
367:                case 2:
368:                    bRetValue = authorizeNewPin(this , _newpin);
369:                    break;
370:                case 3:
371:                    bRetValue = authorizeNextToken(this , _nexttoken);
372:                    break;
373:                }
374:                System.err.println("Thread ended");
375:            }
376:
377:            private static native int setNewPin(String pin, byte canceled,
378:                    byte[] sdclient);
379:
380:            private void setResponse(String sResponse) {
381:                this .sResponse = sResponse;
382:            }
383:
384:            private void setReturnCode(int retCode) {
385:                acmRet = retCode;
386:            }
387:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.