• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unix Authentication by using servlet

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ma,
Could you solve the problem? I am also facing the same unix authentication issue.
Regards,
-Monir
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic