知识库

用于挂起和重新激活用户的有用 Cypher 语句

自 Neo4j 3.1 开始,并实现 本地数据库用户,可以暂停用户,从而阻止该用户进一步进行身份验证。

要查看所有已暂停的用户,请运行以下 Cypher 语句

call dbms.security.listUsers() yield username, flags
with username,flags
where 'is_suspended' in flags
return username

此外,如果您需要暂停所有用户,例如在周末维护期间阻止所有数据库访问,可以使用以下 Cypher 生成 Cypher 语句,随后用于暂停以及重新激活所有用户。

  • 生成用于激活当前所有“活跃”用户的 Cypher 语句

// users with no  is_suspended flag and build the statement to activate the user and not force a password change
call dbms.security.listUsers() yield username, flags with username, flags
where not 'is_suspended' in flags
return 'call dbms.security.activateUser(\'' + username + '\',false);'
  • 生成用于暂停当前所有“活跃”用户的 Cypher 语句

// users with no  is_suspended flag
call dbms.security.listUsers() yield username, flags with username, flags
where not 'is_suspended' in flags
return 'call dbms.security.suspendUser(\'' + username + '\');'

最后,在维护窗口期间,首先运行上面生成的 Cypher 语句来暂停所有用户。注意,无法暂停当前登录的用户,因此您可能会看到调用 dbms.security.suspendUser 时返回的错误信息:“不允许暂停自己(用户 'neo4j')”。

维护窗口结束后,您可以运行生成的 Cypher 语句来激活当前所有已定义的被暂停用户。

© . This site is unofficial and not affiliated with Neo4j, Inc.