}
}
ServerAdminApplication admin = new ServerAdminApplication(childContext,dbConfList,autodbList,storageFactory);
for (ServerConfiguration.AdminHost adminHost : serverConf.getAdminHosts().values()) {
VirtualHost vhost = createVirtualHost(adminHost);
getHosts().add(vhost);
adminRouters.add(vhost);
String authName = adminHost.getAuthName();
if (authName==null) {
getLogger().severe("The admin interface is missing a named auth service.");
continue;
}
AuthService service = services.get(authName);
if (service==null) {
getLogger().severe("Cannot find auth service "+authName+" for admin interface.");
continue;
}
UserGuard adminGuard = new UserGuard(childContext,ChallengeScheme.HTTP_BASIC,"Atom Administrator",service);
adminGuard.getRequiredGroups().add(AuthService.ADMIN_GROUP);
adminGuard.setNext(admin);
vhost.attach("/admin",adminGuard);
}
admins = new HashMap<String,Restlet>();
Restlet lastAdmin = null;
for (final DB adminDB : dbList.values()) {
getLogger().info("Configuring database "+adminDB.getName()+" for administration");
ServerConfiguration.Database databaseConf = serverConf.getDatabases().get(adminDB.getName());
AuthService service = null;
if (databaseConf==null || databaseConf.getAuthName()==null) {
service = new DBAuthService();
Properties props = new Properties();
props.setProperty("database",adminDB.getName());
props.setProperty("dir", adminDB.getDatabaseDir().getAbsolutePath());
try {
service.init(props);
} catch (AuthException ex) {
getLogger().log(Level.SEVERE,"Cannot instantiate auth service for database "+adminDB.getName(),ex);
continue;
}
} else {
service = services.get(databaseConf.getAuthName());
if (service==null) {
getLogger().severe("Cannot find auth service "+databaseConf.getAuthName()+" for database "+adminDB.getName());
continue;
}
}
DBInfo dbinfo = new DBInfo(adminDB.getName(),adminDB,service,databaseConf==null ? null : databaseConf.getGroup(),databaseConf==null ? null : databaseConf.getGroupAlias());
dbConfList.put(dbinfo.getName(),dbinfo);
UserGuard adminGuard = new UserGuard(childContext,ChallengeScheme.HTTP_BASIC,"Atom Administrator",service);
adminGuard.getRequiredGroups().add(AuthService.ADMIN_GROUP);
try {
adminGuard.setNext(new AdminApplication(childContext,adminDB,storageFactory.getStorage(adminDB),AtomApplication.RESOURCE_BASE));
admins.put(adminDB.getName(),adminGuard);
for (Router router : adminRouters) {
router.attach("/admin/database/"+adminDB.getName(),adminGuard).getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
}
lastAdmin = adminGuard;
} catch (Exception ex) {
getLogger().log(Level.SEVERE,"Cannot add admin due to exception.",ex);
}
}
// Add the configured hosts
for (ServerConfiguration.Host hostConf : serverConf.getHosts().values()) {
VirtualHost vhost = createVirtualHost(hostConf);
getHosts().add(vhost);
try {
configure(vhost,hostConf);
} catch (Exception ex) {
getLogger().log(Level.SEVERE,"Cannot configure host "+hostConf.getName()+" due to exception.",ex);
}
}
// Add the configured hosts
for (ServerConfiguration.ResourceHost resourceConf : serverConf.getResourceHosts().values()) {
VirtualHost vhost = createVirtualHost(resourceConf);
getHosts().add(vhost);
try {
configureResource(vhost,resourceConf);
} catch (Exception ex) {
getLogger().log(Level.SEVERE,"Cannot configure host "+resourceConf.getName()+" due to exception.",ex);