From 0d12fdcbc2138811860b5bcc133140d664aeb9cc Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Fri, 13 Jun 2014 12:02:40 +0000 Subject: [PATCH] Added Win auth example git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1602402 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/client/win/ClientWinAuth.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 httpclient-win/src/examples/org/apache/http/examples/client/win/ClientWinAuth.java diff --git a/httpclient-win/src/examples/org/apache/http/examples/client/win/ClientWinAuth.java b/httpclient-win/src/examples/org/apache/http/examples/client/win/ClientWinAuth.java new file mode 100644 index 000000000..97e3db749 --- /dev/null +++ b/httpclient-win/src/examples/org/apache/http/examples/client/win/ClientWinAuth.java @@ -0,0 +1,70 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.examples.client.win; + +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.WinHttpClients; +import org.apache.http.util.EntityUtils; + +/** + * This example demonstrates how to create HttpClient pre-configured + * with support for integrated Windows authentication. + */ +public class ClientWinAuth { + + public final static void main(String[] args) throws Exception { + + if (!WinHttpClients.isWinAuthAvailable()) { + System.out.println("Integrated Win auth is not supported!!!"); + } + + CloseableHttpClient httpclient = WinHttpClients.createDefault(); + // There is no need to provide user credentials + // HttpClient will attempt to access current user security context through + // Windows platform specific methods via JNI. + try { + HttpGet httpget = new HttpGet("http://winhost/"); + + System.out.println("Executing request " + httpget.getRequestLine()); + CloseableHttpResponse response = httpclient.execute(httpget); + try { + System.out.println("----------------------------------------"); + System.out.println(response.getStatusLine()); + EntityUtils.consume(response.getEntity()); + } finally { + response.close(); + } + } finally { + httpclient.close(); + } + } + +} +