* Tests DatabasePermission.
*/
private void checkDatabasePermission() throws IOException {
// test DatabasePermission with null url
try {
new DatabasePermission(null, DatabasePermission.CREATE);
fail("expected NullPointerException");
} catch (NullPointerException ex) {
// expected exception
}
// test DatabasePermission with empty url
try {
new DatabasePermission("", DatabasePermission.CREATE);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected exception
}
// test DatabasePermission with illegal url
try {
new DatabasePermission("no_url", DatabasePermission.CREATE);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected exception
}
// test DatabasePermission with non-canonicalizable URL
try {
new DatabasePermission("directory:.*/\\:///../",
DatabasePermission.CREATE);
fail("expected IOException");
} catch (IOException ex) {
// expected exception
}
// test DatabasePermission with null actions
try {
new DatabasePermission("directory:dir", null);
fail("expected NullPointerException");
} catch (NullPointerException ex) {
// expected exception
}
// test DatabasePermission with empty actions
try {
new DatabasePermission("directory:dir", "");
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected exception
}
// test DatabasePermission with illegal action list
try {
new DatabasePermission("directory:dir", "illegal_action");
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected exception
}
// test DatabasePermission with illegal action list
try {
new DatabasePermission("directory:dir", "illegal,action");
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected exception
}
// test DatabasePermission on illegal action list
try {
new DatabasePermission("directory:dir", "illegal;action");
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected exception
}
// test DatabasePermission on relative directory paths
final DatabasePermission[] relDirPathPermissions
= new DatabasePermission[relDirPaths.length];
for (int i = 0; i < relDirPaths.length; i++) {
relDirPathPermissions[i]
= new DatabasePermission(relDirPaths[i],
DatabasePermission.CREATE);
}
checkNameAndActions(relDirPathPermissions,
relDirPaths);
checkHashCodeAndEquals(relDirPathPermissions,
relDirPathPermissions);
checkImplies(relDirPathPermissions,
relDirPathPermissions);
// test DatabasePermission on relative directory path aliases
final DatabasePermission[] relDirPathAliasPermissions
= new DatabasePermission[relDirPathAliases.length];
for (int i = 0; i < relDirPathAliases.length; i++) {
relDirPathAliasPermissions[i]
= new DatabasePermission(relDirPathAliases[i],
DatabasePermission.CREATE);
}
checkNameAndActions(relDirPathAliasPermissions,
relDirPathAliases);
checkHashCodeAndEquals(relDirPathPermissions,
relDirPathAliasPermissions);
checkImplies(relDirPathPermissions,
relDirPathAliasPermissions);
// test DatabasePermission on absolute directory paths
final DatabasePermission[] absDirPathPermissions
= new DatabasePermission[absDirPaths.length];
for (int i = 0; i < absDirPaths.length; i++) {
absDirPathPermissions[i]
= new DatabasePermission(absDirPaths[i],
DatabasePermission.CREATE);
}
checkNameAndActions(absDirPathPermissions,
absDirPaths);
checkHashCodeAndEquals(absDirPathPermissions,
absDirPathPermissions);
checkImplies(absDirPathPermissions,
absDirPathPermissions);
// test DatabasePermission on absolute directory path aliases
final DatabasePermission[] absDirPathAliasPermissions
= new DatabasePermission[absDirPathAliases.length];
for (int i = 0; i < absDirPathAliases.length; i++) {
absDirPathAliasPermissions[i]
= new DatabasePermission(absDirPathAliases[i],
DatabasePermission.CREATE);
}
checkNameAndActions(absDirPathAliasPermissions,
absDirPathAliases);
checkHashCodeAndEquals(absDirPathPermissions,
absDirPathAliasPermissions);
checkImplies(absDirPathPermissions,
absDirPathAliasPermissions);
// test DatabasePermission for authorized user against policy file
final DatabasePrincipal authorizedUser
= new DatabasePrincipal("authorizedSystemUser");
execute(authorizedUser,
new CreateDatabaseAction(relDirPathPermissions[2]), true);
execute(authorizedUser,
new CreateDatabaseAction(relDirPathPermissions[3]), true);
execute(authorizedUser,
new CreateDatabaseAction(relDirPathPermissions[6]), false);
execute(authorizedUser,
new CreateDatabaseAction(relDirPathPermissions[7]), true);
// test DatabasePermission for unauthorized user against policy file
final DatabasePrincipal unAuthorizedUser
= new DatabasePrincipal("unAuthorizedSystemUser");
execute(unAuthorizedUser,
new CreateDatabaseAction(relDirPathPermissions[2]), false);
execute(unAuthorizedUser,
new CreateDatabaseAction(relDirPathPermissions[3]), false);
execute(unAuthorizedUser,
new CreateDatabaseAction(relDirPathPermissions[6]), false);
execute(unAuthorizedUser,
new CreateDatabaseAction(relDirPathPermissions[7]), false);
// test DatabasePermission for authorized user against policy file
final DatabasePrincipal anyUser
= new DatabasePrincipal("anyUser");
final DatabasePermission dbPerm
= new DatabasePermission("directory:dir",
DatabasePermission.CREATE);
execute(anyUser,
new CreateDatabaseAction(dbPerm), true);
}