Last week I had the task of fixing a bug with a SharePoint application. This application was recently ported from 2007 to 2010. The application connects to a third party Java web application, JIRA, using SharePoint Secure Store Service. If you don't know what JIRA is check it out here: http://en.wikipedia.org/wiki/JIRA
As you know Security Store Service replaced Microsoft Office SharePoint Server 2007 Single Sign On feature.
This SharePoint application has a cool feature that allows individual users to map their SharePoint account to JIRA. The user only has to specify her JIRA credentials, user name and password, and these details are saved into the Secure Store service of SharePoint 2010.
The bug was that the UI was telling the users that their credentials were being saved when in fact they weren't.
After spending some time debugging the application I found out that an exception was not being handled correctly. Once that I introduced the right exception handler to the code I could see that I was getting an "Access Denied" message. The previous code had two fault:
1. Catching the exception with a generic Exception object.
2. Not propagating the Exception message to the UI.
This is the previous code:
public static void SetCredentials(string sharePointUserName,string userName, string userPassword, string targetApplicationID)
..............
{
SPClaim claim = SPClaimProviderManager.CreateUserClaim(currentuser, SPOriginalIssuerType.Windows);
SecureStoreServiceClaim ssClaim = new SecureStoreServiceClaim(claim);
SPServiceContext context =t
SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);
SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
ISecureStore iss = ssp.GetSecureStore(context);
iss.SetUserCredentials(targetApplicationID, ssClaim, credentials);
}
catch (Exception ex)
{
ErrorHelper.AppendEntryToEventVwr("SharePoint Application", ex, string.Empty);
}
finally
{
SPContext.Current.Site.RootWeb.AllowUnsafeUpdates = false;
}
Although the code is handling the exception it only logs the error to the window registry, however it doesn't inform the user that something wrong happens.