Created
March 17, 2016 20:12
-
-
Save wjsl/08fc3963c33a6f826ab0 to your computer and use it in GitHub Desktop.
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
SampleClient { | |
com.sun.security.auth.module.Krb5LoginModule required | |
debug=true | |
useTicketCache=true | |
doNotPrompt=true | |
renewTGT=true | |
; | |
}; |
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
import com.sun.security.auth.callback.TextCallbackHandler; | |
import javax.security.auth.Subject; | |
import javax.security.auth.login.LoginContext; | |
import java.security.AccessController; | |
import java.security.PrivilegedAction; | |
/** | |
* Created by bill on 3/17/16. | |
*/ | |
public class krb { | |
public static void main(String[] args) throws Exception { | |
LoginContext lc = new LoginContext("SampleClient", new TextCallbackHandler()); | |
lc.login(); | |
Subject me = lc.getSubject(); | |
Subject.doAs(me, new PrivilegedAction<Void>() { | |
@Override | |
public Void run() { | |
Subject current = Subject.getSubject(AccessController.getContext()); | |
String name = current.getPrincipals().iterator().next().getName(); | |
System.out.println(String.format("Hello, it's me, %s!", name)); | |
return null; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javac krb.java
java -Djava.security.auth.login.config=jaas.conf krb
Sample output: