/*
* Create ProtectionDomain passing null as CodeSource,
* null as PermissionCollection, class loader and created
* array of QAPrincipals.
*/
ProtectionDomain pd = new ProtectionDomain(null, null,
classLoaders[i], praa[i]);
/*
* Call implies() on DynamicPolicyProvider passing
* created ProtectionDomain and permissions that are
* granted in the policy file.
* Verify that implies() returns false.
*/
checkImplies(pd, pmGranted, false, false);
/*
* Call implies() on DynamicPolicyProvider passing
* created ProtectionDomain and permissions that are
* dynamic granted in the policy file.
* Verify that implies() returns false.
*/
checkImplies(pd, pmDynamicGranted, false, false);
/*
* Call implies() on DynamicPolicyProvider passing
* created ProtectionDomain and permissions that are
* not granted in the policy file.
* Verify that implies() returns false.
*/
checkImplies(pd, pmDynamicNotGranted, false, false);
}
}
/*
* Iterate over created array of array of QAPrincipals.
*/
for (int i = 0; i <= praBase.length; i++) {
/*
* For all loaded classes call grant() on
* DynamicPolicyProvider passing array of QAPrincipals and
* passing permissions that should NOT BE dynamic granted
* and verify that SecurityExceptions are thrown.
*/
checkGrant(classes, praa[i], pmGranted, true);
checkGrant(classes, praa[i], pmNotGranted, true);
checkGrant(classes, praa[i], pmDynamicNotGranted, true);
}
/*
* Verify that size of array of loaded classes is less then
* the size of created array of array of QAPrincipals.
*/
if (classes.length >= praBase.length) {
throw new TestException("Too many loaded classes.");
}
/*
* Iterate over loaded classes.
*/
for (int i = 1; i < classes.length; i++) {
/*
* Call grant() on DynamicPolicyProvider
* passing class, array of QAPrincipals so that
* index of passing class shoud be equal to
* index of array of array of QAPrincipals and
* permissions that should BE dynamic granted
* and verify that no exceptions are thrown.
*/
Class[] cla = new Class[] { classes[i] };
checkGrant(cla, praa[i], pmDynamicGranted, false);
}
/*
* Iterate over loaded classes and check for
* dynamic permissions granted earlier using getGrants()
* method.
*/
int boundCheck = Util.listClasses.length;
for (int i = 1; i < classes.length; i++) {
Class[] cla = new Class[] { classes[i] };
/*
* Iterate over array of array of QAPrincipals and
* call getGrants() passing array of QAPrincipals.
* Verify that getGrants() returns permissions that are
* dynamic granted earlier only for array of QAPrincipals
* that have index more or equal to upperbound index
* for classes that belongs to the same class loader.
* For indexes that less then upperbound index
* getGrants() should return empty array of permissions.
*
*/
for (int j = 0; j <= praBase.length; j++) {
int upperBound = 1 + ((i - 1) / boundCheck) * boundCheck;
if (j < upperBound) {
checkGetGrants(cla, praa[j], pmEmpty);
} else {
checkGetGrants(cla, praa[j], pmDynamicGranted);
}
}
}
/*
* Iterate over loaded classes and check for
* dynamic permissions granted earlier using implies()
* method.
*/
for (int i = 1; i < classes.length; i++) {
/*
* Get CodeSource of class.
*/
CodeSource s = classes[i].getProtectionDomain().getCodeSource();
/*
* Iterate over array of array of QAPrincipals.
*/
for (int j = 0; j < praBase.length; j++) {
/*
* Create ProtectionDomain passing code source of class,
* null as PermissionCollection, class loader of
* class and created array of QAPrincipals.
*/
ProtectionDomain pd = new ProtectionDomain(s, null,
classes[i].getClassLoader(), praa[j]);
/*
* Call implies() on DynamicPolicyProvider passing
* created ProtectionDomain and