Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
81bb1b1
security controller
benoitvidis Jul 8, 2019
7177ddf
doc/security - fixes
benoitvidis Jul 9, 2019
cd6882f
doc/security - lighten yml test files
benoitvidis Jul 9, 2019
d99807f
Merge branch 'master' into kzl-1174-doc-security-controller
jenow Jul 12, 2019
2a92a0b
Update doc/6/controllers/security/delete-user/index.md
benoitvidis Jul 15, 2019
720a654
Update doc/6/controllers/security/delete-user/index.md
benoitvidis Jul 15, 2019
a3b0945
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen Jul 19, 2019
aab3a84
Merge branch 'kzl-1174-doc-security-controller' of github.com:kuzzlei…
Aschen Jul 19, 2019
5b04bf3
wip
Aschen Jul 19, 2019
a16558c
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen Jul 22, 2019
e24a2e5
add gem
Aschen Jul 22, 2019
bf07b41
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen Jul 22, 2019
0d20609
add travis dead links
Aschen Jul 22, 2019
af4ec80
remove deploy
Aschen Jul 22, 2019
e5f31e6
Update doc/6/controllers/security/create-first-admin/index.md
benoitvidis Jul 24, 2019
525c56c
Update doc/6/controllers/security/create-or-replace-profile/snippets/…
benoitvidis Jul 24, 2019
7d2631f
Update doc/6/controllers/security/update-user/index.md
benoitvidis Jul 24, 2019
9accf63
Update doc/6/controllers/security/get-profile-rights/index.md
benoitvidis Jul 24, 2019
1730b35
Update doc/6/controllers/security/delete-user/snippets/delete-user.te…
benoitvidis Jul 24, 2019
e6c64e6
Update doc/6/controllers/security/delete-role/snippets/delete-role.te…
benoitvidis Jul 24, 2019
03756fd
Update doc/6/controllers/security/delete-profile/snippets/delete-prof…
benoitvidis Jul 24, 2019
17cdf92
Update doc/6/controllers/security/create-user/index.md
benoitvidis Jul 24, 2019
916b230
Update doc/6/controllers/security/create-profile/snippets/create-prof…
benoitvidis Jul 24, 2019
b4e8fd2
Update doc/6/controllers/security/create-restricted-user/index.md
benoitvidis Jul 24, 2019
17753c3
Update doc/6/controllers/security/create-or-replace-role/snippets/cre…
benoitvidis Jul 24, 2019
fb6c147
Update doc/6/controllers/security/create-restricted-user/snippets/cre…
benoitvidis Jul 24, 2019
1c080dd
Update doc/6/controllers/security/create-role/snippets/create-role.te…
benoitvidis Jul 24, 2019
f0b18ce
Update doc/6/controllers/security/create-user/index.md
benoitvidis Jul 24, 2019
5607a33
Update doc/6/controllers/security/delete-credentials/snippets/delete-…
benoitvidis Jul 24, 2019
3cafcc2
Merge remote-tracking branch 'origin/6-dev' into kzl-1174-doc-securit…
benoitvidis Jul 24, 2019
b9fa7ce
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen Jul 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ jobs:
script:
- HYDRA_MAX_CONCURRENCY=20 npm run --prefix doc/framework dead-links


- stage: Deploy Stable release on NPM
if: branch = master AND tag IS present AND type != cron
sudo: false
Expand Down
56 changes: 56 additions & 0 deletions doc/6/controllers/security/create-credentials/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
code: true
type: page
title: createCredentials
description: Creates authentication credentials for a user
---

# createCredentials

Creates authentication credentials for a user.

<br />

```js
createCredentials(strategy, kuid, credentials, [options]);
```

<br />

| Property | Type | Description |
| --- | --- | --- |
| `strategy` | <pre>string</pre> | Strategy to use |
| `kuid` | <pre>string</pre> | User [kuid](/core/1/guides/essentials/user-authentication/#kuzzle-user-identifier-kuid) |
| `credentials` | <pre>object</pre> | New credentials |
| `options` | <pre>object</pre> | Query options |

### credentials

The credentials to send. The expected properties depend on the target authentication strategy.

Example for the `local` strategy:

```js
{
username: 'foo',
password: 'bar'
}
```

### options

Additional query options

| Property | Type<br />(default) | Description |
| --- | --- | --- |
| `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `refresh` | <pre>boolean</pre><br />(`false`) | If set to `wait_for`, Kuzzle will not respond until the credentials are indexed |

## Resolves

An `object` representing the new credentials.
The content depends on the authentication strategy.

## Usage

<<< ./snippets/create-credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
try {
await kuzzle.security.createUser('foo', {
content: {
profileIds: ['default'],
fullName: 'John Doe'
},
credentials: {}
});

const response = await kuzzle.security.createCredentials(
'local',
'foo',
{ username: 'foo', password: 'bar' }
);
console.log(response);
/*
{ username: 'foo' }
*/

console.log('Credentials successfully created');
} catch (e) {
console.error(e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: security#createCredentials
description: Creates credentials for the specified strategy
hooks:
after: curl -X DELETE kuzzle:7512/users/foo?refresh=wait_for
template: default
expected: Credentials successfully created
66 changes: 66 additions & 0 deletions doc/6/controllers/security/create-first-admin/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
code: true
type: page
title: createFirstAdmin
description: Creates a Kuzzle administrator account, only if none exist.
---

# createFirstAdmin

Creates a Kuzzle administrator account, only if none exist.

<br />

```js
createFirstAdmin(kuid, body, [options]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kuid is optional and should be put in the options object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not in the sdk and would induce a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should fix our documentation then

```

<br />

| Property | Type | Description |
| --- | --- | --- |
| `kuid` | <pre>string</pre> | Administrator [kuid](/core/1/guides/essentials/user-authentication/#kuzzle-user-identifier-kuid) |
| `body` | <pre>object</pre> | Administrator content &amp; credentials |
| `options` | <pre>object</pre> | Query options |

### body

The `body` property must contain two objects:
- `content`: Administrator additional information. Can be left empty.
Any other attribute can be added.
Make sure to [update the user mapping](/sdk/js/6/controllers/security/update-user-mapping) collection to match your custom attributes.
- `credentials`: Describe how the new administrator can be authenticated. This object must contain one or more
properties, named after the target authentication strategy to use. Each one of these properties are objects
containing the credentials information, corresponding to that authentication strategy.

Example:

```js
{
content: {
firstName: 'John',
lastName: 'Doe'
},
credentials: {
local: {
username: 'admin',
password: 'myPassword'
}
}
}
```

### options

| Property | Type<br />(default) | Description |
| --- | --- | --- |
| `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `reset` | <pre>boolean</pre><br />(`false`) | If true, restricted permissions are applied to `anonymous` and `default` roles |

## Resolves

An [`User`](sdk/js/6/core-classes/user/introduction) object containing information about the newly created administrator.

## Usage

<<< ./snippets/create-first-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
try {
const response = await kuzzle.security.createFirstAdmin(
'admin',
{
content: {
firstName: 'John',
lastName: 'Doe'
},
credentials: {
local: {
username: 'admin',
password: 'myPassword'
}
}
}
);

console.log(response);
/*
User {
_id: 'admin',
content:
{ profileIds: [ 'admin' ],
firstName: 'John',
lastName: 'Doe',
_kuzzle_info:
{ author: '-1',
createdAt: 1560351009496,
updatedAt: null,
updater: null } } }
*/

console.log('First admin successfully created');

} catch (e) {
console.error(e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: security#createFirstAdmin
description: Creates first admin
hooks:
after: curl -X DELETE kuzzle:7512/users/admin?refresh=wait_for
template: default
expected: First admin successfully created
45 changes: 45 additions & 0 deletions doc/6/controllers/security/create-or-replace-profile/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
code: true
type: page
title: createOrReplaceProfile
description: Creates a new profile or, if the provided profile identifier already exists, replaces it.
---

# createOrReplaceProfile

Creates a new profile or, if the provided profile identifier already exists, replaces it.

<br />

```js
createOrReplaceProfile(id, body, [options]);
```

<br />

| Property | Type | Description |
| --- | --- | --- |
| `id` | <pre>string</pre> | Profile identifier |
| `body` | <pre>object</pre> | Profile definition content |
| `options` | <pre>object</pre> | Query options |

### body

| Property | Type | Description |
| --- | --- | --- |
| `policies` | <pre>object</pre> | [Profile content](/core/1/guides/essentials/security/#defining-profiles) |

### options

| Property | Type<br />(default) | Description |
| --- | --- | --- |
| `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `refresh` | <pre>boolean</pre><br />(`false`) | If set to `wait_for`, Kuzzle will not respond until the created/replaced profile is indexed |

## Resolves

A [`Profile`](/sdk/js/6/core-classes/profile/introduction) object representing the updated/created profile.

## Usage

<<< ./snippets/create-or-replace-profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
try {
const response = await kuzzle.security.createOrReplaceProfile(
'myProfile',
{
policies: [
{
roleId: 'default'
},
{
roleId: 'admin',
restrictedTo: [
{
index: 'someIndex',
collections: [
'collection1',
'collection2'
]
}
]
}
]
}
);
console.log(response);

/*
Profile {
_id: 'myProfile',
policies:
[ { roleId: 'default' },
{ roleId: 'admin', restrictedTo: [Array] } ] }
*/

console.log('Profile successfully updated');
} catch (e) {
console.error(e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: security#createOrReplaceProfile
description: Create or replace a profile
hooks:
after: curl -XDELETE kuzzle:7512/profiles/myProfile?refresh=wait_for
template: default
expected: Profile successfully updated
45 changes: 45 additions & 0 deletions doc/6/controllers/security/create-or-replace-role/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
code: true
type: page
title: createOrReplaceRole
description: Creates a new role or, if the provided role identifier already exists, replaces it.
---

# createOrReplaceRole

Creates a new role or, if the provided role identifier already exists, replaces it.

<br />

```js
createOrReplaceRole(id, body, [options]);
```

<br />

| Property | Type | Description |
| --- | --- | --- |
| `id` | <pre>string</pre> | Role identifier |
| `body` | <pre>object</pre> | Role definition content |
| `options` | <pre>object</pre> | Query options |

### body

| Property | Type | Description |
| --- | --- | --- |
| `controllers` | <pre>object</pre> | [Role definition](/core/1/guides/essentials/security/#defining-roles) |

### options

| Property | Type<br />(default) | Description |
| --- | --- | --- |
| `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `refresh` | <pre>boolean</pre><br />(`false`) | If set to `wait_for`, Kuzzle will not respond until the created/replaced role is indexed |

## Resolves

A [`Role`](/sdk/js/6/core-classes/role) object representing the created/replaced role.

## Usage

<<< ./snippets/create-or-replace-role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
try {
const response = await kuzzle.security.createOrReplaceRole(
'read-only',
{
controllers: {
auth: {
actions: {
getCurrentUser: true,
getMyCredentials: true,
getMyRights: true,
logout: true
}
},
collection: {
actions: {
getMapping: true,
list: true
}
},
document: {
actions: {
count: true,
get: true,
mGet: true,
scroll: true,
search: true
}
},
index: {
actions: {
list: true
}
}
}
}
);
console.log(response);
/*
Role {
_id: 'read-only',
controllers:
{ auth: { actions: [Object] },
collection: { actions: [Object] },
document: { actions: [Object] },
index: { actions: [Object] } } }
*/

console.log('Role successfully updated');

} catch (e) {
console.error(e);
}
Loading