Skip to content

Switch State Settings



POST /api/v1/login_mapping/set_disable

Overview

Set the master switch and application mode for the site's system login mapping.

Before Calling and Usage Steps

This is a full write of the switch and mode, not a partial update. It is recommended to always explicitly provide isDisable and type. Omitting isDisable defaults to 0 (enabled); omitting type resets to GlobalValid; sending {} also enables GlobalValid, so it cannot be used to query or retain the original configuration. First use Mapping Switch and Mode to save the old values, then assess the impact of the mode on existing users' next login. isDisable=true only disables system rules; it does not simultaneously disable workspace custom mappings, nor does it immediately revoke existing roles/tokens. After saving, read back the switch and verify subsequent logins with a controlled test identity.

Request Headers

Parameter Type Required Description
X-Df-SVersion string Signature version for the original path and request body; it cannot be omitted while continuing to use the algorithm on this page.
Example: v20240417
How to obtain or fill in: The example on this page uses this fixed version, which is paired with the example signature algorithm.
X-Df-Access-Key string Y Read endpoints can use r or w credentials; write endpoints require w credentials.
Example: <external-access-key>
How to obtain or fill in: Assigned by the site administrator as an External API AK; workspace OpenAPI Keys cannot be used.
X-Df-Signature string Y Concatenate the uppercase method, nonce, original full path, timestamp, and original UTF-8 request body with spaces, then compute HMAC-SHA256 and take the hex digest.
Example: <hmac-sha256-hex>
How to obtain or fill in: Calculate using the paired SK according to External API Signature Authentication; see the complete runnable template below.
X-Df-Timestamp string Y Must be within the signature validity window configured for the site; do not reuse the example time.
Example: 1785427200
How to obtain or fill in: At send time, use str(int(time.time())) to generate the current Unix seconds string.
X-Df-Nonce string Y Temporary nonce; also generate a new value and recompute the signature when resending after a failure.
Example: 97d275ee9f774315a7885ba7347acbd9
How to obtain or fill in: Regenerate uuid.uuid4().hex for each request.

Body Request Parameters

Parameter Type Required Description
isDisable boolean Optional boolean; if omitted, the integer 0 (enabled) is actually used, not the original value. null is invalid.
Allows null: False
Allowed values: [True, False]
Example: false
How to obtain or fill in: Pass true to disable system mapping and false to enable it; if you do not want to change it, first read the switch and explicitly fill in the current value.
type string Optional string; if omitted, defaults to GlobalValid and does not retain the old mode. ValidOnFirstLogin determines first-time status based on historical workspace associations; GlobalValid replaces/cleans up on each login; Append appends to system rules. Workspace custom mappings take precedence.
Allows null: False
Allowed values: ['ValidOnFirstLogin', 'GlobalValid', 'Append']
Example: ValidOnFirstLogin
How to obtain or fill in: Choose from ValidOnFirstLogin, GlobalValid, and Append as expected; first assess direct role changes for existing accounts.

Additional Parameter Notes

For authentication, see External API Signature Authentication. This module manages the site system login mapping (isSystem=1) and is used by third-party logins such as OIDC/LDAP that use the shared login mapping chain; it is not a workspace custom mapping or a standalone SAML settings API. Saving the configuration does not immediately batch-recalculate permissions for all existing users; the mode is applied only during subsequent related logins.

When system mapping is enabled and the target workspace has custom mapping disabled: ValidOnFirstLogin applies system rules only to accounts with no historical direct workspace associations (history includes deleted associations), and is not equivalent to only determining whether an account is newly created this time; GlobalValid replaces direct roles according to the rules on each related login and, when there is no match, may remove direct member/role relationships; Append only appends matching system roles and does not clean up original direct relationships when there is no match. If a workspace has custom mapping enabled, that workspace preferentially executes replacement/cleanup for non-matches according to custom rules, and the retention semantics of system Append or first-login mode cannot be applied. Turning off the system switch does not also turn off workspace custom rules. Existing direct Owner roles are retained during matching processing, and new Owner grants are not made through this module.

Configuration is written to the database and Redis cache in separate steps. After a failure, first read back the configuration and have the administrator verify the persisted configuration; do not directly switch modes repeatedly.

Request Example

import hashlib
import hmac
import json
import time
import uuid
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError

# Replace with the target site address and the External API AK/SK assigned by the administrator.
server = "https://external-api.guance.com"
access_key = "<external-access-key>"
secret_key = "<external-secret-key>"
method = 'POST'
path = '/api/v1/login_mapping/set_disable'
query = {}
data = {'isDisable': False, 'type': 'ValidOnFirstLogin'}
full_path = path + ("?" + urlencode(query) if query else "")
body = "" if data is None else json.dumps(data, ensure_ascii=False, separators=(",", ":"))
timestamp = str(int(time.time()))
nonce = uuid.uuid4().hex
string_to_sign = " ".join([method, nonce, full_path, timestamp, body])
signature = hmac.new(secret_key.encode("utf-8"), string_to_sign.encode("utf-8"), hashlib.sha256).hexdigest()
headers = {
    "X-Df-Access-Key": access_key,
    "X-Df-Timestamp": timestamp,
    "X-Df-Nonce": nonce,
    "X-Df-Signature": signature,
    "X-Df-SVersion": "v20240417",
}
if data is not None:
    headers["Content-Type"] = "application/json"
request = Request(server + full_path, data=None if data is None else body.encode("utf-8"), headers=headers, method=method)
try:
    with urlopen(request, timeout=30) as result:
        payload = json.loads(result.read().decode("utf-8"))
except HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))  # Handle according to errorCode, content, and traceId; do not output AK/SK.
    raise SystemExit(1)
except (URLError, TimeoutError):
    print('请求结果未知,请先核对目标当前状态及是否已经写入,再决定是否重新签名重试;不要自动重复写请求。')
    raise SystemExit(1)
print(json.dumps(payload, ensure_ascii=False, indent=2))

Response

HTTP 200, application/json unified envelope; External does not automatically inject declaration, and list pagination is in content.pageInfo.

Field Type Description
content boolean true when the setting is complete; the configured object is not returned; call the switch query to read it back.
{
  "code": 200,
  "content": true,
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

Confirmed rule and request errors are listed in the table. Ordinary database/cache/audit exceptions ultimately produce 500 ft.InternalServerError; subsequent errors may occur only after the configuration has been committed, so read the current state first and then retry.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed Request field is missing, or the field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError Request JSON syntax is invalid Request JSON format error Fix the JSON according to content.reason, line, and column.
400 ft.JsonFormatError JSON top level is not an object Partial JSON file format error Submit a JSON object according to the parameter table.
500 ft.InternalServerError Database, site configuration cache, audit, or unhandled historical data exception Internal error Keep traceId, and first read the rule or switch to confirm the current state; the database and cache/audit are not in the same transaction, so the error does not prove that nothing was saved.

Feedback

Is this page helpful?