本文整理汇总了Java中org.apache.jackrabbit.api.security.user.UserManager类的典型用法代码示例。如果您正苦于以下问题:Java UserManager类的具体用法?Java UserManager怎么用?Java UserManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserManager类属于org.apache.jackrabbit.api.security.user包,在下文中一共展示了UserManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUserGroupMember
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
/**
* Add a user or another group as a member of a specified group.
*
* Function will log an error and do nothing if either the specified group
* or group member cannot be found, or if the specified group is not actually
* a group (i.e. a user).
*
* @param groupName The name of the group to add the member to.
* @param memberName The name of the user or group to add as a member.
* @throws RepositoryException
*/
protected void addUserGroupMember(String groupName, String memberName) throws RepositoryException {
UserManager userManager = AccessControlUtil.getUserManager(session);
Authorizable group = userManager.getAuthorizable(groupName);
Authorizable member = userManager.getAuthorizable(memberName);
if (group == null) {
logger.error("Cannot add member '{}' to group '{}' because '{}' does not exist", memberName, groupName, groupName);
} else if (!group.isGroup()) {
logger.error("Cannot add member '{}' to group '{}' because '{}' is not a group", memberName, groupName, groupName);
} else if (member == null) {
logger.error("Cannot add member '{}' to group '{}' because '{}' does not exist", memberName, groupName, memberName);
} else {
logger.info("Adding member '{}' to group '{}'", memberName, groupName);
((Group) group).addMember(member);
}
}
示例2: getAuthor
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
public Profile getAuthor() {
Profile author = null;
try {
if (contentFragment != null) {
// TODO: find the right property to get the author id from
Resource contentFragmentResource = contentFragment.adaptTo(Resource.class);
ValueMap contentFragmentProperties = contentFragmentResource.getValueMap();
String authorId = contentFragmentProperties.get(AUTHOR_REF_PATH, String.class);
if (authorId != null) {
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
String authorPath = userManager.getAuthorizable(authorId).getPath();
author = resourceResolver.getResource(authorPath).adaptTo(Profile.class);
}
}
} catch (RepositoryException ex) {
LOGGER.error("Error getting article author", ex);
}
return author;
}
示例3: createUser
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
public boolean createUser(String name, String pass) throws AuthorizableExistsException, RepositoryException {
// usual entry point into the Jackrabbit API
JackrabbitSession js = (JackrabbitSession) session;
UserManager um = js.getUserManager();
PrincipalImpl p = new PrincipalImpl(name);
String usersPath = "/" + name;
User u = um.createUser(name, pass, p, null);
u.setProperty("homeFolder", session.getValueFactory().createValue(usersPath));
// "HOME" folder for the brand new user
// createUsersFolder(name, session);
// Assign permissions to the "HOME" folder of the just created user
// assignInitialPermissions(u, u.getPrincipal(), usersPath, session);
session.save();
return true;
}
示例4: testAnonymousLogin
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testAnonymousLogin() throws Exception {
String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());
UserManager userMgr = getUserManager(root);
// verify initial user-content looks like expected
Authorizable anonymous = userMgr.getAuthorizable(anonymousID);
assertNotNull(anonymous);
assertFalse(root.getTree(anonymous.getPath()).hasProperty(UserConstants.REP_PASSWORD));
ContentSession cs = null;
try {
cs = login(new SimpleCredentials(anonymousID, new char[0]));
fail("Login with anonymousID should fail since the initial setup doesn't provide a password.");
} catch (LoginException e) {
// success
} finally {
if (cs != null) {
cs.close();
}
}
}
示例5: testNotEqualAuthorizables
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
/**
* @since OAK 1.0
*/
@Test
public void testNotEqualAuthorizables() throws Exception {
UserManager otherUserManager = getUserConfiguration().getUserManager(root, getNamePathMapper());
Authorizable user = otherUserManager.getAuthorizable(testUser.getID());
Authorizable group = otherUserManager.getAuthorizable(testGroup.getID());
Map<Authorizable, Authorizable> notEqual = new HashMap<Authorizable, Authorizable>();
notEqual.put(testUser, testGroup);
notEqual.put(user, group);
notEqual.put(testUser, user);
notEqual.put(testGroup, group);
for (Map.Entry entry : notEqual.entrySet()) {
assertFalse(entry.getKey().equals(entry.getValue()));
assertFalse(entry.getValue().equals(entry.getKey()));
}
}
示例6: testRemoveAdminUser
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testRemoveAdminUser() throws Exception {
try {
String adminId = getConfig().getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
UserManager userMgr = getUserManager(root);
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null) {
admin = userMgr.createUser(adminId, adminId);
root.commit();
}
root.getTree(admin.getPath()).remove();
root.commit();
fail("Admin user cannot be removed");
} catch (CommitFailedException e) {
// success
} finally {
root.refresh();
}
}
示例7: testRemoveAdminUserFolder
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testRemoveAdminUserFolder() throws Exception {
try {
String adminId = getConfig().getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
UserManager userMgr = getUserManager(root);
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null) {
admin = userMgr.createUser(adminId, adminId);
root.commit();
}
root.getTree(admin.getPath()).getParent().remove();
root.commit();
fail("Admin user cannot be removed");
} catch (CommitFailedException e) {
// success
} finally {
root.refresh();
}
}
示例8: testDisableAdminUser
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testDisableAdminUser() throws Exception {
try {
String adminId = getConfig().getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
UserManager userMgr = getUserManager(root);
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null) {
admin = userMgr.createUser(adminId, adminId);
root.commit();
}
root.getTree(admin.getPath()).setProperty(REP_DISABLED, "disabled");
root.commit();
fail("Admin user cannot be disabled");
} catch (CommitFailedException e) {
// success
} finally {
root.refresh();
}
}
示例9: testEveryone
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testEveryone() throws Exception {
Principal everyone = principalProvider.getPrincipal(EveryonePrincipal.NAME);
assertTrue(everyone instanceof EveryonePrincipal);
Group everyoneGroup = null;
try {
UserManager userMgr = getUserManager(root);
everyoneGroup = userMgr.createGroup(EveryonePrincipal.NAME);
root.commit();
Principal ep = principalProvider.getPrincipal(EveryonePrincipal.NAME);
assertFalse(ep instanceof EveryonePrincipal);
} finally {
if (everyoneGroup != null) {
everyoneGroup.remove();
root.commit();
}
}
}
示例10: testUserManagementPermissionWithJr2Flag
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testUserManagementPermissionWithJr2Flag() throws Exception {
Root testRoot = getTestRoot();
testRoot.refresh();
UserManager testUserMgr = getUserConfiguration().getUserManager(testRoot, NamePathMapper.DEFAULT);
try {
User u = testUserMgr.createUser("a", "b");
testRoot.commit();
u.changePassword("c");
testRoot.commit();
u.remove();
testRoot.commit();
} finally {
root.refresh();
Authorizable user = getUserManager(root).getAuthorizable("a");
if (user != null) {
user.remove();
root.commit();
}
}
}
示例11: testAccessControlActionForUser
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testAccessControlActionForUser() throws Exception {
UserManager userMgr = getUserManager(root);
User u = null;
try {
String uid = "actionTestUser";
u = userMgr.createUser(uid, uid);
root.commit();
assertAcAction(u, PrivilegeConstants.JCR_ALL);
} finally {
root.refresh();
if (u != null) {
u.remove();
}
root.commit();
}
}
示例12: testAccessControlAction
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
@Test
public void testAccessControlAction() throws Exception {
UserManager userMgr = getUserManager(root);
Group gr = null;
try {
gr = userMgr.createGroup("actionTestGroup");
root.commit();
assertAcAction(gr, PrivilegeConstants.JCR_READ);
} finally {
root.refresh();
if (gr != null) {
gr.remove();
}
root.commit();
}
}
示例13: findPaths
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
private List<PathFilterSet> findPaths(final ResourceResolver resourceResolver,
final String[] authorizableIds) throws RepositoryException {
final UserManager userManager = resourceResolver.adaptTo(UserManager.class);
final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
for (final String authorizableId : authorizableIds) {
try {
final Authorizable authorizable = userManager.getAuthorizable(authorizableId);
if (authorizable != null) {
final String path = authorizable.getPath();
final PathFilterSet principal = new PathFilterSet(path);
// Exclude tokens as they are not vlt installable in AEM6/Oak
principal.addExclude(new DefaultPathFilter(path + "/\\.tokens"));
pathFilterSets.add(principal);
}
} catch (RepositoryException e) {
log.warn("Unable to find path for authorizable " + authorizableId, e);
}
}
return pathFilterSets;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:25,代码来源:AuthorizablePackagerServletImpl.java
示例14: getPrincipalResources
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
/**
* Gets the resources for the param principals.
*
* @param resourceResolver the ResourceResolver obj to get the principal resources;
* Must have read access to the principal resources.
* @param principalNames the principals to get
* @return a list of PathFilterSets covering the selectes principal names (if they exist)
* @throws RepositoryException
*/
private List<PathFilterSet> getPrincipalResources(final ResourceResolver resourceResolver,
final String[] principalNames) throws RepositoryException {
final UserManager userManager = resourceResolver.adaptTo(UserManager.class);
final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
for (final String principalName : principalNames) {
final Authorizable authorizable = userManager.getAuthorizable(principalName);
if (authorizable != null) {
final Resource resource = resourceResolver.getResource(authorizable.getPath());
if (resource != null) {
final PathFilterSet principal = new PathFilterSet(resource.getPath());
// Exclude tokens as they are not vlt installable in AEM6/Oak
principal.addExclude(new DefaultPathFilter(resource.getPath() + "/\\.tokens"));
pathFilterSets.add(principal);
}
}
}
return pathFilterSets;
}
示例15: CsvUser
import org.apache.jackrabbit.api.security.user.UserManager; //导入依赖的package包/类
public CsvUser(Resource resource) throws RepositoryException {
if (resource == null) {
throw new IllegalArgumentException("Authorizable object cannot be null");
}
final UserManager userManager = resource.adaptTo(UserManager.class);
this.properties = resource.getValueMap();
this.authorizable = userManager.getAuthorizableByPath(resource.getPath());
this.declaredGroups = getGroupIds(authorizable.declaredMemberOf());
this.transitiveGroups = getGroupIds(authorizable.memberOf());
this.allGroups.addAll(this.transitiveGroups);
this.allGroups.addAll(this.declaredGroups);
this.transitiveGroups.removeAll(this.declaredGroups);
this.firstName = properties.get("profile/givenName", "");
this.lastName = properties.get("profile/familyName", "");
this.email = properties.get("profile/email", "");
this.createdDate = properties.get(JcrConstants.JCR_CREATED, Calendar.class);
this.lastModifiedDate = properties.get("cq:lastModified", Calendar.class);
}