Skip to content

Commit

Permalink
JCR-2887 : Split PrivilegeRegistry in a per-session manager instance …
Browse files Browse the repository at this point in the history
…and a repository level registry [work in progress]

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/trunk@1082450 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
anchela committed Mar 17, 2011
1 parent f53daf4 commit e2e931a
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public boolean grants(Path absPath, int permissions) {
return true;
}
public int getPrivileges(Path absPath) throws RepositoryException {
return getPrivilegeManagerImpl().getBits(new Privilege[] {getAllPrivilege()});
return getPrivilegeManagerImpl().getBits(getAllPrivilege());
}
public boolean hasPrivileges(Path absPath, Privilege[] privileges) {
public boolean hasPrivileges(Path absPath, Privilege... privileges) {
return true;
}
public Set<Privilege> getPrivilegeSet(Path absPath) throws RepositoryException {
Expand Down Expand Up @@ -150,10 +150,10 @@ public int getPrivileges(Path absPath) throws RepositoryException {
if (isAcItem(absPath)) {
return PrivilegeRegistry.NO_PRIVILEGE;
} else {
return getPrivilegeManagerImpl().getBits(new Privilege[] {getReadPrivilege()});
return getPrivilegeManagerImpl().getBits(getReadPrivilege());
}
}
public boolean hasPrivileges(Path absPath, Privilege[] privileges) throws RepositoryException {
public boolean hasPrivileges(Path absPath, Privilege... privileges) throws RepositoryException {
if (isAcItem(absPath)) {
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.jackrabbit.spi.Path;

import javax.jcr.RepositoryException;
import javax.jcr.security.AccessControlException;
import javax.jcr.security.Privilege;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -123,9 +122,9 @@ public int getPrivileges(Path absPath) throws RepositoryException {
}

/**
* @see CompiledPermissions#hasPrivileges(Path, Privilege[])
* @see CompiledPermissions#hasPrivileges(org.apache.jackrabbit.spi.Path,javax.jcr.security.Privilege...)
*/
public boolean hasPrivileges(Path absPath, Privilege[] privileges) throws RepositoryException {
public boolean hasPrivileges(Path absPath, Privilege... privileges) throws RepositoryException {
Result result = getResult(absPath);
int builtin = getPrivilegeManagerImpl().getBits(privileges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public interface CompiledPermissions {
* specified <code>absPath</code>.
* @throws RepositoryException
*/
boolean hasPrivileges(Path absPath, Privilege[] privileges) throws RepositoryException;
boolean hasPrivileges(Path absPath, Privilege... privileges) throws RepositoryException;

/**
* Returns the <code>Privilege</code>s granted by the underlying policy
Expand Down Expand Up @@ -135,7 +135,7 @@ public int getPrivileges(Path absPath) {
return PrivilegeRegistry.NO_PRIVILEGE;
}

public boolean hasPrivileges(Path absPath, Privilege[] privileges) throws RepositoryException {
public boolean hasPrivileges(Path absPath, Privilege... privileges) throws RepositoryException {
return false;
}
public Set<Privilege> getPrivilegeSet(Path absPath) throws RepositoryException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public boolean isCustomPrivilege(Privilege privilege) throws AccessControlExcept
* @throws AccessControlException If the specified array is null, empty
* or if it contains an unregistered privilege.
*/
public int getBits(Privilege[] privileges) throws AccessControlException {
public int getBits(Privilege... privileges) throws AccessControlException {
if (privileges == null || privileges.length == 0) {
throw new AccessControlException("Privilege array is empty or null.");
}
Expand All @@ -197,7 +197,8 @@ public int getBits(Privilege[] privileges) throws AccessControlException {
if (priv instanceof PrivilegeImpl) {
defs[i] = ((PrivilegeImpl) priv).definition;
} else {
throw new AccessControlException("Unknown privilege '" + priv.getName() + "'.");
String name = (priv == null) ? "null" : priv.getName();
throw new AccessControlException("Unknown privilege '" + name + "'.");
}
}
return registry.getBits(defs);
Expand All @@ -211,11 +212,11 @@ public int getBits(Privilege[] privileges) throws AccessControlException {
* <code>bits</code>. If <code>bits</code> does not match to any registered
* privilege an empty array will be returned.
*
* @param bits Privilege bits as obtained from {@link #getBits(Privilege[])}.
* @param bits Privilege bits as obtained from {@link #getBits(Privilege...)}.
* @return Array of <code>Privilege</code>s that are presented by the given
* <code>bits</code> or an empty array if <code>bits</code> cannot be
* resolved to registered <code>Privilege</code>s.
* @see #getBits(Privilege[])
* @see #getBits(Privilege...)
*/
public Set<Privilege> getPrivileges(int bits) {
Name[] names = registry.getNames(bits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public Privilege[] getPrivileges(int bits) {
* @throws AccessControlException If the specified array is null
* or if it contains an unregistered privilege.
* @see #getPrivileges(int)
* @deprecated Use {@link PrivilegeManagerImpl#getBits(javax.jcr.security.Privilege[])} instead.
* @deprecated Use {@link PrivilegeManagerImpl#getBits(javax.jcr.security.Privilege...)} instead.
*/
public static int getBits(Privilege[] privileges) throws AccessControlException {
if (privileges == null || privileges.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void init(Session systemSession, Map configuration) throws RepositoryExce
editor = new ACLEditor(session, resolver.getQPath(acRoot.getPath()));
entriesCache = new EntriesCache(session, editor, acRoot.getPath());
PrivilegeManagerImpl pm = getPrivilegeManagerImpl();
readBits = pm.getBits(new Privilege[] {pm.getPrivilege(Privilege.JCR_READ)});
readBits = pm.getBits(pm.getPrivilege(Privilege.JCR_READ));

// TODO: replace by configurable default policy (see JCR-2331)
if (!configuration.containsKey(PARAM_OMIT_DEFAULT_PERMISSIONS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ protected CompiledPermissionsImpl(Set<Principal> principals, String userNodePath

private int getPrivilegeBits(String privName) throws RepositoryException {
PrivilegeManagerImpl impl = getPrivilegeManagerImpl();
return impl.getBits(new Privilege[] {impl.getPrivilege(privName)});
return impl.getBits(impl.getPrivilege(privName));
}

//------------------------------------< AbstractCompiledPermissions >---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public boolean isAllow() {
return false;
}
public int getPrivilegeBits() throws RepositoryException {
return privilegeMgr.getBits(new Privilege[] {privilegeMgr.getPrivilege(Privilege.JCR_READ)});
return privilegeMgr.getBits(privilegeMgr.getPrivilege(Privilege.JCR_READ));
}
public String[] getRestrictionNames() {
return new String[0];
Expand Down
Loading

0 comments on commit e2e931a

Please sign in to comment.