Simple Kerberos client in Java?

后端 未结 9 586
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 06:47

Applications such a Google\'s Chrome and IE can transparently handle Kerberos authentication; however I can not find a \"simple\" Java solution to match this transparency. A

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 07:01

    There is now a simple solution for this using the Apache HTTP Components Client 4.5 or greater. This is still marked as experimental in 4.5 so your milage may vary, but this is working fine for me in an enterprise context.

    In addition to the HC 4.5 client jars you will need to have the httpclient-win, jna and jna-platform jars on your classpath, as provided with http-component-client. You then construct a Kerberos enabled HC-client as follows:

    CloseableHttpClient httpclient = WinHttpClients.createDefault();
    

    Or using the builder:

    HttpClientBuilder clientBuilder = WinHttpClients.custom();
    

    Which can then be customised as required before building the client:

    CloseableHttpClient client = clientBuilder.build();
    

    This solution works without any external configuration, and most importantly solves the issue where the in-built JRE mechanism breaks for users with local Admin rights on Windows 7+. This is possible because the Kerberos ticket is being retrieved directly from the SSPI API via JNA, rather than going through the GSSAPI provided by the JRE.

    Example code from the http-components team

    This was all made possible by the good work of Daniel Doubrovkine Timothy Wall and Ryan McKinley

提交回复
热议问题