Differences between revisions 9 and 10
Revision 9 as of 2013-04-03 21:46:40
Size: 2020
Editor: gayatrimehra
Comment:
Revision 10 as of 2013-04-03 21:47:32
Size: 2075
Editor: gayatrimehra
Comment:
Deletions are marked like this. Additions are marked like this.
Line 57: Line 57:
final List<String> users = new ArrayList<String>();
Line 62: Line 63:

Jackrabbit provides an additional API for security and user management. This is about user & group (principal) management. See AccessControl on how to set permissions for users and groups.

API

As an example to check if a user is the admin user, use:

JackrabbitSession js = (JackrabbitSession) session;
User user = ((User) js.getUserManager().getAuthorizable(session.getUserID()));
boolean isAdmin = user.isAdmin();

Please note this algorithm can only be used if user management is supported.

--->>create users

session = (JackrabbitSession) session;
final UserManager userManager = session.getUserManager();
final User user = userManager.createUser(userName, userName);
session.save();

-->> remove user

session = (JackrabbitSession) session;
final UserManager userManager = session.getUserManager();
final User user = (User) userManager.getAuthorizable(userName);
user.remove();
session.save();

--->> fetch members from a group

final List<String> members = new ArrayList<String>();
final UserManager userManager = ((JackrabbitSession) session)
                                        .getUserManager();
final Authorizable auth2 = userManager.getAuthorizable(groupName);
if (auth2.isGroup()) {
Group group = (Group) auth2;
Iterator<Authorizable> iter = group.getMembers();
while (iter.hasNext()) {
Authorizable auth = iter.next();
if (!auth.isGroup()) {
members.add(auth.getID());
                        }
        }

-->> Retrieve all available users from the repo

final List<String> users = new ArrayList<String>();

final UserManager userManager = ((JackrabbitSession) session)
                                        .getUserManager();
Iterator<Authorizable> iter = userManager.findAuthorizables(
        "jcr:primaryType", "rep:User");

while (iter.hasNext()) {
Authorizable auth = iter.next();
if (!auth.isGroup()) {
                users.add(auth.getID());
        }
}
if (!userManager.isAutoSave()) {
        session.save();
        }

TODO

  • list users
  • change password
  • etc.

UserManagement (last edited 2013-04-03 21:47:32 by gayatrimehra)