Skip to content

Instantly share code, notes, and snippets.

@sembrestels
Last active October 14, 2015 12:56
Show Gist options
  • Save sembrestels/0c2abbb26cde71cabe6c to your computer and use it in GitHub Desktop.
Save sembrestels/0c2abbb26cde71cabe6c to your computer and use it in GitHub Desktop.
Simple JAAS Snippet

Simple JAAS Snippet

Execute using the following commands:

javac *.java
java -Djava.security.auth.login.config=jaas.config Simple
Simple { com.sun.security.auth.module.UnixLoginModule required; };
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
import javax.security.auth.login.LoginContext;
public class Simple {
public static void main (String[] args) {
LoginContext lc = null;
try {
lc = new LoginContext("Simple", new CallbackHandler() {
public void handle (Callback[] calbacks) {
}
});
lc.login();
Subject subject = lc.getSubject();
System.out.println("Logged in as " + subject.toString());
} catch (LoginException e) {
System.out.println("Impossible identify the user: " + e.getLocalizedMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment