You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2021/09/27 11:14:30 UTC
[jena-site] branch main updated: Auth registration example
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena-site.git
The following commit(s) were added to refs/heads/main by this push:
new 52da1a6 Auth registration example
52da1a6 is described below
commit 52da1a6ee13db48f426af3c492cffebe9b20b173
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Mon Sep 27 12:14:07 2021 +0100
Auth registration example
---
source/documentation/sparql-apis/__index.md | 47 ++++++++++++++++++-----------
1 file changed, 29 insertions(+), 18 deletions(-)
diff --git a/source/documentation/sparql-apis/__index.md b/source/documentation/sparql-apis/__index.md
index 160960d..ccc594c 100644
--- a/source/documentation/sparql-apis/__index.md
+++ b/source/documentation/sparql-apis/__index.md
@@ -294,37 +294,48 @@ query.
### JDK HttpClient.authenticator
-The java platform provides basic authentication.
-This is not challenge based - any request sent using a `HttpClient` configured with an authenticator will include the authentication details. (Caution- - including sending username/password to the wrong site!).
+```java
+ // Basic or Digest - determined when the challenge happens.
+ AuthEnv.get().registerUsernamePassword(URI.create(dataURL), "user", "password");
+ try ( QueryExecution qExec = QueryExecutionHTTP.service(dataURL)
+ .endpoint(dataURL)
+ .queryString("ASK{}")
+ .build()) {
+ qExec.execAsk();
+ }
+```
+
+alternatively, the java platform provides basic authentication.
+This is not challenge based - any request sent using a `HttpClient` configured
+with an authenticator will include the authentication details.
+(Caution - including sending username/password to the wrong site!).
+Digest authentication must use `AuthEnv.get().registerUsernamePassword`.
```java
Authenticator authenticator = AuthLib.authenticator("user", "password");
HttpClient httpClient = HttpClient.newBuilder()
- .connectTimeout(Duration.ofSeconds(10))
.authenticator(authenticator)
.build();
```
```java
- // Use with RDFConnection
- try ( RDFConnection conn = RDFConnectionRemote.service(dataURL)
- .httpClient(httpClient)
- .build()) {
- conn.queryAsk("ASK{}");
- }
+ // Use with RDFConnection
+ try ( RDFConnection conn = RDFConnectionRemote.service(dataURL)
+ .httpClient(httpClient)
+ .build()) {
+ conn.queryAsk("ASK{}");
+ }
```
```java
- // Use with QueryExecution
- System.out.println("HttpClient + QueryExecutionHTTP");
- try ( QueryExecution qExec = QueryExecutionHTTP.service(dataURL)
- .httpClient(httpClient)
- .endpoint(dataURL)
- .queryString("ASK{}")
- .build()) {
- qExec.execAsk();
- }
+ try ( QueryExecution qExec = QueryExecutionHTTP.service(dataURL)
+ .httpClient(httpClient)
+ .endpoint(dataURL)
+ .queryString("ASK{}")
+ .build()) {
+ qExec.execAsk();
+ }
```
### Challenge registration