Skip to content

Commit

Permalink
GDB-5393 Refactor repository and server clients configuration (#127)
Browse files Browse the repository at this point in the history
* GDB-5393 Refactor repository and server clients configuration

Provides configuration builder and unifies configuration creation.
Provides authentication factory.
Authentication service refactor to decouple user state
Minor sonar bug fixes
Test refactored according code changes
New eslint rules for test files
Update documentation
Update README.md
Update CHANGELOG.md
  • Loading branch information
teodossidossev authored Feb 10, 2021
1 parent a78665a commit ae13c41
Show file tree
Hide file tree
Showing 166 changed files with 6,412 additions and 2,746 deletions.
13 changes: 12 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,16 @@
"node": true,
"browser": true,
"jest": true
}
},
"overrides": [
{
"files": ["test/**", "test-e2e/**"],
"rules": {
"require-jsdoc": "off",
"prefer-promise-reject-errors": "off",
"valid-jsdoc": "off"
}
}
]
}

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
* `Check the GDB server version and report mismatches if the client version implements a different version unless the check is stopped.`
* `Support secured endpoints exposing only HTTPS`

## 2.0.0 (2021-02-10)
* Major changes in the construction of server and repository client configurations.
* Update Readme.md

## 1.7.0 (2021-02-10)
* Upgrade to graphDb 9.6.0

## 1.6.1 (2021-02-09)
* Authenticate against a secured GDB server
* Manage repositories through GraphDBServerClient
* Fix latest vulnerabilities and lib updates
* Migrate to Jenkins
* Update repository tutorials in Readme.md
* Created README for the e2e-test package

**Bugfixes**
* Repository client authentication endpoint fix

## 1.5.0 (2020-12-10)
* Upgrade to graphDb 9.5.0

Expand Down
82 changes: 64 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,26 @@ first.
const {ServerClient, ServerClientConfig} = require('graphdb').server;
const {RDFMimeType} = require('graphdb').http;

const serverConfig = new ServerClientConfig('http://rdf4j-compliant-server/', 0, {
'Accept': RDFMimeType.SPARQL_RESULTS_JSON
});
const serverConfig = new ServerClientConfig('http://rdf4j-compliant-server/')
.setTimeout(5000)
.setHeaders({
'Accept': RDFMimeType.SPARQL_RESULTS_JSON
})
.setKeepAlive(true);

const server = new ServerClient(serverConfig);
```

When created, configurations receive the following default parameters:
```javascript
/**
* The Server client configuration constructor
* sets configuration default value to
* timeout = 10000,
* keepAlive = true
*/
```

* Fetch repository ids

```javascript
Expand Down Expand Up @@ -180,8 +194,8 @@ Used to automate the security user management API: add, edit, or remove users.
// Import all classes needed for work
const {GraphDBServerClient, ServerClientConfig} = require('graphdb').server;
// Instance the server configuration
const serverConfig = new ServerClientConfig('http://rdf4j-compliant-server/', 10000,
new Map(), 'admin', 'root', true, true);
const serverConfig = new ServerClientConfig('http://rdf4j-compliant-server/')
.useGdbTokenAuthentication('admin', 'root');
// Instance the server client
const serverClient = new GraphDBServerClient(serverConfig);
```
Expand Down Expand Up @@ -289,28 +303,50 @@ Use with extreme caution, as the changes that are made to the application settin
* Instantiating repository client

```javascript
const endpoint = 'http://GDB';
const readTimeout = 30000;
const writeTimeout = 30000;
const config = new RepositoryClientConfig(['http://GDB/repositories/my-repo'], {
'Accept': RDFMimeType.TURTLE
}, '', readTimeout, writeTimeout);
const config = new RepositoryClientConfig(endpoint)
.setEndpoints(['http://GDB/repositories/my-repo'])
.setHeaders({
'Accept': RDFMimeType.TURTLE
})
.setReadTimeout(readTimeout)
.setWriteTimeout(writeTimeout);
const repository = new RDFRepositoryClient(config);
```
When created, configurations receive the following default parameters:
```javascript
/**
* The Repository client configuration constructor
* sets configuration default value to
* defaultRDFMimeType = 'application/sparql-results+json',
* keepAlive = true,
* readTimeout = 10000,
* writeTimeout = 10000
*/
```

* Obtaining repository client instance through a ServerClient

```javascript
const {ServerClient, ServerClientConfig} = require('graphdb').server;
const {RepositoryClientConfig} = require('graphdb').repository;

const config = new ServerClientConfig('http://GDB', 0, {});
const endpoint = 'http://GDB';
const config = new ServerClientConfig(endpoint);
const server = new ServerClient(config);

const readTimeout = 30000;
const writeTimeout = 30000;
const repositoryClientConfig = new RepositoryClientConfig(['http://GDB/repositories/my-repo'], {}, '', readTimeout, writeTimeout);
return server.getRepository('automotive', repositoryClientConfig).then((rdfRepositoryClient) => {
// rdfRepositoryClient is a configured instance of RDFRepositoryClient

const repositoryClientConfig = new RepositoryClientConfig(endpoint)
.setEndpoints(['http://GDB/repositories/my-repo'])
.setReadTimeout(readTimeout)
.setWriteTimeout(writeTimeout);
return server.getRepository('automotive', repositoryClientConfig)
.then((rdfRepositoryClient) => {
// rdfRepositoryClient is a configured instance of RDFRepositoryClient
});
```

Expand Down Expand Up @@ -436,7 +472,7 @@ return repository.update(payload).then(() => {

```javascript
repository.deleteStatements(subj, pred, obj, contexts).then(() => {

// do work
});
```

Expand Down Expand Up @@ -568,24 +604,28 @@ In case the server requires that requests should be authenticated, then in the `
##### ServerClient
```javascript
const headers = {'Accept': 'text/plain'};
const config = new ServerClientConfig('/endpoint', 1000, headers, 'testuser', 'P@sw0rd');
const config = new ServerClientConfig('/endpoint')
.setTimeout(5000)
.setHeaders(headers)
.useGdbTokenAuthentication('user', 'root');
const client = new ServerClient(config);
```
##### RepositoryClient
```javascript
const endpoint = 'http://host/';
const endpoints = ['http://host/repositories/repo1'];
const headers = {};
const contentType = '';
const readTimeout = 1000;
const writeTimeout = 1000;

const config = new RepositoryClientConfig()
const config = new RepositoryClientConfig(endpoint)
.setEndpoints(endpoints)
.setHeaders(headers)
.setDefaultRDFMimeType(contentType)
.setReadTimeout(readTimeout)
.setWriteTimeout(writeTimeout)
.setUsername('testuser')
.setPass('pass123');
.useGdbTokenAuthentication('testuser', 'pass123');
const repository = new RDFRepositoryClient(config);
const httpRequest = repository.httpClients[0].request;
````
Expand All @@ -599,12 +639,18 @@ If the GDB token expires, then the first API call will be rejected with an http
Instead of using GDB token, users can access secured GraphDB by passing valid base-64 encoded username:password combinations as a header.
In case Basic authentication will be used, then the headers in the `ServerClientConfig` and `RepositoryClientConfig` must be configured to send the `username` and `password` which to be used for the authentication. From this moment on, with every API call is sent also an `authorization` header with the encoded credentials as value.
```javascript
config.setBasicAuthentication(true);
config.useBasicAuthentication('admin', 'root');
```

> **Note:**
> Basic Authentication is even more vulnerable to man-in-the-middle attacks than GDB token! Anyone who intercepts your requests will be able to reuse your credentials indefinitely until you change them. Since the credentials are merely base-64 encoded, they will also get your username and password. This is why it is very important to always use encryption in transit.

##### Disable authentication
If necessary, authentication can be disabled in the configuration.
```javascript
config.disableAuthentication();
```

### Response Parsers

Read responses of different content types might be parsed to data objects with
Expand Down
Loading

0 comments on commit ae13c41

Please sign in to comment.