Policy defPolicy = new PolicyFileProvider(defPolicyFile);
Policy dynLdrPolicy = new DynamicPolicyProvider(ldrPolicy);
Policy dynDefPolicy = new DynamicPolicyProvider(defPolicy);
DynamicPolicy[] dp = {
new LoaderSplitPolicyProvider(parentLdr, ldrPolicy, defPolicy),
new LoaderSplitPolicyProvider(parentLdr, dynLdrPolicy, defPolicy),
new LoaderSplitPolicyProvider(parentLdr, ldrPolicy, dynDefPolicy)
};
for (int i = 0; i < dp.length; i++) {
if (dp[i].grantSupported()) {
throw new TestException("grant is not supported by " + dp[i]);
}
try {
dp[i].grant(fooCl, null,
new Permission[]{ new RuntimePermission("Q") });
throw new TestException("RuntimePermission is granted by "
+ dp[i]);
} catch (UnsupportedOperationException e) {
}
}
LoaderSplitPolicyProvider pol = new LoaderSplitPolicyProvider(
parentLdr, dynLdrPolicy, dynDefPolicy);
ProtectionDomain myPd =
LoaderSplitPolicyProviderTest.class.getProtectionDomain(),
fooPd = fooCl.getProtectionDomain(),
barPd = barCl.getProtectionDomain(),
nullPd = new ProtectionDomain(
new CodeSource((URL) null,
(java.security.cert.Certificate[]) null),
null, null, null);
Permission perm = new RuntimePermission("defaultPolicyStatic");
if (!pol.implies(myPd, perm) ||
pol.implies(fooPd, perm) ||
pol.implies(barPd, perm) ||
pol.implies(nullPd, perm))
{
throw new TestException(
"Does not satisfy implies conditions for " + perm + ".");
}
if (!contains(pol.getPermissions(myPd), perm) ||
contains(pol.getPermissions(fooPd), perm) ||
contains(pol.getPermissions(barPd), perm) ||
contains(pol.getPermissions(nullPd), perm))
{
throw new TestException(
"Does not satisfy getPermissions conditions for " + perm
+ ".");
}
if (!(contains(pol.getPermissions(myPd.getCodeSource()), perm) &&
contains(pol.getPermissions(fooPd.getCodeSource()), perm) &&
contains(pol.getPermissions(barPd.getCodeSource()), perm) &&
contains(pol.getPermissions(nullPd.getCodeSource()), perm)))
{
throw new TestException(
"Does not satisfy getPermissions & getCodeSource "
+ "conditions for " + perm + ".");
}
perm = new RuntimePermission("defaultPolicyGrant");
((DynamicPolicy) dynDefPolicy).grant(
null, null, new Permission[]{ perm });
if (!pol.implies(myPd, perm) ||
pol.implies(fooPd, perm) ||
pol.implies(barPd, perm) ||
pol.implies(nullPd, perm))
{
throw new TestException("Does not satisfy implies conditions for "
+ perm + ".");
}
if (!contains(pol.getPermissions(myPd), perm) ||
contains(pol.getPermissions(fooPd), perm) ||
contains(pol.getPermissions(barPd), perm) ||
contains(pol.getPermissions(nullPd), perm))
{
throw new TestException(
"Does not satisfy getPermissions conditions for " + perm
+ ".");
}
perm = new RuntimePermission("loaderPolicyStatic");
if (pol.implies(myPd, perm) ||
!pol.implies(fooPd, perm) ||
!pol.implies(barPd, perm) ||
!pol.implies(nullPd, perm))
{
throw new TestException("Does not satisfy implies conditions for "
+ perm + ".");
}
if (contains(pol.getPermissions(myPd), perm) ||
!contains(pol.getPermissions(fooPd), perm) ||
!contains(pol.getPermissions(barPd), perm) ||
!contains(pol.getPermissions(nullPd), perm))
{
throw new TestException(
"Does not satisfy getPermissions conditions for " + perm
+ ".");
}
if (contains(pol.getPermissions(myPd.getCodeSource()), perm) ||
contains(pol.getPermissions(fooPd.getCodeSource()), perm) ||
contains(pol.getPermissions(barPd.getCodeSource()), perm) ||
contains(pol.getPermissions(nullPd.getCodeSource()), perm))
{
throw new TestException(
"Does not satisfy getPermissions & getCodeSource "
+ "conditions for " + perm + ".");
}
perm = new RuntimePermission("loaderPolicyGrant");
((DynamicPolicy) dynLdrPolicy).grant(
null, null, new Permission[]{ perm });
if (pol.implies(myPd, perm) ||
!pol.implies(fooPd, perm) ||
!pol.implies(barPd, perm) ||
!pol.implies(nullPd, perm))
{
throw new TestException("Does not satisfy implies conditions for "
+ perm + ".");
}
if (contains(pol.getPermissions(myPd), perm) ||
!contains(pol.getPermissions(fooPd), perm) ||
!contains(pol.getPermissions(barPd), perm) ||
!contains(pol.getPermissions(nullPd), perm))
{
throw new TestException(
"Does not satisfy getPermissions conditions for " + perm
+ ".");
}