//Get the site
SSOSite ssoSite = getSSOSiteObject(site);
if (ssoSite == null)
{
throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
}
// Get the Principal information
String fullPath = ((BasePrincipal)SecurityHelper.getBestPrincipal(subject, UserPrincipal.class)).getFullPath();
try
{
// Get remotePrincipals for Site and match them with the Remote Principal for the Principal attached to site
Collection principalsForSite = ssoSite.getPrincipals();
Collection remoteForSite = ssoSite.getRemotePrincipals();
// If any of them don't exist just return
if (principalsForSite == null || remoteForSite== null )
throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
Collection remoteForPrincipals = getRemotePrincipalsForPrincipal(principalsForSite, fullPath);
if ( remoteForPrincipals == null)
throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
// Get remote Principal that matches the site and the principal
if ((remotePrincipal = FindRemoteMatch(remoteForPrincipals, remoteForSite)) == null )
{
throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
}
// Update assocation tables
ssoSite.getRemotePrincipals().remove(remotePrincipal);
getRemotePrincipalsForPrincipal(principalsForSite, fullPath).remove(remotePrincipal);
// delete the remote Principal from the SECURITY_PRINCIPAL table
getPersistenceBrokerTemplate().delete(remotePrincipal);
}
catch(SSOException ssoex)
{
throw new SSOException(ssoex);
}
catch (Exception e)
{
e.printStackTrace();
throw new SSOException(SSOException.FAILED_STORING_SITE_INFO_IN_DB + e.toString() );
}
// Update database
try
{
getPersistenceBrokerTemplate().store(ssoSite);
}
catch (Exception e)
{
e.printStackTrace();
throw new SSOException(SSOException.FAILED_STORING_SITE_INFO_IN_DB + e.toString() );
}
// Clear cache
// this.mapSite.clear();
}