17.14. 身份验证操作
设置密码策略
-
将 realm 的
passwordPolicy
属性设置为包含特定策略供应商 ID 和可选配置的枚举表达式。 使用以下示例将密码策略设置为默认值。默认值包括:
- 210,000 哈希迭代
- 至少一个特殊字符
- 至少一个大写字符
- 至少一个数字字符
-
不等于
用户的用户名
至少 8 个字符长
kcadm.sh update realms/demorealm -s 'passwordPolicy="hashIterations and specialChars and upperCase and digits and notUsername and length"'
$ kcadm.sh update realms/demorealm -s 'passwordPolicy="hashIterations and specialChars and upperCase and digits and notUsername and length"'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- 要使用与默认值不同的值,请在括号中传递配置。
使用以下示例将密码策略设置为:
- 300,000 个哈希迭代
- 至少两个特殊字符
- 至少两个大写字符
- 至少两个小写字符
- 至少两位数字
- 至少 9 个字符长
-
不等于
用户的用户名
至少重复四个更改
kcadm.sh update realms/demorealm -s 'passwordPolicy="hashIterations(300000) and specialChars(2) and upperCase(2) and lowerCase(2) and digits(2) and length(9) and notUsername and passwordHistory(4)"'
$ kcadm.sh update realms/demorealm -s 'passwordPolicy="hashIterations(300000) and specialChars(2) and upperCase(2) and lowerCase(2) and digits(2) and length(9) and notUsername and passwordHistory(4)"'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
获取当前的密码策略
您可以通过过滤除 passwordPolicy
属性之外的所有输出来获取当前的 realm 配置。
例如,显示 demorealm
的 passwordPolicy
。
kcadm.sh get realms/demorealm --fields passwordPolicy
$ kcadm.sh get realms/demorealm --fields passwordPolicy
列出身份验证流
在 authentication/flows
端点上运行 get
命令。
例如:
kcadm.sh get authentication/flows -r demorealm
$ kcadm.sh get authentication/flows -r demorealm
获取特定的身份验证流
在 authentication/flows/FLOW_ID
端点上运行 get
命令。
例如:
kcadm.sh get authentication/flows/febfd772-e1a1-42fb-b8ae-00c0566fafb8 -r demorealm
$ kcadm.sh get authentication/flows/febfd772-e1a1-42fb-b8ae-00c0566fafb8 -r demorealm
列出流的执行
在 authentication/flows/FLOW_ALIAS/executions
端点上运行 get
命令。
例如:
kcadm.sh get authentication/flows/Copy%20of%20browser/executions -r demorealm
$ kcadm.sh get authentication/flows/Copy%20of%20browser/executions -r demorealm
在执行中添加配置
- 为流获取执行。
- 记录流的 ID。
-
在
authentication/executions/{executionId}/config
端点上运行create
命令。
例如:
kcadm.sh create "authentication/executions/a3147129-c402-4760-86d9-3f2345e401c7/config" -r demorealm -b '{"config":{"x509-cert-auth.mapping-source-selection":"Match SubjectDN using regular expression","x509-cert-auth.regular-expression":"(.*?)(?:$)","x509-cert-auth.mapper-selection":"Custom Attribute Mapper","x509-cert-auth.mapper-selection.user-attribute-name":"usercertificate","x509-cert-auth.crl-checking-enabled":"","x509-cert-auth.crldp-checking-enabled":false,"x509-cert-auth.crl-relative-path":"crl.pem","x509-cert-auth.ocsp-checking-enabled":"","x509-cert-auth.ocsp-responder-uri":"","x509-cert-auth.keyusage":"","x509-cert-auth.extendedkeyusage":"","x509-cert-auth.confirmation-page-disallowed":""},"alias":"my_otp_config"}'
$ kcadm.sh create "authentication/executions/a3147129-c402-4760-86d9-3f2345e401c7/config" -r demorealm -b '{"config":{"x509-cert-auth.mapping-source-selection":"Match SubjectDN using regular expression","x509-cert-auth.regular-expression":"(.*?)(?:$)","x509-cert-auth.mapper-selection":"Custom Attribute Mapper","x509-cert-auth.mapper-selection.user-attribute-name":"usercertificate","x509-cert-auth.crl-checking-enabled":"","x509-cert-auth.crldp-checking-enabled":false,"x509-cert-auth.crl-relative-path":"crl.pem","x509-cert-auth.ocsp-checking-enabled":"","x509-cert-auth.ocsp-responder-uri":"","x509-cert-auth.keyusage":"","x509-cert-auth.extendedkeyusage":"","x509-cert-auth.confirmation-page-disallowed":""},"alias":"my_otp_config"}'
获取执行配置
- 为流获取执行。
-
记下其
authenticationConfig
属性,其中包含配置 ID。 -
在
authentication/config/ID
端点上运行get
命令。
例如:
kcadm get "authentication/config/dd91611a-d25c-421a-87e2-227c18421833" -r demorealm
$ kcadm get "authentication/config/dd91611a-d25c-421a-87e2-227c18421833" -r demorealm
更新执行配置
- 获取流的执行。
-
获取流的
authenticationConfig
属性。 - 记下属性中的配置 ID。
-
在
authentication/config/ID
端点上运行update
命令。
例如:
kcadm update "authentication/config/dd91611a-d25c-421a-87e2-227c18421833" -r demorealm -b '{"id":"dd91611a-d25c-421a-87e2-227c18421833","alias":"my_otp_config","config":{"x509-cert-auth.extendedkeyusage":"","x509-cert-auth.mapper-selection.user-attribute-name":"usercertificate","x509-cert-auth.ocsp-responder-uri":"","x509-cert-auth.regular-expression":"(.*?)(?:$)","x509-cert-auth.crl-checking-enabled":"true","x509-cert-auth.confirmation-page-disallowed":"","x509-cert-auth.keyusage":"","x509-cert-auth.mapper-selection":"Custom Attribute Mapper","x509-cert-auth.crl-relative-path":"crl.pem","x509-cert-auth.crldp-checking-enabled":"false","x509-cert-auth.mapping-source-selection":"Match SubjectDN using regular expression","x509-cert-auth.ocsp-checking-enabled":""}}'
$ kcadm update "authentication/config/dd91611a-d25c-421a-87e2-227c18421833" -r demorealm -b '{"id":"dd91611a-d25c-421a-87e2-227c18421833","alias":"my_otp_config","config":{"x509-cert-auth.extendedkeyusage":"","x509-cert-auth.mapper-selection.user-attribute-name":"usercertificate","x509-cert-auth.ocsp-responder-uri":"","x509-cert-auth.regular-expression":"(.*?)(?:$)","x509-cert-auth.crl-checking-enabled":"true","x509-cert-auth.confirmation-page-disallowed":"","x509-cert-auth.keyusage":"","x509-cert-auth.mapper-selection":"Custom Attribute Mapper","x509-cert-auth.crl-relative-path":"crl.pem","x509-cert-auth.crldp-checking-enabled":"false","x509-cert-auth.mapping-source-selection":"Match SubjectDN using regular expression","x509-cert-auth.ocsp-checking-enabled":""}}'
删除执行的配置
- 为流获取执行。
-
获取 flows
authenticationConfig
属性。 - 记下属性中的配置 ID。
-
在
authentication/config/ID
端点上运行delete
命令。
例如:
kcadm delete "authentication/config/dd91611a-d25c-421a-87e2-227c18421833" -r demorealm
$ kcadm delete "authentication/config/dd91611a-d25c-421a-87e2-227c18421833" -r demorealm