Creating users from scripts
The following script creates a user and assigns the ROLE_USER role to them. It can be executed from Administration > Utilities > Scripting.
Replace the following placeholder values in the script before executing:
- The string "newId" is the user ID that will be assigned.
- The string "newPassword" is the user password that will be assigned.
- The string "newMail@mail.com" is the user email address.
- The string "New Real Name" is the user's full name.
import com.openkm.util.ContextWrapper;
import com.openkm.api.OKMAuth;
import com.openkm.bean.User;
OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
User user = new User("newId", "newPassword", "newMail@mail.com", "New Real Name", true);
okmAuth.createUser(null, user);
okmAuth.assignRole(null, user.getId(), "ROLE_USER");