Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Java Program to use JPam Authentication
JPam is a Java-PAM bridge. PAM, or Pluggable Authentication Modules, is a standard security architecture used on Linux, Mac OS X, Solaris, HP-UX and other Unix systems. JPam is the missing link between the two.
JPAM permits the use of PAM authentication facilities by Java applications running on those platforms.
These facilities include:
In this example I will demonstrate how to use Jpam in your java application.
1. Download the JPam from
2. Extract the tar on the disk
3. change directory to the extracted folder and copy the net-sf-jpam file to the /etc/pam.d
4. Create a sample java program-make sure you have JPam-1.1.jar in the classpath
// sample program
import java.util.Arrays;
import java.util.Arrays;
import java.util.List;
import net.sf.jpam.Pam;
public class PamAuthenticator {
        public static void main(String[] args) {
        public static void authenticate(String user, String password,String profile)  {
              Pam pam = new Pam(profile);
              System.out.println("Starting auth with username "+user+" passwd "+password+" for profile "+profile);
              if (!pam.authenticateSuccessful(user, password)) {
                throw new RuntimeException(String.format("PAM profile '%s' validation failed", profile));
              System.out.println("done with "+profile);
compile and run the test class as follows
java -cp .:* -Djava.library.path=`pwd` PamAuthenticator root hadoop login
Copy link

Cmlsh commented Jun 27, 2018

how to add JPam-1.1.jar in classpath ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment