}
protected SSOSite addSite(Long ownerDomainId, SSOSite site) throws SSOException
{
if (domainAccessManager.getDomainByName(site.getName()) != null){
throw new SSOException(SSOException.SITE_ALREADY_EXISTS);
}
SecurityDomainImpl sd = new SecurityDomainImpl();
sd.setName(site.getName());
sd.setOwnerDomainId(ownerDomainId);
sd.setEnabled(true);
sd.setRemote(true);
try{
domainStorageManager.addDomain(sd);
} catch(SecurityException sx){
log.error("Could not add remote security domain with name "+site.getName()+" for owner domain "+ownerDomainId);
throw new SSOException(SSOException.SITE_COULD_NOT_BE_CREATED,sx);
}
SecurityDomain storedDomain = domainAccessManager.getDomainByName(site.getName());
if (storedDomain == null || storedDomain.getDomainId() == null){
throw new SSOException(SSOException.SITE_COULD_NOT_BE_CREATED);
}
site.setSecurityDomainId(storedDomain.getDomainId());
try{
return ssoSiteManagerSPI.add(site);
} catch (SSOException se){
// catch SSO Exception to remove already stored domain.
try{
domainStorageManager.removeDomain(storedDomain);
} catch (SecurityException secex){
}
// rethrow exception
throw new SSOException(se);
}
}