}
catch (SSOException ssoex)
{
System.out.println("SSO Credential add FAILED for user:" + TEST_USER + " site: " + TEST_URL);
ssoex.printStackTrace();
throw new Exception(ssoex.getMessage());
}
}
else
{
System.out.println("SSO Credential found for user:" + TEST_USER + " site: " + TEST_URL);
}
// Add another remote principal for the same user
if (ssoBroker.hasSSOCredentials(subject, TEST_URL2) == false)
{
System.out.println("No SSO Credential for user:" + TEST_USER + " site: " + TEST_URL2);
// Add credential
try
{
ssoBroker.addCredentialsForSite(subject, REMOTE_USER2, TEST_URL2, REMOTE_PWD_2);
ssoBroker.setRealmForSite(TEST_URL2, "Nagios Access");
System.out.println("SSO Credential added for user:" + TEST_USER + " site: " + TEST_URL2);
}
catch (SSOException ssoex)
{
System.out.println("SSO Credential add FAILED for user:" + TEST_USER + " site: " + TEST_URL2);
ssoex.printStackTrace();
throw new Exception(ssoex.getMessage());
}
}
else
{
System.out.println("SSO Credential found for user:" + TEST_USER + " site: " + TEST_URL2);
}
// Add the credentail again -- should get an error
try
{
ssoBroker.addCredentialsForSite(subject, REMOTE_USER2, TEST_URL2, REMOTE_PWD_2);
throw new Exception("Added same credentail twice -- API should prevent users from doing that.");
}
catch (SSOException ssoex)
{
System.out.println("Adding same SSO Credential twice failed (as expected) Message :" + ssoex.getMessage());
}
catch (Exception e)
{
throw new Exception("Adding SSO Credential twice throw an unandled exception. Error: " + e.getMessage());
}
// Test if the credential where persisted
// Test credential update
SSOContext ssocontext = ssoBroker.getCredentials(subject, TEST_URL);
System.out.println("SSO Credential: User:" + ssocontext.getRemotePrincipalName() + " Password: "
+ ssocontext.getRemoteCredential() + " for site: " + TEST_URL);
SSOContext ssocontext2 = ssoBroker.getCredentials(subject, TEST_URL2);
System.out.println("SSO Credential: User:" + ssocontext.getRemotePrincipalName() + " Password: "
+ ssocontext.getRemoteCredential() + " for site: " + TEST_URL2);
try
{
// Update Remote credential
System.out.println("SSO Credential Update");
ssoBroker.updateCredentialsForSite(subject, REMOTE_USER, TEST_URL, REMOTE_PWD_2);
ssocontext = ssoBroker.getCredentials(subject, TEST_URL);
System.out.println("SSO Credential updated: User:" + ssocontext.getRemotePrincipalName() + " Password: "
+ ssocontext.getRemoteCredential());
}
catch (SSOException ssoex)
{
System.out.println("SSO Credential update FAILED for user:" + TEST_USER + " site: " + TEST_URL);
throw new Exception(ssoex.getMessage());
}
/*
* For hypersonic the cascading deletes are not generated by Torque and the remove credentials fails with a
* constraint error. Comment test out for M1 release but the problem needs to be addressed for the upcoming
* releases try { // Remove credential for Site ssoBroker.removeCredentialsForSite(subject, TEST_URL);
* System.out.println("SSO Credential removed for user:" + TEST_USER+ " site: " + TEST_URL); }
* catch(SSOException ssoex) { System.out.println("SSO Credential remove FAILED for user:" + TEST_USER+ " site: " +
* TEST_URL); throw new Exception(ssoex.getMessage()); }
*/
Iterator sites = ssoBroker.getSites("");
while (sites.hasNext())
{
SSOSite site = (SSOSite) sites.next();
System.out.println("Site = " + site.getName());
}
// Cleanup
try
{
ssoBroker.removeCredentialsForSite(subject, TEST_URL);
ssoBroker.removeCredentialsForSite(subject, TEST_URL2);
System.out.println("SSO Credential removed for user:" + TEST_USER+ " sites: " + TEST_URL + " " + TEST_URL2);
}
catch(SSOException ssoex)
{
System.out.println("SSO Credential remove FAILED for user:" + TEST_USER+ " site: " + TEST_URL + " and " + TEST_URL2);
throw new Exception(ssoex.getMessage());
}
}