本文整理汇总了Java中org.apache.jackrabbit.api.security.user.UserManager.getAuthorizable方法的典型用法代码示例。如果您正苦于以下问题:Java UserManager.getAuthorizable方法的具体用法?Java UserManager.getAuthorizable怎么用?Java UserManager.getAuthorizable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jackrabbit.api.security.user.UserManager
的用法示例。
在下文中一共展示了UserManager.getAuthorizable方法的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: 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();
}
}
}
示例3: 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()));
}
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: 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();
}
}
示例7: 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
示例8: 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;
}
示例9: createGroups
import org.apache.jackrabbit.api.security.user.UserManager; //导入方法依赖的package包/类
/**
* Create user groups for authors and testers.
*
* @param bundleContext The bundle context provided by the component.
*/
private void createGroups(BundleContext bundleContext){
ServiceReference SlingRepositoryFactoryReference = bundleContext.getServiceReference(SlingRepository.class.getName());
SlingRepository repository = (SlingRepository)bundleContext.getService(SlingRepositoryFactoryReference);
Session session = null;
if (repository != null) {
try {
session = repository.loginAdministrative(null);
if (session != null && session instanceof JackrabbitSession) {
UserManager userManager = ((JackrabbitSession)session).getUserManager();
ValueFactory valueFactory = session.getValueFactory();
Authorizable authors = userManager.getAuthorizable(PublickConstants.GROUP_ID_AUTHORS);
if (authors == null) {
authors = userManager.createGroup(PublickConstants.GROUP_ID_AUTHORS);
authors.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_AUTHORS));
}
Authorizable testers = userManager.getAuthorizable(PublickConstants.GROUP_ID_TESTERS);
if (testers == null) {
testers = userManager.createGroup(PublickConstants.GROUP_ID_TESTERS);
testers.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_TESTERS));
}
}
} catch (RepositoryException e) {
LOGGER.error("Could not get session", e);
} finally {
if (session != null && session.isLive()) {
session.logout();
session = null;
}
}
}
}
示例10: getUserPath
import org.apache.jackrabbit.api.security.user.UserManager; //导入方法依赖的package包/类
public String getUserPath(ResourceResolver resolver, String userId)
throws UnsupportedRepositoryOperationException, RepositoryException {
if (!userPaths.containsKey(userId)) {
final UserManager userManager = resolver.adaptTo(UserManager.class);
final Authorizable usr = userManager.getAuthorizable(userId);
if (usr != null) {
userPaths.put(userId, usr.getPath());
}
}
return userPaths.get(userId);
}
示例11: getUser
import org.apache.jackrabbit.api.security.user.UserManager; //导入方法依赖的package包/类
@Override
public org.apache.jackrabbit.api.security.user.Authorizable getUser() {
if (this.session != null && this.session instanceof JackrabbitSession) {
try {
UserManager userManager = ((JackrabbitSession) this.session).getUserManager();
return userManager.getAuthorizable(this.session.getUserID());
} catch (RepositoryException e) {
log.error("Could not obtain a Jackrabbit UserManager", e);
}
}
return null;
}
示例12: start
import org.apache.jackrabbit.api.security.user.UserManager; //导入方法依赖的package包/类
@Activate
public void start(BundleContext bundleContext) throws Exception {
String[] authorizableIds;
// attempt to find a matching configuration for this service
Configuration config = configurationAdmin.getConfiguration(SERVICE_PID);
Dictionary<String, Object> properties = config.getProperties();
if(properties != null) {
authorizableIds = PropertiesUtil.toStringArray(properties.get(AUTHORIZABLE_IDS));
} else {
authorizableIds = new String[]{DEFAULT_AUTHORIZABLE};
}
Session session = null;
try {
/*
* We should be using a system user for this but currently getting a
* `org.apache.jackrabbit.oak.api.CommitFailedException: OakAccess0000: Access denied`
* when attempting to change the admin password using a system user with ALL permissions granted.
*
* The system user "shinesolutions-password-service" is included as part of this source code and should be
* used like so once the permission issue is resolved:
* <code>
* ResourceResolver resolver = resolverFactory.getServiceResourceResolver(new HashMap<String, Object>() {{
* put(ResourceResolverFactory.SUBSERVICE, "password-service");
* }});
* </code>
*/
ResourceResolver resolver = resolverFactory.getAdministrativeResourceResolver(null);
UserManager userManager = resolver.adaptTo(UserManager.class);
session = resolver.adaptTo(Session.class);
for (String authorizable : authorizableIds) {
try {
Authorizable user = userManager.getAuthorizable(authorizable);
if (user != null) {
((User) user).changePassword(authorizable);
if (!userManager.isAutoSave()) {
session.save();
}
log.info("Changed the password for {}", authorizable);
} else {
log.error("Could not find authorizable {}", authorizable);
}
} catch (RepositoryException repEx) {
log.error("Could not change password for {}", authorizable, repEx);
}
}
} catch (LoginException loginEx) {
log.error("Could not login to the repository", loginEx);
} finally {
if(session != null) {
session.logout();
}
}
}
示例13: GroupPredicate
import org.apache.jackrabbit.api.security.user.UserManager; //导入方法依赖的package包/类
GroupPredicate(UserManager userManager, String groupId, boolean declaredMembersOnly) throws RepositoryException {
Authorizable authorizable = userManager.getAuthorizable(groupId);
group = (authorizable == null || !authorizable.isGroup()) ? null : (Group) authorizable;
this.declaredMembersOnly = declaredMembersOnly;
}
示例14: testAdminConfiguration
import org.apache.jackrabbit.api.security.user.UserManager; //导入方法依赖的package包/类
/**
* @since OAK 1.0 The configuration defines if the password of the
* admin user is being set.
*/
@Test
public void testAdminConfiguration() throws Exception {
Map<String,Object> userParams = new HashMap();
userParams.put(UserConstants.PARAM_ADMIN_ID, "admin");
userParams.put(UserConstants.PARAM_OMIT_ADMIN_PW, true);
ConfigurationParameters params = ConfigurationParameters.of(ImmutableMap.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams)));
SecurityProvider sp = new SecurityProviderImpl(params);
final ContentRepository repo = new Oak().with(new InitialContent())
.with(new PropertyIndexEditorProvider())
.with(new PropertyIndexProvider())
.with(new TypeEditorProvider())
.with(sp)
.createContentRepository();
ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {
@Override
public ContentSession run() throws Exception {
return repo.login(null, null);
}
});
try {
Root root = cs.getLatestRoot();
UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
Authorizable adminUser = umgr.getAuthorizable("admin");
assertNotNull(adminUser);
Tree adminTree = root.getTree(adminUser.getPath());
assertTrue(adminTree.exists());
assertNull(adminTree.getProperty(UserConstants.REP_PASSWORD));
} finally {
cs.close();
}
// login as admin should fail
ContentSession adminSession = null;
try {
adminSession = repo.login(new SimpleCredentials("admin", new char[0]), null);
fail();
} catch (LoginException e) {
//success
} finally {
if (adminSession != null) {
adminSession.close();
}
}
}
示例15: testAnonymousConfiguration
import org.apache.jackrabbit.api.security.user.UserManager; //导入方法依赖的package包/类
/**
* @since OAK 1.0 The anonymous user is optional.
*/
@Test
public void testAnonymousConfiguration() throws Exception {
Map<String,Object> userParams = new HashMap();
userParams.put(UserConstants.PARAM_ANONYMOUS_ID, "");
ConfigurationParameters params = ConfigurationParameters.of(ImmutableMap.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams)));
SecurityProvider sp = new SecurityProviderImpl(params);
final ContentRepository repo = new Oak().with(new InitialContent())
.with(new PropertyIndexEditorProvider())
.with(new PropertyIndexProvider())
.with(new TypeEditorProvider())
.with(sp)
.createContentRepository();
ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {
@Override
public ContentSession run() throws Exception {
return repo.login(null, null);
}
});
try {
Root root = cs.getLatestRoot();
UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
Authorizable anonymous = umgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
assertNull(anonymous);
} finally {
cs.close();
}
// login as admin should fail
ContentSession anonymousSession = null;
try {
anonymousSession = repo.login(new GuestCredentials(), null);
fail();
} catch (LoginException e) {
//success
} finally {
if (anonymousSession != null) {
anonymousSession.close();
}
}
}