Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why Hit "No Token Present" error even the USB token has been inserted?

843811Jun 14 2009 — edited Jun 15 2009
Hi,

I am totally new to programming with cryptographic token.
When i try to login my secure token after inserted it into the USB port, my program throws "No Token Present" error.
I confirmed that the USB token is inserted properly because i can login the token with the Token Admin app installed on my system.
I have also installed the Provider successfully dynamically in my code.

Can anyone give me some idea or solution?
Thanks very much.

I program based on JDK 6 update 7 on Windows XP SP2 and the USB Secure Token (ST 2) is from SecureMetrics.
The error message is as shown as below:


Please kindly help to take a look at my code.
Use Provider: SunPKCS11-FeitianPKCS
Version: 1.600000
Info: SunPKCS11-FeitianPKCS using library D:\Develop\JavaPKCS11\ST2pkcs11v10.dll
Services: 0
{color:#999999}{color:#ff0000}javax.security.auth.login.LoginException: No token{color}{color}{color:#ff0000} present{color}{color:#ff0000}
{color}at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1044)
// Main code
String configName = "D:\\Develop\\JavaPKCS11\\pkcs11.cfg";
Provider p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);

Provider[] ps = Security.getProviders();

System.out.printf("Total providers %d\n\n", ps.length);

for (int i=0; i<ps.length;i++) {
System.out.printf("Provider[%d]: %s\n",i, ps.getName());
}

//Create the provider we defined
Provider p = Security.getProvider("SunPKCS11-FeitianPKCS");
System.out.printf("\nUse Provider: %s\n", p.getName());
System.out.printf("Version: %f\n", p.getVersion());
System.out.printf("Info: %s\n", p.getInfo());

//List all the services it supports
System.out.printf("Services: %d\n", p.getServices().size());
Set ss = p.getServices();
Iterator ii = ss.iterator();
Service s;
while (ii.hasNext()) {
s = (Service) ii.next();
System.out.printf("Service: %s - %s - %s \n", s.getType(), s.getAlgorithm(), s.getClassName());
}
try {
MyGuiCallbackHandler mcb = new MyGuiCallbackHandler();
Subject token = new Subject();
AuthProvider aprov = (AuthProvider) p;

//Login the token
aprov.login(token, mcb);
..............

Config:
name = FeitianPKCS#11
library = D:\Develop\JavaPKCS11\ST2pkcs11v10.dll
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2009
Added on Jun 14 2009
8 comments
944 views