由于我们的登录名存在区分大小写的问题,因此我试图将木兰应用程序中的所有用户名都更改为大写。
我编写了这个时髦的脚本,下面是一个用于将密码重置为“”的示例,以捕获用户并将其更改为大写,但是看来name属性未设置。
https://documentation.magnolia-cms.com/display/WIKI/Reset+all+passwords
import info.magnolia.jcr.util.NodeUtil
import info.magnolia.jcr.predicate.NodeTypePredicate
import info.magnolia.jcr.util.NodeTypes
session = ctx.getJCRSession("users")
users = NodeUtil.collectAllChildren(session.getNode("/public"), new NodeTypePredicate(NodeTypes.User.NAME))
users.each() {
changedName = it.name.toUpperCase();
it.setProperty("name", changedName)
it.save();
println "1 " + changedName;
println "2 " + it.name;
}
session.save();
当我检查它时,返回的是它们在芒果中的存储方式,而不是全部大写,并且在查看用户名时也不会在安全性应用程序中更改它们。
答案 0 :(得分:1)
import info.magnolia.jcr.util.NodeUtil
import info.magnolia.jcr.predicate.NodeTypePredicate
import info.magnolia.jcr.util.NodeTypes
session = ctx.getJCRSession("users")
users = NodeUtil.collectAllChildren(session.getNode("/admin"), new NodeTypePredicate(NodeTypes.User.NAME))
users.each() {
name = it.name
changedName = it.name.toUpperCase();
it.setProperty("name", changedName)
it.setProperty("jcrName", changedName)
it.save()
NodeUtil.renameNode(it, changedName)
it.getNode("acl_users").getNodes().each { node ->
newPath = node.getProperty("path").getString().replace(name, changedName)
node.setProperty("path", newPath)
node.save()
}
}
session.save()
嘿,也许这就是您要寻找的。您需要在“我的版本”中更改节点名称和jcrName,然后遍历acl_users节点并更改每个路径。希望这对您有用。
答案 1 :(得分:0)
IIRC,您需要更改三件事。
name
是其中之一,然后是jcrName
属性,然后您需要更改节点本身的名称。至少如果您希望以这种方式在安全应用程序中看到它。
对于登录本身,您所做的应该已经足够。
答案 2 :(得分:0)
尝试使用PropertyUtil的setProperty方法。 您必须提取所需的所有节点,然后遍历它们。假设变量 node 是要更改名称的Node,请执行以下操作:
String newName = StringUtils.upperCase(PropertyUtil.getString(node, "jcrName"));
PropertyUtil.setProperty(node, "jcrName", newName);
jcrName是您需要覆盖的属性。将代码包装到try / catch块中,然后开始。
希望有帮助。