Tuesday, 26 July 2011

Acces Denied - Secure Store Service

Hi Friends and Neiughbours,

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.






Thursday, 21 July 2011

Simply use of EFM and Lambda

Recently I had a request from a client to make enhancements to an existent application. They wanted to add more options to two lists, drop down lists.

One of these lists contain countries where their products were manufactured. In the original list there were around 37 countries. They wanted to add more countries to this list. However there was a catch

The data for the countries drop down list is stored on a table called Countries. 



Now there is the need to add more countries to the list, say 160 more countries.
The only issue is that, the main table, let’s called products already got rows of data pointing to the country id of the Country table.
For example several of the products have a 7 on their MANUFACTARED_ID column meaning these product are manufactured in Denmark. We can’t slide new countries between the existing ones. The current relationship of the product and the countries were they are manufacture would be broken!
What about putting the new countries, 160 right in the end of the table?
In this way the existing countries keep their ID’s and any references to this id, COUNTRY_ID, by any of our database entities remain valid.

This is a potential solution; the only issue with this approach is that all the new countries will come last!
So if Albania and Afghanistan are added they will not come before Australia but they will be placed all the way down the list.

So what we need to do is to modify the code so we retrieve and sort the countries before we populate the drop down list. By the way the existing code didn't sort the countries so We need to change this:

public List RetrieveCountries() {
List countriesList = ubfContext.Countries.ToList();
}
We simply add a lambda expression a pass it to the Entity Framework query:

public List RetrieveCountries() {
var countries = ubfContext.Countries.OrderBy(country => country.COUNTRY_NAME);
return countries.ToList();
}


Even that Albania and Afghanistan , and all the other new countries, were placed after the existent countries in the Country table They are being displayed, in the list, in the right order.

Saturday, 2 July 2011

How to remove a SharePoint Shared Services Provider (SSP)

Warning
It is not a good idea to remove the SSP once MOSS 2007 is hosting functional web applications.


This tip is for removing a SharePoint Shared Service Provider which is not working correctly due to misconfiguration issues during its installation or configuration

As the name implies Shared Services Provider manages and provides several services to all web applications running on a given MOSS installation.

Some of these services are: Profile import, search , all Excel services.

Each of the web applications on MOSS 2007 don't handle the above services by themselves but rather they go to the provider of these services: SharePoint Services provider.

Some times after installing and configuring the SSP you may notice some errors and the dreaded: "Provisioning in Progress".









As you can see from the screen shot below the delete option has been disabled










So How do we removed the SSP in order to install and configure it again?

The steps to remove the SSP are the following:

1. Obtain the GUID of the SSP.

This can be done by clicking on the 'properties' option of the menu








SSP GUID










2. Now that we have the guid we just append this GUID to the Admin delete page:
So ...../_admin/deletessp.aspx
becomes ...../_admin/deletessp.aspx?sspId=d578f420-9a85-4b78-b43d-e704576a6453






When removing the SSP We just need to make sure we select the option "Remove and delete the associated databases" to avoid having orphans databases.

Friday, 17 June 2011

Advance usage analysis for a SharePoint 2007 Site

Hi Friends and Neighbours,

MOSS 2007 have an advanced usage analysis report for site collection. These features are not turn on by default. We, as consultant, need to do this as part
of the installation or support procedure. These features will empower our clients to have access to stats report of their sites.


Using SharePoint(MOSS only) in-built usage report feature

SharePoint(MOSS version) lets you to view usage analysis reports for a site collection.Check that the following setting are turned on bLink home site collection:

1) In Shared Services Providers "Advanced usage analysis processing" should be enabled.
2) In Central Administration < Operation , "enable logging and usage analysis processing" should be enabled

Using LogParser


If these features are disabled on the target SharePoint collection, usage stats can be collected from IIS.
Remember that any SharePoint site run on top of IIS.

The Dark side of the Force has a mighty weapon on its disposal to query any log produced by Windows:

Log parser is a powerful, versatile tool that provides universal query access to text-based data such as log files, XML files and CSV files, as well as key data sources on the Windows operating system such as the Event Log, the Registry, the file system, and Active Directory

You can download LogParser by clicking on this link: Download it

There are different stats which can be generated by using different LogParser queries:







Top bandwidth usage by URL  SELECT top 50 DISTINCT  SUBSTR(TO_LOWERCASE(cs-uri-stem), 0, 55) AS Url,  Count(*) AS Hits,  AVG(sc-bytes) AS AvgBytes,  SUM(sc-bytes) as ServedBytes  FROM {filename}  GROUP BY Url  HAVING Hits >= 20  ORDER BY ServedBytes DESC url                                                   hits  avgbyte  served -------------------------------------------------     ----- -------  ------- /favicon.ico                                          16774 522      8756028 /content/img/search.png                               15342 446      6842532  



You can find some LogParse queries by following this link