Admin admin = new Admin(Admin.TYPE_CACOMMANDLINE_USER);
// Initialize with a new CA
adminGroupSession.init(admin, caid, DEFAULT_SUPERADMIN_CN);
// Retrieve access rules and check that they were added
AdminGroup ag = adminGroupSession.getAdminGroup(admin, AdminGroup.PUBLICWEBGROUPNAME);
assertNotNull(ag);
Collection<AccessRule> rules = ag.getAccessRules();
assertEquals("Number of available access rules for AdminGroup.PUBLICWEBGROUPNAME was not the expected.", 8, rules.size());
// Add some new strange access rules
ArrayList<AccessRule> accessrules = new ArrayList<AccessRule>();
accessrules.add(new AccessRule("/public_foo_user", AccessRule.RULE_ACCEPT, false));
accessrules.add(new AccessRule("/foo_functionality/basic_functions", AccessRule.RULE_ACCEPT, false));
accessrules.add(new AccessRule("/foo_functionality/view_certificate", AccessRule.RULE_ACCEPT, false));
adminGroupSession.addAccessRules(admin, AdminGroup.PUBLICWEBGROUPNAME, accessrules);
// Retrieve the access rules and check that they were added
ag = adminGroupSession.getAdminGroup(admin, AdminGroup.PUBLICWEBGROUPNAME);
assertNotNull(ag);
rules = ag.getAccessRules();
assertEquals(11, rules.size()); // We have added three rules
Iterator<AccessRule> iter = rules.iterator();
boolean found = false;
while (iter.hasNext()) {
AccessRule rule = iter.next();
if (rule.getAccessRule().equals("/foo_functionality/view_certificate")) {
found = true;
}
}
assertTrue(found);
// Initialize the same CA again, this will remove old default Public Web
// rules and create new ones.
// This had some troubles with glassfish before, hence the creation of
// this test
adminGroupSession.init(admin, caid, DEFAULT_SUPERADMIN_CN);
// Retrieve access rules and check that we only have the default ones
ag = adminGroupSession.getAdminGroup(admin, AdminGroup.PUBLICWEBGROUPNAME);
assertNotNull(ag);
rules = ag.getAccessRules();
assertEquals(8, rules.size());
iter = rules.iterator();
found = false;
while (iter.hasNext()) {
AccessRule rule = (AccessRule) iter.next();