Domain User
Type | {{#dataTypeArticle objectTypeId}}{{objectTypeId}}{{/dataTypeArticle}} |
Datastore Type | {{#dataTypeArticle datastoreTypeId}}{{datastoreTypeId}}{{/dataTypeArticle}} |
Supports | {{#article "security/authorities"}}authorities{{/article}}, {{#article "security/permissions"}}permissions{{/article}}, {{#article "transfer"}}transfer{{/article}} |
Configuration
Domain Users maintain a configuration that you can adjust or consult as you create, update and query for them.
The following table presents you the configuration properties.
Property | Type | Default | Read-Only | Description |
---|---|---|---|---|
name | text | The name (i.e. the user id or account name) for the principal. This can be any text that you like. However, it must be unique across all users in the domain. For example, you cannot have two users in the domain with the name "joe". | ||
type | text | Read-Only | The type of principal - either USER or GROUP . This value is auto-populated upon creation. |
|
authorities | array | [] | An array of text describing the authorities that this user should be granted. This is customizable for your own use and describes server-scoped authorities. Cloud CMS does not use this array for any of its internal authority calculations against objects or data stores. |
Create a Domain User
You create a Domain User by passing in a configuration object that contains, at minimum, the name
of the user being created. The name
of the user must be unique across all principals in the domain. You cannot have two users with the same name
in the same domain. Similarly, you cannot have a user and a group with the same name
in the same domain.
Here is how you create a Domain User:
// create a user domain.createUser({ "name": "ryount" });
// we can also create a user using a more generalized method domain.createPrincipal({ "name": "ryount", "type": "user" });
<p>
You can provide additional properties and also custom properties at the point of creation.
Here is an example of you'd do that:
</p>
// assume we have a domain var domain = ...;
// create a user domain.createUser({ "name": "ryount", "email": "ryount@brewers.com", "title": "Robin Yount", "description": "Center Fielder for the 1982 Milwaukee Brewers", "position": "cf" });
<p>
Domain Users also support authentication. This means that they can authenticate to your cloud platform
and your applications can provide safely store usernames and passwords while providing login services
like password resets, email confirmations and the like.
<br/>
<br/>
It's easy to create a user with a password. Here's an example:
</p>
// assume we have a domain var domain = ...;
// create a user domain.createUser({ "name": "ryount", "email": "ryount@brewers.com", "password": "robin" });
<h2 id="update">Update a Domain User</h2>
<p>
To update, all you have to do is make changes to your Domain User and fire away.
</p>
// assume we have a domain user var user = ...;
// update user.set("title", "Legend of Rock"); user.update();
<p>
You can update any property you'd like from the domain user except for the <code>type</code>. You cannot
switch a group into a user or vice-versa. While both Domain Groups and Domain Users are Domain Principals,
they're not interchangeable.
</p>
<h2 id="delete">Delete a Domain User</h2>
<p>
You can delete a Domain User at any time. All memberships of the Domain User within Domain Groups will
be cleaned up as well. If any Identities associated with a Domain User are no longer needed, they will
also be cleaned up.
Here is an example:
</p>
user.del();
<h2 id="read">Read a Domain User</h2>
<p>
You can read a Domain User by its <code>_doc</code> ID field.
</p>
// assume we have a domain var domain = ...;
// assume we have a user Id var userId = "4b5b685c980c10f98beb";
domain.readPrincipal(userId).then(function() { console.log("Found Domain User with ID: " + this.getId()); });
<h2 id="list">List Domain Users</h2>
<p>
You can retrieve a list of Domain Users for your domain quite easily.
The following code hands back the full list.
</p>
domain.listUsers();
<p>
You can then iterate over the list to pick at what you'd like.
</p>
domain.listUsers().each(function() { console.log("Domain User title: " + this.get("title")); });
<p>
Retrieving the full list is potentially an expensive operation, depending how many items you have.
The more your retrieve, the more data goes over the wire and so forth. Thus, you might wish to
<i>paginate</i> your call and retrieve a subset of the total list at a time.
<br/>
<br/>
Here is an example that retrieves in pages of size 10.
It starts on the second page (by skipping to starting index 20).
It also sorts by the <code>title</code> field in a descending sequence.
</p>
domain.listUsers({ "limit": 10, "skip": 20, "sort": { "title": -1 } }).each(function() { console.log("Domain User title: " + this.get("title")); });
<p>
You don't have to have all of the pagination parameters (<code>limit</code>, <code>skip</code> and <code>sort</code>).
You might only want to include one or two. It's up to you.
</p>
<p>
In addition, you can retrieve a full list of principals (both users and groups) by using a
more generalized approach to list principals.
</p>
domain.listPrincipals({ "limit": 10, "skip": 20, "sort": { "title": -1 } }).each(function() { console.log("Domain Principal: " + this.getId() + " of type: " + this.get("type")); });
<h2 id="query">Query Domain Users</h2>
<p>
You can run custom queries against your Domain Users to find exactly what you're looking for.
Here is a query that looks for Domain Users which are disabled.
</p>
domain.queryUsers({ "position": "cf" });
<p>
Here is that same query followed by an iteration over the result map.
</p>
domain.queryUsers({ "position": "cf" }).each(function(id) { console.log("Found an Domain User: " + id + " with title: " + this.get("title")); });
<p>
You can mix queries with pagination to reduce data over the wire and speed up performance.
Here is that same query with some pagination thrown in.
We limit to pages of size 10 and sort by <code>title</code>.
</p>
domain.queryUsers({ "position": "cf" },{ "limit": 10, "skip": 20, "sort": { "title": -1 } }).each(function(id) { console.log("Found an Domain User: " + id + " with title: " + this.get("title")); });
<p>
In addition, you can query against the full set of principals (both users and groups) by using a
more generalized approach to query principals.
</p>
domain.queryPrincipals({ "position": "cf" },{ "limit": 10, "skip": 20, "sort": { "title": -1 } }).each(function(id) { console.log("Found an Domain Principal: " + id + " of type: " + this.get("type")); });