Created
November 27, 2016 11:28
-
-
Save rajkrrsingh/acbc26b68ba9ba3c6ca791a8d8d30da6 to your computer and use it in GitHub Desktop.
Java Program to use JPam Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
account | |
auth | |
password | |
session | |
In this example I will demonstrate how to use Jpam in your java application. | |
1. Download the JPam from http://sourceforge.net/projects/jpam/files/ | |
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) { | |
authenticate(args[0],args[1],args[2]); | |
} | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to add JPam-1.1.jar in classpath ?