use of org.apache.jackrabbit.core.security.authorization.AccessControlProvider in project jackrabbit by apache.
the class UserAccessControlProviderTest method testAnonymousAccessDenied2.
public void testAnonymousAccessDenied2() throws Exception {
Map<String, String> config = new HashMap<String, String>();
config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ID, "abc");
AccessControlProvider p2 = new UserAccessControlProvider();
try {
p2.init(s, config);
Principal princ = new Principal() {
public String getName() {
return "abc";
}
};
Set<Principal> anonymousPrincipals = Collections.singleton(princ);
assertFalse(p2.canAccessRoot(anonymousPrincipals));
CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
try {
assertEquals(CompiledPermissions.NO_PERMISSION, cp);
assertFalse(cp.canReadAll());
assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
} finally {
cp.close();
}
} finally {
p2.close();
}
}
use of org.apache.jackrabbit.core.security.authorization.AccessControlProvider in project jackrabbit by apache.
the class UserAccessControlProviderTest method testAnonymousAccessDenied.
public void testAnonymousAccessDenied() throws Exception {
Map<String, String> config = new HashMap<String, String>();
config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
AccessControlProvider p2 = new UserAccessControlProvider();
try {
p2.init(s, config);
Set<Principal> anonymousPrincipals = getAnonymousPrincipals();
assertFalse(p2.canAccessRoot(anonymousPrincipals));
CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
try {
assertEquals(CompiledPermissions.NO_PERMISSION, cp);
assertFalse(cp.canReadAll());
assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
} finally {
cp.close();
}
} finally {
p2.close();
}
}
use of org.apache.jackrabbit.core.security.authorization.AccessControlProvider in project jackrabbit by apache.
the class CombinedProvider method getEditor.
/**
* @see AccessControlProvider#getEditor(javax.jcr.Session)
*/
public AccessControlEditor getEditor(Session editingSession) {
checkInitialized();
List<AccessControlEditor> editors = new ArrayList<AccessControlEditor>();
for (AccessControlProvider provider : providers) {
try {
editors.add(provider.getEditor(editingSession));
} catch (RepositoryException e) {
log.debug(e.getMessage());
// ignore.
}
}
if (!editors.isEmpty()) {
return new CombinedEditor(editors.toArray(new AccessControlEditor[editors.size()]));
} else {
log.debug("None of the derived access control providers supports editing.");
return null;
}
}
use of org.apache.jackrabbit.core.security.authorization.AccessControlProvider in project jackrabbit by apache.
the class DefaultSecurityManager method getAccessManager.
/**
* @see JackrabbitSecurityManager#getAccessManager(Session,AMContext)
*/
public AccessManager getAccessManager(Session session, AMContext amContext) throws RepositoryException {
checkInitialized();
AccessManagerConfig amConfig = repository.getConfig().getSecurityConfig().getAccessManagerConfig();
try {
String wspName = session.getWorkspace().getName();
AccessControlProvider pp = getAccessControlProvider(wspName);
AccessManager accessMgr;
if (amConfig == null) {
log.debug("No configuration entry for AccessManager. Using org.apache.jackrabbit.core.security.DefaultAccessManager");
accessMgr = new DefaultAccessManager();
} else {
accessMgr = amConfig.newInstance(AccessManager.class);
}
accessMgr.init(amContext, pp, workspaceAccessManager);
return accessMgr;
} catch (AccessDeniedException e) {
// re-throw
throw e;
} catch (Exception e) {
// wrap in RepositoryException
String clsName = (amConfig == null) ? "-- missing access manager configuration --" : amConfig.getClassName();
String msg = "Failed to instantiate AccessManager (" + clsName + ")";
log.error(msg, e);
throw new RepositoryException(msg, e);
}
}
use of org.apache.jackrabbit.core.security.authorization.AccessControlProvider in project jackrabbit by apache.
the class DefaultSecurityManager method getAccessControlProvider.
//--------------------------------------------------------------------------
/**
* Returns the access control provider for the specified
* <code>workspaceName</code>.
*
* @param workspaceName Name of the workspace.
* @return access control provider
* @throws NoSuchWorkspaceException If no workspace with 'workspaceName' exists.
* @throws RepositoryException
*/
private AccessControlProvider getAccessControlProvider(String workspaceName) throws NoSuchWorkspaceException, RepositoryException {
checkInitialized();
AccessControlProvider provider = acProviders.get(workspaceName);
if (provider == null || !provider.isLive()) {
// mark this workspace as 'active' so the workspace does not
// get disposed by the workspace-janitor
// TODO: There should be a cleaner way to do this.
repository.markWorkspaceActive(workspaceName);
WorkspaceSecurityConfig secConf = null;
WorkspaceConfig conf = repository.getConfig().getWorkspaceConfig(workspaceName);
if (conf != null) {
secConf = conf.getSecurityConfig();
}
provider = acProviderFactory.createProvider(repository.getSystemSession(workspaceName), secConf);
synchronized (acProviders) {
acProviders.put(workspaceName, provider);
}
}
return provider;
}
Aggregations