• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unix Authentication by using servlet

 
Ma Di
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ma,
Could you solve the problem? I am also facing the same unix authentication issue.
Regards,
-Monir
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic