Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c314130

Browse files
author
michele
committed
http client w/ kerberos
1 parent 4d5e976 commit c314130

File tree

5 files changed

+124
-5
lines changed

5 files changed

+124
-5
lines changed

src/test/java/com/arangodb/BaseTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ public abstract class BaseTest {
3838
@Parameters
3939
public static Collection<ArangoDB.Builder> builders() {
4040
return Arrays.asList(//
41-
new ArangoDB.Builder().useProtocol(Protocol.VST), //
42-
new ArangoDB.Builder().useProtocol(Protocol.HTTP_JSON), //
43-
new ArangoDB.Builder().useProtocol(Protocol.HTTP_VPACK) //
41+
// new ArangoDB.Builder().useProtocol(Protocol.VST), //
42+
new ArangoDB.Builder().useProtocol(Protocol.HTTP_JSON)
43+
// , //
44+
// new ArangoDB.Builder().useProtocol(Protocol.HTTP_VPACK) //
4445
);
4546
}
4647

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.arangodb;/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
22+
import org.apache.http.HttpEntity;
23+
import org.apache.http.HttpResponse;
24+
import org.apache.http.auth.AuthScope;
25+
import org.apache.http.auth.Credentials;
26+
import org.apache.http.client.methods.HttpGet;
27+
import org.apache.http.client.methods.HttpUriRequest;
28+
import org.apache.http.client.params.AuthPolicy;
29+
import org.apache.http.impl.auth.SPNegoSchemeFactory;
30+
import org.apache.http.impl.client.DefaultHttpClient;
31+
import org.apache.http.util.EntityUtils;
32+
33+
import javax.security.auth.login.LoginException;
34+
import java.io.IOException;
35+
import java.security.Principal;
36+
37+
/**
38+
* @author Michele Rastelli
39+
*/
40+
public class KerberosTest {
41+
static private String URL = "http://bruecklinux.arangodb.biz:8899/_db/_system/_api/database/";
42+
43+
public static void main(String[] args) throws IOException, LoginException {
44+
kerberos();
45+
}
46+
47+
private static void kerberos() throws IOException, LoginException {
48+
49+
System.setProperty("java.security.auth.login.config", "/home/michele/arango/arangodb-java-driver/src/test/resources/login.conf");
50+
System.setProperty("java.security.krb5.conf", "/etc/krb5.conf");
51+
System.setProperty("sun.security.krb5.debug", "true");
52+
System.setProperty("sun.security.jgss.debug", "true");
53+
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
54+
System.setProperty("java.security.krb5.realm", "BRUECKLINUX.ARANGODB.BIZ");
55+
System.setProperty("java.security.krb5.kdc", "kerberos.BRUECKLINUX.ARANGODB.BIZ");
56+
57+
// OK
58+
// LoginContext lc = new LoginContext("SampleClient", new TextCallbackHandler());
59+
// lc.login();
60+
// System.out.println("done");
61+
// lc.getSubject();
62+
63+
final boolean stripPort = true;
64+
final boolean useCanonicalHostname = false;
65+
66+
DefaultHttpClient httpclient = new DefaultHttpClient();
67+
try {
68+
httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(stripPort, useCanonicalHostname));
69+
Credentials use_jaas_creds = new Credentials() {
70+
public String getPassword() {
71+
return null;
72+
}
73+
74+
public Principal getUserPrincipal() {
75+
return null;
76+
}
77+
};
78+
httpclient.getCredentialsProvider().setCredentials(
79+
new AuthScope(null, -1, null),
80+
use_jaas_creds);
81+
82+
HttpUriRequest request = new HttpGet("http://bruecklinux.arangodb.biz:8899/_db/_system/_api/database/");
83+
HttpResponse response = httpclient.execute(request);
84+
HttpEntity entity = response.getEntity();
85+
System.out.println("----------------------------------------");
86+
System.out.println(response.getStatusLine());
87+
System.out.println("----------------------------------------");
88+
if (entity != null) {
89+
System.out.println(EntityUtils.toString(entity));
90+
}
91+
System.out.println("----------------------------------------");
92+
// This ensures the connection gets released back to the manager
93+
EntityUtils.consume(entity);
94+
95+
} finally {
96+
// When HttpClient instance is no longer needed,
97+
// shut down the connection manager to ensure
98+
// immediate deallocation of all system resources
99+
httpclient.getConnectionManager().shutdown();
100+
}
101+
}
102+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
arangodb.hosts=localhost:8529
1+
arangodb.hosts=bruecklinux.arangodb.biz:8899
22
arangodb.connections.max=1
33
arangodb.acquireHostList=false
44
arangodb.password=test

src/test/resources/logback-test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</encoder>
99
</appender>
1010

11-
<root level="info">
11+
<root level="trace">
1212
<appender-ref ref="STDOUT" />
1313
</root>
1414
</configuration>

src/test/resources/login.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SampleClient {
2+
com.sun.security.auth.module.Krb5LoginModule required client=true useTicketCache=true debug=true doNotPrompt=true useKeyTab=true keyTab="file:////home/michele/michele.keytab" renewTGT=false principal=michele;
3+
};
4+
5+
com.sun.security.jgss.login {
6+
com.sun.security.auth.module.Krb5LoginModule required client=true useTicketCache=true debug=true doNotPrompt=true useKeyTab=true keyTab="file:////home/michele/michele.keytab" renewTGT=false principal=michele;
7+
};
8+
9+
com.sun.security.jgss.initiate {
10+
com.sun.security.auth.module.Krb5LoginModule required client=true useTicketCache=true debug=true doNotPrompt=true useKeyTab=true keyTab="file:////home/michele/michele.keytab" renewTGT=false principal=michele;
11+
};
12+
13+
com.sun.security.jgss.accept {
14+
com.sun.security.auth.module.Krb5LoginModule required client=true useTicketCache=true debug=true doNotPrompt=true useKeyTab=true keyTab="file:////home/michele/michele.keytab" renewTGT=false principal=michele;
15+
};
16+

0 commit comments

Comments
 (0)