GeeCON Prague 2014*
The moose likes Servlets and the fly likes Unix Authentication by using servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Unix Authentication by using servlet" Watch "Unix Authentication by using servlet" New topic
Author

Unix Authentication by using servlet

Ma Di
Greenhorn

Joined: Nov 28, 2000
Posts: 6
I'm working on a servlet which verify user's validity using their
unix account username/password. I wonder how to implement this task. The UNIX OS is SUN Solaris. I know the related UNIX commands are "ypmatch" and "crypt".
Is there anyone who has done similiar job? Could you privide piece of source code for me? I'm really appreciated for it.
Rgds,
madi
Mirko Froehlich
Ranch Hand

Joined: Aug 21, 2000
Posts: 114
I cannot send you any sample code, but I think I can help you with the general solution. You probably want to have an HTML (or JSP) page with a form, that posts the username and password to your servlet. The servlet then gets the username and password from the request, executes the appropriate Unix commands, and examines the results. If the authentication is successful, you could forward to a success page (or do whatever else you want to do), otherwise forward to an error page or back to the login page.
-Mirko
Ma Di
Greenhorn

Joined: Nov 28, 2000
Posts: 6
Thanks Mirko. I understand what you mean. It's exactly I want to
say but I meet hard problems when I implenment the solution. I'm
not very familiar with Java. For example,I need to call a C Library function crypt() in Java. The test code is as following:
import java.io.*;
class CryptTest {

private native String crypt(String pass, String salt);
public static void main(String[] args) {
CryptTest test = new CryptTest();
String pass = "melody";
String salt = "QE";
String entpass = test.crypt(pass,salt);

System.out.println("entpass is : "+entpass);
}
}
The compile is successful. When I run it, there's a "java.lang.UnsatisfiedLinkError". It means it can't find the crypt() C function. How can I do now?
Thanks for your answers.
Mirko Froehlich
Ranch Hand

Joined: Aug 21, 2000
Posts: 114
Unfortunately, I am not much of an expert on native methods - in fact, I have never used them. One thing I know is that you need to manually load the necessary library using the "System.loadLibrary" method. You should do this in a static block to ensure that the library is loaded immediately after the class is loaded and will be available when you need it. For example:
class CryptTest {
...
...
static {
System.loadLibrary("MyLibrary");
}
...
...
}
Replace "MyLibrary" with the appropriate library name, not sure what this is in your case (probably the standard C library).
An alternative, which I was referring to in my first post, would be to use Unix commands corresponding to the C functions (if they exist). You can use "Runtime.getRuntime().exec()" to execute a System command, which spawns a new process. You then need to wait until it has finished and look at the result.
Hope this helps.
-Mirko

Originally posted by Ma Di:
Thanks Mirko. I understand what you mean. It's exactly I want to
say but I meet hard problems when I implenment the solution. I'm
not very familiar with Java. For example,I need to call a C Library function crypt() in Java. The test code is as following:
import java.io.*;
class CryptTest {

private native String crypt(String pass, String salt);
public static void main(String[] args) {
CryptTest test = new CryptTest();
String pass = "melody";
String salt = "QE";
String entpass = test.crypt(pass,salt);

System.out.println("entpass is : "+entpass);
}
}
The compile is successful. When I run it, there's a "java.lang.UnsatisfiedLinkError". It means it can't find the crypt() C function. How can I do now?
Thanks for your answers.

Monir Mozumder
Greenhorn

Joined: Feb 19, 2003
Posts: 2
Hi Ma,
Could you solve the problem? I am also facing the same unix authentication issue.
Regards,
-Monir
 
GeeCON Prague 2014
 
subject: Unix Authentication by using servlet