* @see org.apache.jetspeed.sso.SSOProvider#addCredentialsForSite(org.apache.jetspeed.sso.SSOSite, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public void addCredentialsForSite(SSOSite ssoSite, String principalFullPath, String principalName, String remoteUser, String scrambledPwd) throws SSOException
{
// Add an entry for the principal to the site if it doesn't exist
SSOPrincipal principal = getPrincipalForSite(ssoSite, principalFullPath);
if (principal == null)
{
principal = getSSOPrincipal(principalFullPath);
ssoSite.addPrincipal(principal);
}
else
{
// Check if the entry the user likes to update exists already
Collection remoteForSite = ssoSite.getRemotePrincipals();
Collection principalsForSite = ssoSite.getPrincipals();
if (remoteForSite != null && principalsForSite != null)
{
Collection remoteForPrincipals = getRemotePrincipalsForPrincipal(principalsForSite, principalFullPath);
if (remoteForPrincipals != null)
{
if (findRemoteMatch(remoteForPrincipals, remoteForSite) != null)
{
// Entry exists can't to an add has to call update
throw new SSOException(SSOException.REMOTE_PRINCIPAL_EXISTS_CALL_UPDATE);
}
}
}
}
if (principal == null)
{
throw new SSOException(SSOException.FAILED_ADDING_PRINCIPAL_TO_MAPPING_TABLE_FOR_SITE);
}
// Create a remote principal and credentials
InternalUserPrincipalImpl remotePrincipal = new InternalUserPrincipalImpl(remoteUser);
/*
* The RemotePrincipal (class InternalUserPrincipal) will have a
* fullPath that identifies the entry as an SSO credential. The entry
* has to be unique for a site and principal (GROUP -or- USER ) an
* therefore it needs to be encoded as following: The convention for the
* path is the following: /sso/SiteID/{user|group}/{user name | group
* name}/remote user name
*/
if (principalFullPath.indexOf("/group/") > -1)
{
remotePrincipal.setFullPath("/sso/" + ssoSite.getSiteId() + "/group/" + principalName + "/" + remoteUser);
}
else
{
remotePrincipal.setFullPath("/sso/" + ssoSite.getSiteId() + "/user/" + principalName + "/" + remoteUser);
}
// New credential object for remote principal
InternalCredentialImpl credential = new InternalCredentialImpl(remotePrincipal.getPrincipalId(), scrambledPwd, 0, DefaultPasswordCredentialImpl.class.getName());
if (remotePrincipal.getCredentials() == null)
{
remotePrincipal.setCredentials(new ArrayList(0));
}
remotePrincipal.getCredentials().add(credential);
// Add it to Principals remotePrincipals list
principal.addRemotePrincipal(remotePrincipal);
// Update the site remotePrincipals list
ssoSite.getRemotePrincipals().add(remotePrincipal);
// Update principal in database, (defer site update)