SMART COSMOS Edge User (DevKit) API Documentation

Authorities

REST API

Endpoint

REST API

Required Authority

Create

POST /tenants

none

Update

PUT /tenants/{urn}

https://authorities.smartcosmos.net/tenants/update

Find by URN

GET /tenants/{urn}

https://authorities.smartcosmos.net/tenants/read

Find by Name

GET /tenants/?name={name}

https://authorities.smartcosmos.net/tenants/read

Endpoint

REST API

Required Authority

Create

POST /users

https://authorities.smartcosmos.net/users/create

Update

PUT /users/{urn}

https://authorities.smartcosmos.net/users/update

Find by URN

GET /users/{urn}

https://authorities.smartcosmos.net/users/read

Find by Name

GET /users/?name={name}

https://authorities.smartcosmos.net/users/read

Delete

DELETE /users/{urn}

https://authorities.smartcosmos.net/users/delete

Endpoint

REST API

Required Authority

Create

POST /roles

https://authorities.smartcosmos.net/roles/create

Update

PUT /roles/{urn}

https://authorities.smartcosmos.net/roles/update

Find by URN

GET /roles/{urn}

https://authorities.smartcosmos.net/roles/read

Find by Name

GET /roles/?name={name}

https://authorities.smartcosmos.net/roles/read

Delete

DELETE /roles/{urn}

https://authorities.smartcosmos.net/roles/delete

JSON Fields for Tenants

Field Format Default Required Description

urn

String

generated

no

representation of a User identifier in a common scheme, e.g. urn:user:uuid:<UUID>, will be generated if not provided

name

String

no default

yes

Name of the tenant organization (e.g. Example Company)

active

boolean

true

no

username

String

no default

yes (for create)

Initial admin account

JSON Fields for Users

Field Format Default Required Description

urn

String

generated

no

representation of a User identifier in a common scheme, e.g. urn:user:uuid:<UUID>, will be generated if not provided

username

String

no default

yes

login name, e.g. bob@example.com

emailAddress

String

no default

no

e.g. bob@example.com

active

boolean

true

no

givenName

String

no default

no

surname

String

no default

no

password

String

no default

no

roles

Array of String

no default

yes

e.g. Admin or User

authorities

Array of String

no default

yes

e.g. [https://authorities.smartcosmos.net/things/read, https://authorities.smartcosmos.net/things/create]

tenantUrn

String

no default

yes

representation of the tenant identifier in a common scheme, e.g. urn:tenant:uuid:<UUID>, will be generated if not provided

JSON Fields for Roles

Field Format Default Required Description

urn

String

generated

no

representation of a Role identifier in a common scheme, e.g. urn:role:uuid:<UUID>, will be generated if not provided

name

String

no default

yes

Unique name of the role, e.g. Admin

authorities

Array of String

no default

yes

e.g. [https://authorities.smartcosmos.net/things/read, https://authorities.smartcosmos.net/things/create]

tenantUrn

String

no default

yes

representation of the tenant identifier in a common scheme, e.g. urn:tenant:uuid:<UUID>, will be generated if not provided

URN Scheme

Note that the illustrated scheme for URNs is only for documentation purposes. There must not be any assumptions or expectations on the scheme in the REST layer. All URNs or identifiers are just String values in the scope of REST modules!

Request parameters

Parameter Parameter Type Format Description

urn

url

String

the URN of the Tenant, User, or Role

name

query

String

Optional search parameter to filter the search result by name

API Endpoints

Response Description

400 BAD REQUEST

There were constraint violations in the request body.

401 UNAUTHORIZED

The User represented by the authentication header could not be authenticated.

403 FORBIDDEN

The User represented by the authentication header lacks the authority to perform this action.

404 NOT FOUND

The Thing or Metadata was not found.

409 CONFLICT

A Thing with this URN already exists.

Tenant Endpoints

Create - POST /tenants

Create a new Tenant, and a default User with the Admin Role.

POST /tenants

Example 1

{
    "active": true,
    "name": "Example Company",
    "username": "waldo@example.com"
}
Response
201 CREATED
{
    "urn": "urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c",
    "admin": {
        "urn": "urn:user:uuid:34068f4d-12a5-4546-80f8-9f84b762db20",
        "username": "waldo@example.com",
        "password": "PleaseChangeMeImmediately",
        "roles": [
          "Admin"
        ],
        "tenantUrn": "urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c"
    }
}

Example 2

{
    "name": "Example Company",
    "username": "waldo@example.com"
}
Response
201 CREATED
{
    "urn": "urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c",
    "admin": {
        "urn": "urn:user:uuid:34068f4d-12a5-4546-80f8-9f84b762db20",
        "username": "waldo@example.com",
        "password": "PleaseChangeMeImmediately",
        "roles": [
          "Admin"
        ],
        "tenantUrn": "urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c"
    }
}
Update - PUT /tenants/{urn}

Update an existing Tenant.

PUT /tenants/urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c
{
    "active": false,
    "name": "My Example Company"
}
Response
204 NO CONTENT
Find by URN - GET /tenants/{urn}

Get a Tenant by its URN.

GET /tenants/urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c
Response
200 OK
{
    "urn": "urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c",
    "active": true,
    "name": "My Example Company"
}
Find by Name - GET /tenants/?name={name}

Get a Tenant by its name.

GET /tenants?name=My%20Example%20Company
Response
200 OK
{
    "urn": "urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c",
    "active": true,
    "name": "My Example Company"
}
GET /tenants
Response
200 OK
[
    {
        "urn": "urn:tenant:uuid:346e742e-2f1e-4d91-9ffe-7b38eec6219c",
        "active": true,
        "name": "My Example Company"
    },
    {
        "urn": "urn:tenant:uuid:f1e4ff26-2a5f-41c6-8533-4994cb2cceec",
        "active": true,
        "name": "Another Example Company"
    }
]

User Endpoints

Create - POST /users

Create a new User belonging to the Tenant of the authenticated User.

POST /users

Example 1

{
    "active": true,
    "roles": [
        "User"
    ],
    "username": "bob@example.com",
    "emailAddress": "bob@example.com",
    "givenName": "Bob",
    "surname": "Smith"
}
Response
201 CREATED
{
    "urn": "urn:user:uuid:68a76616-3748-4bc2-93c1-3940b47abb7f",
    "username": "bob@example.com",
    "password": "PleaseChangeMeImmediately",
    "roles": [
        "User"
    ],
    "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
}

Example 2

{
    "roles": [
        "User"
    ],
    "username": "bob@example.com"
}
Response
201 CREATED
{
    "urn": "urn:user:uuid:68a76616-3748-4bc2-93c1-3940b47abb7f",
    "username": "bob@example.com",
    "password": "PleaseChangeMeImmediately",
    "roles": [
        "User"
    ],
    "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
}
Update - PUT /users/{urn}

Update the existing User with the specified URN.

PUT /users/urn:user:uuid:68a76616-3748-4bc2-93c1-3940b47abb7f
{
    "active": false,
    "password": "xyz1234567"
}
Response
204 NO CONTENT
Find by URN - GET /users/{urn}

Get the User with the specified URN.

GET /users/urn:user:uuid:68a76616-3748-4bc2-93c1-3940b47abb7f
Response
200 OK
{
    "urn": "urn:user:uuid:68a76616-3748-4bc2-93c1-3940b47abb7f",
    "active": true,
    "roles": [
        "User"
    ],
    "username": "bob@example.com",
    "emailAddress": "bob@example.com",
    "givenName": "Bob",
    "surname": "Smith",
    "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
}

Find by Name - GET /users?name={name}

Get the User with the specified name.

GET /users
Response
200 OK
[
    {
        "urn": "urn:user:uuid:68a76616-3748-4bc2-93c1-3940b47abb7f",
        "active": true,
        "roles": [
            "User"
        ],
        "username": "bob@example.com",
        "emailAddress": "bob@example.com",
        "givenName": "Bob",
        "surname": "Smith",
        "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
    },
    {
        "urn": "urn:user:uuid:af37520d-86ad-49fe-be25-92ce269fbda4",
        "active": true,
        "roles": [
            "Admin"
        ],
        "username": "jane@example.com",
        "emailAddress": "jane@example.com",
        "givenName": "Jane",
        "surname": "Smith",
        "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
    }
]
Delete - DELETE /users/{urn}

Delete the User with the specified URN.

DELETE /users/urn:role:uuid:fcdf5432-49a8-45ef-96a2-94a022022860
Response
204 NO CONTENT

Roles Endpoints

Create - POST /roles/

Create a Role.

POST /roles/
{
    "name": "User",
    "authorities": [
        "https://authorities.smartcosmos.net/things/read"
    ]
}
Response
201 CREATED
{
    "urn": "urn:role:uuid:fcdf5432-49a8-45ef-96a2-94a022022860",
    "name": "User",
    "active": true,
    "authorities": [
        "https://authorities.smartcosmos.net/things/read"
    ],
    "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
}
Update - PUT /roles/{urn}

Update an existing Role.

PUT /roles/urn:role:uuid:fcdf5432-49a8-45ef-96a2-94a022022860
{
    "name": "User",
    "authorities": [
        "https://authorities.smartcosmos.net/things/read"
    ]
}
Response
204 NO CONTENT
Find by URN - GET /roles/{urn}

Get the Role with the specified URN.

GET /roles/urn:role:uuid:318a9fae-0218-486c-b9f6-86f76b2ff6af
Response
200 OK
{
    "urn": "urn:role:uuid:318a9fae-0218-486c-b9f6-86f76b2ff6af",
    "name": "Admin",
    "active": true,
    "authorities": [
        "https://authorities.smartcosmos.net/things/read",
        "https://authorities.smartcosmos.net/things/create"
    ],
    "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
}
Find by Name - GET /roles?name={name}

Get the Role with the specified name.

GET /roles
Response
200 OK
[
    {
        "urn": "urn:role:uuid:318a9fae-0218-486c-b9f6-86f76b2ff6af",
        "name": "Admin",
        "active": true,
        "authorities": [
            "https://authorities.smartcosmos.net/things/read",
            "https://authorities.smartcosmos.net/things/create"
        ],
        "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
    },
    {
        "urn": "urn:role:uuid:fcdf5432-49a8-45ef-96a2-94a022022860",
        "name": "User",
        "active": true,
        "authorities": [
            "https://authorities.smartcosmos.net/things/read"
        ],
        "tenantUrn": "urn:tenant:uuid:69bb7c6a-a43b-493d-8e9d-e5a3ed65728a"
    }
]
Delete - DELETE /roles/{urn}

Delete the Role with the specified URN.

DELETE /roles/urn:role:uuid:fcdf5432-49a8-45ef-96a2-94a022022860
Response
204 NO CONTENT

Configuration

Below is a typical smartcosmos-edge-user-devkit.yml file, which provides configuration for the service. Individual endpoints can be turned off by setting their respective enabled flags to false. The default behavior (i.e., in the absence of an enabled flag for the endpoint) is enabled.

For a docker-compose deployment of SMART COSMOS DevKit, the file is located in the config directory. For a deployment in which the developer is running her own SMART COSMOS config-server service, the file is located in the top directory of smartcosmos-cluster-config.

server:
  port: 45371

spring:
  datasource:
    url: jdbc:mysql://{dbServer}/{dbName}
    username: {dbUser}
    password: {dbPassword}
    driver-class-name: org.mariadb.jdbc.Driver
    test-on-borrow: true
    validation-query: SELECT 1
  jpa:
    hibernate:
      # Edge User DevKit and User Details DevKit share the database scheme
      ddl-auto: update
      naming_strategy: org.hibernate.cfg.EJB3NamingStrategy

smartcosmos:
  security:
    enabled: true

  endpoints:
    tenants:
      enabled: true
      create.enabled: true
      read:
        urn.enabled: true
        all.enabled: true
      update.enabled: true
    users:
      enabled: true
      create.enabled: true
      read:
        urn.enabled: true
        all.enabled: true
      update.enabled: true
      delete.enabled: true
    roles:
      enabled: true
      create.enabled: true
      read:
        urn.enabled: true
        all.enabled: true
      update.enabled: true
      delete.enabled: true