Wednesday, August 15, 2012

SharePoint 2010 Authentication Security


Autrzn
SP is neutral to any identity provider.
As long as SP is provided with a SAML token which matches the industry standards settings, it accepts the same .In SP you will get multi-auth web applications i.e supporting various authzn. providers.This will show up in the Login page.


For custom Access Denied page :
Central Admin -- default login page or you can specify URL for the page that u have made.
SP is always running the STS(single token service) under the covers for us.


you can change the classic mode authn to Claims mode using Powershell.
Claims Identities provider: i.e. AD. whos is saying the username/group and the password is correct.
 






Claims Provider:
Provides claims that are adding  extra attributes/claims to the user SAML token based on business rules.depending on the token values u authrz
Claims provider tell SP : here is some info  abt the current user and trust me its correct .
Here is the info abt the user and based on the database i will populate some claims.
Its like HTTP module/handler in .Net . once the identity provider says that this is Sujoy the SP calls all the custom claims provider/providers and in that code you can add claims(eg Manager/Member/Geaography) to what you call is a  SAML token.
This is called claims augmentation.


AuthRiz.:

2 ways to accomplish the same :

People Picker
When u config claims using (FBA , Win Auth) these claims are going to show up in the ppl picker.So u can authrz depending on the claims.
The code that he has written generates 2 claims : manager, member claim.
So in can Authz according to what comes up as claim
In the code there is Linq to SQL as SPMetal has been used for getting data from the database that contains user data .


The business req  as shown in the video:
 if the user comes in thru  windows auth then the user is a manager
Else
 the user comes in thru the FBA then  the user needs to be verified against the db.i.e.member





Uses of Claims

For Datagrid to display all claims that are there on the site
 After the code walkthru.He is authorizing the data based on claims.

2 scenarios ;

Scenario 1 :if its  SP object (site/list /folder/item) then you can use the ppl picker.

Scenario 2 :However,if this is a webpart  and the ppl picker is not best for that.(cant secure a webpart).here u can inspect claims for the current user  and then render information accordingly.This is a authrz piece that will be v helpful.Uses custom code and then you can inspect the claims


Hence there are 2 things that claims provider can do :
1>Augment the token/claim and make that show in the  people picker.
2>Claims Picker.



Steve Peschka -- blogs v usefull.
msdn.microsoft.com/en-us/library/ff699494.aspx

When some launches the ppl picker then the code goes thru the config file to find out the claims provder/provders that are registered/listed here.The claims are
picked up and added to the SAML token

FillResolve : When some 1 checks the check box infront of the name that is there in the people picker
FillSearch  : when some types in the first letter in the searchbox of the claim(say m) and then hits search and the matching items come out.

CreateClaims() inbuilt method is used for the creation of claims .Helper methods should be used during coding.


Conclusions :
Provisioning permissions based on an attribute of the user, instead of on who the user is, opens many possibilities. It can mean, as it does in this scenario, that I do not care who you are. I do not care how you logged in. I do not care whether you are a Windows user
or a forms-based authentication user.

All I care about is who your favorite basketball team is.
Here is a classic problem from Microsoft Office SharePoint Server 2007 that still exists in SharePoint 2010—when I am at work, I log on to my SharePoint site by using my Windows credentials, Steve Peschka. But when I go home, I hit the site via our extra net and I must use forms-based authentication.

For our custom claims provider to support search, we must add support for the following properties and
methods of the SPClaimProvider class: SupportsSearch, SupportsResolve, FillSearch, FillResolve (the overload with SPClaim as an input parameter), FillSchema, and FillEntityTypes.


For Authnt/identity provider use the WIF classes.


=====================================================

User identity in Active Directory Domain Services (AD DS) is based on a user account. For successful authentication, the user provides the account name and proof of knowledge of the password. AD DS for account attributes and other information, such as group.

Claims-based identity is based on the user obtaining a security token that is digitally signed by a commonly trusted identity provider and contains a set of claims. Each claim represents a specific item of data about the user such as his or her name, group memberships, and role on the network Claims-based authentication in Windows is built on Windows Identity Foundation (WIF), which is a set of .NET Framework classes that is used to implement claims-based identity. Claims-based authentication relies on standards such as WS-Federation, WS-Trust, and protocols such as SAML.
If you select Claims-Based Authentication, SharePoint Server 2010 automatically changes all user accounts to claims identities, resulting in a claims token for each user. The claims token contains the claims pertaining to the user. Windows accounts are converted into Windows claims. Forms-based membership users are transformed into forms-based authentication claims. Claims that are included in SAML-based tokens can be used by SharePoint Server 2010. Additionally, SharePoint developers and administrators can augment user tokens with additional claims. For example, Windows user accounts and forms-based accounts can be augmented with additional claims that are used by SharePoint Server 2010.

Forms-based authentication is an identity management system that is based on ASP.NET membership and role provider authentication. In SharePoint Server 2010, forms-based authentication is available only when you use claims-based authentication. 


Secure Store Service(STS)
In Microsoft SharePoint Server 2010, the Secure Store Service replaces the single sign-on (SSO) feature of Microsoft Office SharePoint Server 2007. The Secure Store Service is a claims-aware authorization service that includes a secure database for storing credentials.
The Secure Store Service is an authorization service that runs on an application server. The Secure Store Service provides a database that is used to store credentials. These credentials usually consist of a user identity and password, but can also contain other fields that you define. For example, SharePoint Server 2010 can use the secure store database to store and retrieve credentials for access to external data sources. The Secure Store Service provides support for storing multiple sets of credentials for multiple back-end systems.

Usage :

Microsoft Business Connectivity Services    Can use Secure Store to map the user’s credentials to a set of credentials for an external system. You can either map each user’s credentials to a unique account on the external system or you can map a set of authenticated users to a single group account.

PerformancePoint Services    Requires Secure Store if you want to configure an unattended service account for data authentication.
Similarly it can be used for the same in the PowerPivot for SharePoint 2010,Excel Services,Visio Services

SharePoint 2010 Search

good course on Search :

http://msdn.microsoft.com/en-us/sp2010devtrainingcourse_extendingsharepointsearchlab_topic2

Scott Hillier speak on the search in SP 2010 is being noted below and I am a fan of this persons speaking

Managed Property

We create a managed property 'Avg Rating' and map it one to one with the crawled property OSS-AvgRating.
The Managed Property is kind of the HumanReadable property that u would like to map with the crawled property that is
fetched and indexed from the 3rd party data source.

Imp : A crawler crawls and fetches data from any ext sources in a raw form . Say crawled database gets info regarding geographies .Some call their geography USA,Some America,others come from Asia ,others from japan .
All of these can be grouped into one term called 'address' which can be in the managed database.So its a mapping from the crawled db to the managed db. 

Relevancy

When/while searching we have to increase relevancy
Ranking and Sorting :
Relevancy  is like a spice in the meal. u are nudging the item to be more relevant and then it will appear in the
search


Authoratative pages :

SSA and u can tell certain pages to be  authoritative page.So the docs will spear at the top
****** -- dint understand much

Custom Ranking models : new in SP 2010
Query independent element : no matter what the user type s (say) xml/doc elements are pushed to the top .
Q dependant element  : depending on the keyword that was typed.it rises to the top.

You have to enable the SpEnterprise SeachManagedproperty is explicitly use the managed property in the ranking model.
The next step is to create the ranking model which is nothing but an xml file as shown in the below screen shot . 

Here the 'body' is give '0' weight  in the query independent feature
BUt the q dependent feature is given the weight which is required here .
PID is the property id of the managed property that u care about.U can get the same using PowerShell

XML for Ranking Model





AFTER THATS DONE WE WILL HAVE to display the same using the searchCore Results webPart.SP has 6-7 OOB ranking models.There is a default ranking model that can be setup for this WEbP.The rest of the  6 of them are people search.We can get a list of SharePoint ranking models. Also we get the id related to each of those models .

CoreSearchResults Webp uses XSLT for the same .Value of the avg rating columns and    
Export the  webpart.Open the same and search for the 'DefaultrankingModel Property'change the value from and empty string to the GUID models that pwershell was used for installation, a few minutes back.

Search CR Webpart

Combination of PowerShell commands

Some results from the search :
suppose u type in
a* AverageRating>0

The search return the results after going through the ranking model and the index associated with the same.

Suppose u type in
AverageRating>0
Then the search only goes through the managed property database and not thru the ranking model/index etc.Its faster.
Reason : There is no value typed in  before the 'AverageRating' .Hence the search doesnt go deep .


Customizing Search center


In SP 2010 we can get involved in the search pipeline before the query is executed(before its fed into the search) and even after the query has been run(display of results using the XSLT).

All 'Site Content' , we can get the searachresults tab and the Searchtab. When we  edit the same we can see that they are tied to diff aspx pages .ie, Search Results.aspx and Search.aspx






The key new thing in SP 2010  is that we can inherit from the CorResultsWebpart and create a webpart based on the same.Inside the same we can create the object of the Query manager class and then create a query for the same.QM object allows u to insert/manipulate the pipeline before the query is executed.
Here in the picture is the 'Assigned To' managed property that we are targeting.




.Net asembly connector =  BCS model
It exposes the External system to crawling .
We can create custom connectors

BCS Allows    u to search external system.So in this example we search a external doc system for searching something . its external to SP so we will use BCS for the same .The solution here is that we  have the option of searching a doc and being able to open the doc.
We create an ECT -- is like a regular content type(doc/task CT).It represented fields from the external system and the operations that we can perform on that external doc system.So BCS creates an service class that is used to read the data that we want to.

Friday, July 27, 2012

SP Workflows


wonderfull blog abt WF

http://sergeluca.wordpress.com/2011/02/13/step-by-step-tutorial-creating-workflows-for-sharepoint-2010-retrieving-list-items-step-215/
 
Pluggable WF :
http://sandhoo.wordpress.com/2010/05/26/sharepoint-2010-pluggable-workflow-services-with-correlation-and-external-callbacks/

SP2010 improvements in WF :
http://msdn.microsoft.com/en-us/magazine/ee335710.aspx

Windows WF tutorial :
http://msdn.microsoft.com/en-us/library/dd692929

A sequential workflow moves to the next activity when it is finished executing the previous activity.
A state machine workflow typically moves to a different state when an external action occurs. This external action can be the host application raising an event handled by the workflow. The action can also be the host application pro grammatically setting the next state. You can also use the SetState activity in the workflow to move to a new state.

New in SP 2010 :

SharePoint Designer 2010 includes a new task process designer. that creates an activity in the workflow but allows flexibility in how you manage the approval process all within that one activity. This includes defining escalation processes, delegation, defining approval requirements and semantics of what happens if the underlying document is changed during the approval.
  • Site WF
  • List WF
  • Reusable Declarative  workflow : The workflow design can be reused and associated with multiple lists. Also, the Save as Template command can be usedto create a WSP file containing a reusable workflow which can be moved to another SharePoint server or to Visual Studio2010
  • High Privilege Workflows :In SharePoint 2007, workflows ran as the identity of the logged on user. In SharePoint 2010, with high privilege workflows you can specify an account to run a workflow as to give it additional needed permissions (see Figure 3). When creating a workflow in SharePoint Designer 2010, individual steps can be added that enable it to run as the author of the workflow instead of the logged on user.
  • Workflow Messaging Improvements    SharePoint 2010 adds four new workflow Event Receivers for list based workflows. The four workflow event receivers available are Starting, Started, Postponed and Completed .These are similar to other SharePoint event receivers and they execute code on the server in response to the even.These  events canb be associated with list only.The new events attach to a specific list.
  • Pluggable workflow services :   are defined by creating an interface containing methods and events. This interface is connected to a pair of activities called CallExternalMethod and HandleExternalEvent..Using these new activities, you can send asynchronous messages to an external system right from within the SharePoint  workflow
Correlation Tokens
If you’ve ever created a workflow in SharePoint, then you’ve used correlation tokens with almost every SharePoint related activity, such as CreateTask. So why is correlation needed in your custom local communication service definition? Basically it is a mechanism that allows the workflow runtime to route inbound messages to the correct instance of the persisted activities.if you have more than one activity that is waiting for external communication events. If you are writing a pluggable workflow service and have multiple HandleExternalEvent activities of the same interface type and operation, then you need to provide correlation token capabilities. If you don’t have more than one activity instance in the same workflow persisted and waiting on a particular event, then you don’t have to worry about correlation tokens 

Steps for Sequential WF :
Seq  WF
Step 1 - Create a new SharePoint Sequential Workflow project








The first activity (step) of a (Visual Studio) Sharepoint workflow must be an OnWorkflowActivated activity.

The Sharepoint team also provided more specific Sharepoint activities : you will find them in Microsoft.Sharepoint.WorkflowActions assembly; this assembly can be found in the 14\ISAPI folder and is referenced by default in our Visual Studio 2010 project (figure 19).
These activities can be dragged & drop to the Visual Studio Workflow designer surface from the toolbox (select the panel Sharepoint Workflow):




Step 2 – Add an initiation form to the workflow
Select the Workflow Initiation Form template and the new form is automatically associated with the workflow. It is an ASPX form that you edit in HTML (see Figure 11).
Step 3 – Add a workflow log activity
Step 4 – Add a CreateTask activity
 Here  :: A correlation token is used for message correlation in workflow. It provides a unique identifier that enables a mapping between a task object in a specific workflow instance and the workflow runtime in SharePoint. This is used so that when SharePoint receives a message for the workflow instance it can locate the correct task within the correct workflow instance. The CorrelationToken property must be configured and it’s not recommended to use the WorkflowToken for tasks, although this isn’t prevented in the tool. Enter the new name for the correlation token as TaskToken and press enter. Then expand the (+) symbol which appears and click the drop down to the right of OwnerActivityName and choose the workflow.
Step 5 – Add the OnTaskChanged and CompleteTask activities
    Use the While activity to wait for multiple changes to the task until you see the changes you want. The While activity must contain another activity, such as the OnTaskChanged activity. The Listen activity can also be used to listen for multiple events at one time by adding a Listen activity with actual event receiver activities inside the Listen branches. Alternatively, you can just wait until the task is deleted with the OnTaskDeleted activity.  A common requirement is to escalate or timeout waiting for an event. This is done by using a Listen activity to listen for both the task changed message and a timer message by using a Delay activity. The first message to be received by either contained activity resumes the workflow and the other activity stops waiting. The Delay activity is sent a message when the timeout occurs
    There are lots of options described above but the simplest is to use OnTaskChanged which will wait for any change to the task item and then continue on. To configure the OnTaskChanged, you need to wire up the CorrelationToken and the TaskId properties to the same fields as the CreateTask.
Step 6 – Deploy and Test the Workflow


Steps for Pluggable WF Service :

Step 1 – Create a Pluggable Workflow Service
Step 2 – Update the web.config
Step 3 – Create the workflow model
Step 4 – Run the workflow