{"id":6716,"date":"2012-11-13T14:12:58","date_gmt":"2012-11-13T19:12:58","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=6716"},"modified":"2013-07-28T14:11:23","modified_gmt":"2013-07-28T19:11:23","slug":"javase-6-http-authentication","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=6716","title":{"rendered":"Windows Kerberos Authentication with java.net.Authenticator"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Overview\">Overview<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Http_Authentication\">Http Authentication<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#java.net.Authenticator\">java.net.Authenticator<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Authentication_Schemes\">Authentication Schemes<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Http_Basic\">Http Basic<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Http_Digest\">Http Digest<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#NTLM\">NTLM<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#SPNEGO\">SPNEGO<\/a>\n\t\t\t\t<ol class='toc-odd level-3'>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Kerberos_5_Configuration\">Kerberos 5 Configuration<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t<\/ol>\n<\/ol>\n\t\t\t<li>\n\t\t\t\t<a href=\"#IIS_Kerberos_Only_Authentication_Example\">IIS Kerberos Only Authentication Example<\/a>\n\t\t\t\t<ol class='toc-even level-2'>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Domain_Controller\">Domain Controller<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#IIS_Server\">IIS Server<\/a>\n\t\t\t\t\t\t<ol class='toc-odd level-3'>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<a href=\"#Configure_IIS\">Configure IIS<\/a>\n\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<a href=\"#Setup_SPN_for_IIS_HTTP\">Setup SPN for IIS HTTP<\/a>\n\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t<\/ol>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Client_Machine\">Client Machine<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Java_App:_RunHttpSpnego.java\">Java App: RunHttpSpnego.java<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Kerberos_config:_krb5.conf\">Kerberos config: krb5.conf<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#JAAS_Config:_login.conf\">JAAS Config: login.conf<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Compile_and_run:\">Compile and run:<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t<\/ol>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Caveats\">Caveats<\/a>\n\t\t\t\t<ol class='toc-even level-2'>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Windows_2008_Domain_Controller\">Windows 2008 Domain Controller<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t<\/ol>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Tools\">Tools<\/a>\n\t\t\t\t<ol class='toc-even level-2'>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Windows_klist.exe\">Windows <em>klist.exe<\/em><\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#MIT_Kerberos_for_Windows\">MIT Kerberos for Windows<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<a href=\"#Sync_Time_with_Windows_Server\">Sync Time with Windows Server<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t<\/ol>\n\t\t\t<li>\n\t\t\t\t<a href=\"#References\">References<\/a>\n\t\t\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"Overview\"><h2>Overview<\/h2><\/span>\n<span id=\"Http_Authentication\"><h3>Http Authentication<\/h3><\/span>\n<p>* Java SE supports:<br \/>\n&#8211; HTTP Basic authentication<br \/>\n&#8211; HTTP Digest authentication<br \/>\n&#8211; NTLM<br \/>\n&#8211; Http SPNEGO Negotiate with Kerberos and NTLM<br \/>\n* Uses java.net.Authenticator to<br \/>\n&#8211; enable authentication<br \/>\n&#8211; provide access to a store of usernames and passwords<br \/>\n* Work with both proxies and servers<\/p>\n<span id=\"java.net.Authenticator\"><h3>java.net.Authenticator<\/h3><\/span>\n<p>* Is an abstract class.<br \/>\n* Represents an object that knows how to obtain authentication for a network connection, usually by prompting user for information.<\/p>\n<span id=\"\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_classDiagram.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_classDiagram-300x225.jpg\" alt=\"\" title=\"JavaNetAuthenticator_classDiagram\" width=\"300\" height=\"225\" class=\"aligncenter size-medium wp-image-6726\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_classDiagram-300x225.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_classDiagram.jpg 841w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Subclasses override<br \/>\n&#8211; <em>getPasswordAuthentication()<\/em> to acquire username and password.<br \/>\n&#8211; <em>setDefault(Authenticator)<\/em> to register with the system and <strong>enable<\/strong> autehntication.<br \/>\n* Example:<\/p>\n<pre lang=\"java\">\r\n    class MyAuthenticator extends Authenticator {\r\n\r\n        public PasswordAuthentication getPasswordAuthentication () {\r\n            return new PasswordAuthentication (\"user\", \"pass1\".toCharArray());\r\n        }\r\n    }\r\n<\/pre>\n<p>* Another example: <a href=\"http:\/\/nextmidas.techma.com\/nm\/nxm\/sys\/net\/HttpAuthenticator.java\">http:\/\/nextmidas.techma.com\/nm\/nxm\/sys\/net\/HttpAuthenticator.java<\/a><br \/>\n* Choose witch authentication scheme is used:<br \/>\n&#8211; By default, the implementation chosses the most secure protocol transparently.<br \/>\n&#8211; Can be overridden with <em>-Dhttp.auth.preference=&#8221;scheme&#8221;<\/em> system property.<\/p>\n<span id=\"Authentication_Schemes\"><h2>Authentication Schemes<\/h2><\/span>\n<p>* Scheme preference: <em>GSS\/SPNEGO -> Digest -> NTLM -> Basic<\/em><br \/>\n* Specify no fallback with system proprety: <em>http.auth.preference<\/em><\/p>\n<span id=\"Http_Basic\"><h3>Http Basic<\/h3><\/span>\n<p>* Not secure<br \/>\n* Defined in RFC 2317<br \/>\n* Username and password are encoded in base64<br \/>\n* <em>getRequestingPrompt()<\/em> returns the basic authentication realm as provided by the server<\/p>\n<span id=\"Http_Digest\"><h3>Http Digest<\/h3><\/span>\n<p>* More secure than Basic.<br \/>\n* Username and password are hashed with MD5<br \/>\n* Turn on mutual authentication:<\/p>\n<pre lang=\"bash\">\r\n  -Dhttp.auth.digest.validateServer=\"true\"\r\n  -Dhttp.auth.digest.validateProxy=\"true\"\r\n<\/pre>\n<span id=\"NTLM\"><h3>NTLM<\/h3><\/span>\n<p>* More secure than Basic, but less secure than Digest.<br \/>\n* Can be used with proxies or servers, but <strong>not<\/strong> both at the same time.<br \/>\n* Specify domain name:<br \/>\n&#8211; Prefix username with domain name followed by a backslash: <em>domainName\\username<\/em><br \/>\n&#8211; Use system property: <em>http.auth.ntlm.domain<\/em><\/p>\n<span id=\"SPNEGO\"><h3>SPNEGO<\/h3><\/span>\n<p>* Negotiate scheme<br \/>\n* Only supports<br \/>\n&#8211; NTLM<br \/>\n&#8211; Kerberos<\/p>\n<span id=\"Kerberos_5_Configuration\"><h4>Kerberos 5 Configuration<\/h4><\/span>\n<p>* Use <em>java.security.krb5.conf<\/em> system property to point to Kerberos 5 configurations<\/p>\n<pre lang=\"java\">\r\njava -Djava.security.krb5.conf=krb5.conf ...\r\n<\/pre>\n<p>or programmatically:<\/p>\n<pre lang=\"java\">\r\nSystem.setProperty(\"java.security.krb5.conf\", \"kbr5.conf\");\r\n<\/pre>\n<p>* Use <em>com.sun.security.jgss.krb5.initiate<\/em> entry in JAAS login config file to config which login moduel to use:<\/p>\n<pre lang=\"java\">\r\n  com.sun.security.jgss.krb5.initiate {\r\n      com.sun.security.auth.module.Krb5LoginModule\r\n      ...\r\n  };\r\n<\/pre>\n<span id=\"IIS_Kerberos_Only_Authentication_Example\"><h2>IIS Kerberos Only Authentication Example<\/h2><\/span>\n<span id=\"Domain_Controller\"><h3>Domain Controller<\/h3><\/span>\n<p>* Windows 2003 SP1 Enterprise Server<br \/>\n&#8211; Computer name: <em>DC01<\/em><br \/>\n&#8211; AD Domain name: <em>MYTEST.local<\/em><br \/>\n&#8211; NetBIOS domain name: <em>MYTEST<\/em><br \/>\n* Admin User:<br \/>\n&#8211; Administrator\/Welcome1<br \/>\n* Client user domain name:<br \/>\n&#8211; <em>Jimmy.Li@MYTEST.local<\/em>\/Password1<\/p>\n<span id=\"_1\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_jimmy_1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_jimmy_1-300x249.jpg\" alt=\"\" title=\"dc01_mytest_local_newuser_jimmy_1\" width=\"300\" height=\"249\" class=\"aligncenter size-medium wp-image-6799\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_jimmy_1-300x249.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_jimmy_1.jpg 437w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Application domain name (under which IIS runs as):<br \/>\n&#8211; <em>App.Service@MYTEST.local<\/em>\/Password1<\/p>\n<span id=\"_2\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_app.service_1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_app.service_1-300x250.jpg\" alt=\"\" title=\"dc01_mytest_local_newuser_app.service_1\" width=\"300\" height=\"250\" class=\"aligncenter size-medium wp-image-6798\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_app.service_1-300x250.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/dc01_mytest_local_newuser_app.service_1.jpg 437w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<span id=\"IIS_Server\"><h3>IIS Server<\/h3><\/span>\n<p>* Windows 7<br \/>\n&#8211; Computer name: <em>WIN7X64NOV3<\/em><br \/>\n* Local User:<br \/>\n&#8211; <em>Jimmy<\/em>\/Password1<br \/>\n* Login as domain User (otherwise cannot start IIS?):<br \/>\n&#8211; <em>Administrator<\/em>\/Welcome1<br \/>\n* IIS run as service account:<br \/>\n&#8211; <em>App.Service@MYTEST.local<\/em>\/Password1<\/p>\n<span id=\"Configure_IIS\"><h4>Configure IIS<\/h4><\/span>\n<p>* Install IIS for Win 7:<\/p>\n<span id=\"_3\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_Install_IIS_1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_Install_IIS_1-269x300.jpg\" alt=\"\" title=\"JavaNetAuthenticator_Install_IIS_1\" width=\"269\" height=\"300\" class=\"aligncenter size-medium wp-image-6733\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_Install_IIS_1-269x300.jpg 269w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_Install_IIS_1.jpg 484w\" sizes=\"auto, (max-width: 269px) 100vw, 269px\" \/><\/a><\/h6><\/span>\n<p>* Enable Kerberos only authentication:<\/p>\n<span id=\"_4\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_EnableWinAuth_1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_EnableWinAuth_1-300x221.jpg\" alt=\"\" title=\"JavaNetAuthenticator_IIS_EnableWinAuth_1\" width=\"300\" height=\"221\" class=\"aligncenter size-medium wp-image-6764\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_EnableWinAuth_1-300x221.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_EnableWinAuth_1.jpg 665w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Run IIS DefaultAppPool as an application user, e.g. <em>App.Service<\/em><\/p>\n<span id=\"_5\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_PoolRunAs_1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_PoolRunAs_1-300x89.jpg\" alt=\"\" title=\"JavaNetAuthenticator_IIS_PoolRunAs_1\" width=\"300\" height=\"89\" class=\"aligncenter size-medium wp-image-6774\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_PoolRunAs_1-300x89.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/11\/JavaNetAuthenticator_IIS_PoolRunAs_1.jpg 888w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<span id=\"Setup_SPN_for_IIS_HTTP\"><h4>Setup SPN for IIS HTTP<\/h4><\/span>\n<p>* Login domain controller.<br \/>\n* Issue <em>setspn<\/em> commands:<\/p>\n<pre lang=\"bash\">\r\n# Add\r\nsetspn -A HTTP\/win7x64nov3 MYTEST\\App.Service\r\nsetspn -A HTTP\/win7x64nov3.mytest.local MYTEST\\App.Service\r\n\r\n# List\r\nsetspn -L App.Service\r\n\r\n# Delete when not needed anymore\r\nsetspn -D HTTP\/win7x64nov3 MYTEST\\App.Service\r\nsetspn -D HTTP\/win7x64nov3.mytest.local MYTEST\\App.Service\r\n<\/pre>\n<p>* See <a href=\"http:\/\/support.microsoft.com\/?id=871179\">http:\/\/support.microsoft.com\/?id=871179<\/a> for setspn command help.<\/p>\n<span id=\"Client_Machine\"><h3>Client Machine<\/h3><\/span>\n<p>* Turn on <em>allowtgtsessionkey<\/em> in registry. Otherwise you&#8217;ll get <em>Integrity check on decrypted field failed<\/em> error, because no TGT ticket could be read from LSA cache when you specify <em>userTicketCache=true<\/em> in the login.conf file.<\/p>\n<pre lang=\"bash\">\r\nHKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Lsa\\Kerberos\\Parameters\r\nValue Name: allowtgtsessionkey\r\nValue Type: REG_DWORD\r\nValue: 0x01\r\n<\/pre>\n<p>* Also, for Windows 2008 domain, client user <em>cannot<\/em> be in domain administrator group. If you login client machine with a user who is in domain administrator group, you&#8217;ll need elevated privileges in order to read LSA ticket cache.<\/p>\n<span id=\"Java_App:_RunHttpSpnego.java\"><h3>Java App: RunHttpSpnego.java<\/h3><\/span>\n<pre lang=\"java\">\r\npackage test.http.auth.one;\r\n\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.InputStreamReader;\r\nimport java.net.Authenticator;\r\nimport java.net.MalformedURLException;\r\nimport java.net.PasswordAuthentication;\r\nimport java.net.URL;\r\n\r\npublic class RunHttpSpnego {\r\n\r\n  static final String kuser = \"jdoe\"; \/\/ your account name\r\n  static final String kpass = \"SecretPassword\"; \/\/ your password for the account\r\n\r\n  static class MyAuthenticator extends Authenticator {\r\n    public PasswordAuthentication getPasswordAuthentication() {\r\n      \/\/ I haven't checked getRequestingScheme() here, since for NTLM\r\n      \/\/ and Negotiate, the usrname and password are all the same.\r\n      System.err.println(\"Feeding username and password for \"\r\n          + getRequestingScheme());\r\n      return (new PasswordAuthentication(kuser, kpass.toCharArray()));\r\n    }\r\n  }\r\n\r\n  public static void main(String[] args) throws Exception {\r\n    Authenticator.setDefault(new MyAuthenticator());\r\n    readUrl(args);\r\n    System.out.println(\"################################\");\r\n    System.out.println(\"Read again...\");\r\n    readUrl(args);\r\n  }\r\n\r\n  private static void readUrl(String[] args) throws MalformedURLException,\r\n      IOException {\r\n    URL url = new URL(args[0]);\r\n    InputStream ins = url.openConnection().getInputStream();\r\n    BufferedReader reader = new BufferedReader(new InputStreamReader(ins));\r\n    String str;\r\n    while ((str = reader.readLine()) != null)\r\n      System.out.println(str);\r\n  }\r\n}\r\n<\/pre>\n<span id=\"Kerberos_config:_krb5.conf\"><h3>Kerberos config: krb5.conf<\/h3><\/span>\n<p>* Mnimal:<\/p>\n<pre lang=\"bash\">\r\n[libdefaults]\r\n    default_realm = MYTEST.LOCAL\r\n[realms]\r\n    MYTEST.LOCAL = {\r\n        kdc = DC01.MYTEST.local\r\n    }\r\n<\/pre>\n<p>* Win 2003 (this one is actually used):<\/p>\n<pre lang=\"bash\">\r\n[libdefaults]\r\n    default_realm = MYTEST.LOCAL\r\n\tdefault_tkt_enctypes = aes128-cts rc4-hmac des3-cbc-sha1 des-cbc-md5 des-cbc-crc\r\n\tdefault_tgs_enctypes = aes128-cts rc4-hmac des3-cbc-sha1 des-cbc-md5 des-cbc-crc\r\n\tpermitted_enctypes   = aes128-cts rc4-hmac des3-cbc-sha1 des-cbc-md5 des-cbc-crc\r\n\r\n[realms]\r\n\tMYTEST.LOCAL  = {\r\n\t\tkdc = DC01.MYTEST.local \r\n\t\tdefault_domain = MYTEST.local \r\n}\r\n\r\n[domain_realm]\r\n\t.MYTEST.LOCAL = MYTEST.local \r\n<\/pre>\n<p>* For Windows 2008, DES encryption types are turned off by default. <\/p>\n<pre lang=\"bash\">\r\n[libdefaults]\r\n    default_realm = MYTEST.LOCAL\r\n    default_tkt_enctypes = rc4-hmac \r\n    default_tgt_enctypes = rc4-hmac \r\n    permitted_enctypes = rc4-hmac\r\n\r\n[realms]\r\n\tMYTEST.LOCAL  = {\r\n\t\tkdc = mytest.local \r\n\t\tdefault_domain = mytest \r\n}\r\n\r\n[domain_realm]\r\n\t.mytest = MYTEST.LOCAL \r\n<\/pre>\n<span id=\"JAAS_Config:_login.conf\"><h3>JAAS Config: login.conf<\/h3><\/span>\n<pre lang=\"bash\">\r\ncom.sun.security.jgss.krb5.initiate {\r\n  com.sun.security.auth.module.Krb5LoginModule required \r\n  doNotPrompt=false\r\n  storePass=true \r\n  useTicketCache=true;\r\n};\r\n<\/pre>\n<p>* Turn on debugging:<\/p>\n<pre lang=\"bash\">\r\ncom.sun.security.jgss.krb5.initiate {\r\n  com.sun.security.auth.module.Krb5LoginModule required \r\n  doNotPrompt=false \r\n  useTicketCache=true \r\n  debug=true;\r\n};\r\n<\/pre>\n<span id=\"Compile_and_run:\"><h3>Compile and run:<\/h3><\/span>\n<pre lang=\"java\">\r\nset JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_33\r\nSET PATH=%JAVA_HOME%\\bin;%path%\r\n\r\njava -Djava.security.krb5.conf=krb5.conf -Djava.security.auth.login.config=login.conf -Djavax.security.auth.useSubjectCredsOnly=false test.http.auth.one.RunHttpSpnego http:\/\/dc01-a\/testauth\/test.htm\r\n\r\n# Turn on debugging with -Dsun.security.krb5.debug=true\r\njava -Djava.security.krb5.conf=krb5.conf -Djava.security.auth.login.config=login.conf -Djavax.security.auth.useSubjectCredsOnly=false -Dsun.security.krb5.debug=true test.http.auth.one.RunHttpSpnego http:\/\/dc01-a\/testauth\/test.htm\r\n<\/pre>\n<span id=\"Caveats\"><h2>Caveats<\/h2><\/span>\n<p>* In <em>krb5.conf<\/em>, the realm name <strong>has to be<\/strong> all upper cases.<br \/>\n&#8211; This works:<\/p>\n<pre lang=\"bash\">\r\n[libdefaults]\r\n    default_realm = MYTEST.LOCAL\r\n[realms]\r\n    MYTEST.LOCAL = {\r\n ...\r\n<\/pre>\n<p>&#8211; This does <strong>not<\/strong> works<\/p>\n<pre lang=\"bash\">\r\n[libdefaults]\r\n    default_realm = mytest.local\r\n[realms]\r\n    mytest.local = {\r\n<\/pre>\n<span id=\"Windows_2008_Domain_Controller\"><h3>Windows 2008 Domain Controller<\/h3><\/span>\n<p>* On the client machine, user <strong>cannot<\/strong> be a domain administrator. Otherwise, LSA ticket cannot be accessed. Windows 2003 does not have this restriction.<br \/>\n* Encryption types need to be<\/p>\n<pre lang-\"bash\">\r\n    default_tkt_enctypes = rc4-hmac \r\n    default_tgt_enctypes = rc4-hmac \r\n    permitted_enctypes = rc4-hmac\r\n<\/pre>\n<span id=\"Tools\"><h2>Tools<\/h2><\/span>\n<span id=\"Windows_klist.exe\"><h3>Windows <em>klist.exe<\/em><\/h3><\/span>\n<pre lang=\"bash\">\r\ncd c:\\Windows\\system32\r\nklist\r\nc:\\Windows\\System32>klist\r\n\r\nCurrent LogonId is 0:0x4d672\r\n\r\nCached Tickets: (5)\r\n\r\n#0>     Client: Administrator @ MYTEST.LOCAL\r\n        Server: krbtgt\/MYTEST.LOCAL @ MYTEST.LOCAL\r\n        KerbTicket Encryption Type: RSADSI RC4-HMAC(NT)\r\n        Ticket Flags 0x60a00000 -> forwardable forwarded renewable pre_authent\r\n        Start Time: 11\/22\/2012 20:39:15 (local)\r\n        End Time:   11\/23\/2012 6:05:44 (local)\r\n        Renew Time: 11\/29\/2012 0:35:44 (local)\r\n        Session Key Type: RSADSI RC4-HMAC(NT)\r\n<\/pre>\n<span id=\"MIT_Kerberos_for_Windows\"><h3>MIT Kerberos for Windows<\/h3><\/span>\n<p>* Download MIT Kerberos for Windows from <a href=\"http:\/\/web.mit.edu\/kerberos\/dist\/index.html\">MIT Kerberos dist site<\/a>, e.g. Installer kfw-3-2-2.exe, 6425k.<br \/>\n* Double click to install.<\/p>\n<span id=\"Sync_Time_with_Windows_Server\"><h3>Sync Time with Windows Server<\/h3><\/span>\n<p>w32tm \/resync<\/p>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* Java SE 6: <a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/net\/Authenticator.html\">java.net.Authenticator<\/a><br \/>\n* <a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/technotes\/guides\/net\/http-auth.html\">Http Authentication<\/a><br \/>\n* <a href=\"http:\/\/cr.openjdk.java.net\/~weijun\/special\/krb5winguide-2\/raw_files\/new\/kwin\">Kerberos Programming on Windows<\/a><br \/>\n* <a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/jre\/api\/security\/jaas\/spec\/com\/sun\/security\/auth\/module\/Krb5LoginModule.html\">Class Krb5LoginModule<\/a><br \/>\n* <a href=\"http:\/\/old.nabble.com\/Error-calling-function-protocol-status:-1312-td25889010.html\">http:\/\/old.nabble.com\/Error-calling-function-protocol-status:-1312-td25889010.html<\/a><br \/>\n* <a href=\"http:\/\/blog.facilelogin.com\/2010\/11\/kerberos-debugging-tips.html\">http:\/\/blog.facilelogin.com\/2010\/11\/kerberos-debugging-tips.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Http Authentication * Java SE supports: &#8211; HTTP Basic authentication &#8211; HTTP Digest authentication &#8211; NTLM &#8211; Http SPNEGO Negotiate with Kerberos and NTLM * Uses java.net.Authenticator to &#8211; enable authentication &#8211; provide access to a store of usernames &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=6716\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[287],"tags":[291,372,290,628],"class_list":["post-6716","post","type-post","status-publish","format-standard","hentry","category-kerberos","tag-authentication","tag-authenticator","tag-http","tag-kerberos"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-1Kk","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/6716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6716"}],"version-history":[{"count":32,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/6716\/revisions"}],"predecessor-version":[{"id":7936,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/6716\/revisions\/7936"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}