Page tree

Here's a Groovy script to reset all the passwords in our database to "". We used this when we went from Magnolia's native authentication to using LDAP.

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.rootNode, new NodeTypePredicate(NodeTypes.User.NAME))
int count = 0
users.each() {
    if (it.name != "anonymous" && it.name != "superuser" ) {
        it.setProperty("pswd", "")
        it.save()
        count++
    }
}
println("Reset password for " + count + " users.")
println("Passwords for user \"anonymous\" and \"superuser\" remain unchanged.")