Methods Summary |
---|
public void | add(java.security.Permission p)
// Required test
if (isReadOnly())
throw new IllegalArgumentException("Read only collection");
// This is a homogenous collection, as are all
// PermissionCollections that you'll implement.
if (!(p instanceof XYZPayrollPermission))
throw new IllegalArgumentException("Wrong permission type");
XYZPayrollPermission xyz = (XYZPayrollPermission) p;
String name = xyz.getName();
XYZPayrollPermission other =
(XYZPayrollPermission) permissions.get(name);
if (other != null)
xyz = merge(xyz, other);
// An administrative permission. The administrative permission
// may have only view or only update or both, and multiple
// admin permissions may be added, so the masks are OR-ed
// together.
if (name.equals("*")) {
addedAdmin = true;
adminMask = xyz.mask | adminMask;
}
permissions.put(name, xyz);
|
public java.util.Enumeration | elements()
return permissions.elements();
|
public boolean | implies(java.security.Permission p)
if (!(p instanceof XYZPayrollPermission))
return false;
XYZPayrollPermission xyz = (XYZPayrollPermission) p;
// If the admin name is present, then all names are implied;
// we need check only the permissions.
if (addedAdmin && (adminMask & xyz.mask) == xyz.mask)
return true;
// Otherwise, we can just see if the given individual is
// in our table and if so, see if the permissions match.
Permission inTable = (Permission) permissions.get(xyz.getName());
if (inTable == null)
return false;
return inTable.implies(xyz);
|
private XYZPayrollPermission | merge(XYZPayrollPermission a, XYZPayrollPermission b)
String aAction = a.getActions();
if (aAction.equals(""))
return b;
String bAction = b.getActions();
if (bAction.equals(""))
return a;
return new XYZPayrollPermission(a.getName(), aAction + "," + bAction);
|