Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / CustomTokenProvider.cs / 1 / CustomTokenProvider.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
//
// Presharp uses the c# pragma mechanism to supress its warnings.
// These are not recognised by the base compiler so we need to explictly
// disable the following warnings. See http://winweb/cse/Tools/PREsharp/userguide/default.asp
// for details.
//
#pragma warning disable 1634, 1691 // unknown message, unknown pragma
namespace Microsoft.InfoCards
{
using System;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.IdentityModel;
using System.Security.Cryptography.Xml;
using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace;
using System.Collections.ObjectModel;
using System.Collections.Generic;
//
// This class is used to provide a custom token provider for self issued card authentication
//
internal class CustomTokenProvider : SecurityTokenProvider, IDisposable
{
InfoCardPolicy m_policy;
InfoCard m_card;
IssuedSecurityTokenParameters m_parameters;
TokenDescriptor m_token;
EndpointAddress m_target;
SelfIssuedSamlTokenFactory m_tokenFactory;
bool m_isSelfIssuedCreds;
ProtocolProfile m_protocolProfile;
SelfIssuedAuthProofToken m_proofToken;
public CustomTokenProvider( IssuedSecurityTokenParameters parameters, InfoCard card, EndpointAddress target, bool isSelfIssuedCreds, ProtocolProfile profile )
{
m_isSelfIssuedCreds = isSelfIssuedCreds;
m_card = card;
m_parameters = parameters;
m_target = target;
m_protocolProfile = profile;
ValidatePolicy();
m_tokenFactory = new SelfIssuedSamlTokenFactory();
}
public void Dispose()
{
//
// We must dispose this handle explicitly.
//
if ( null != m_token )
{
m_token.Dispose();
m_token = null;
}
//
// We must dispose this proof token explicitly.
//
if ( null != m_proofToken )
{
m_proofToken.Dispose();
m_proofToken = null;
}
}
void ValidatePolicy()
{
try
{
m_policy = PolicyFactory.CreatePolicyForCustomTokenProvider( m_target, m_parameters, m_protocolProfile );
//
// For customTokenProvider, the party we're encrypting the token to, an IP/STS, is also our relying party
// for the self-issued or X509 token. So ImmediateTokenRecipient == Recipient in this case.
// Manually set the recipient cert to allow us to create the RPID, OrgId etc. subsequently
// when Validate is called.
//
m_policy.SetRecipientInfo( m_policy.ImmediateTokenRecipient, null, 0 );
//
// The custom token provider is also used in X509 creds code path
// so need to have m_isSelfIssuedCreds to distinguish the two.
//
if ( m_isSelfIssuedCreds )
{
m_policy.ThrowIfNonPpidClaimsPresent();
}
m_policy.Validate();
}
catch ( Exception e )
{
if ( IDT.IsFatal( e ) )
{
throw;
}
//
// We need to throw here.
// We do not want any other providers to
// to be able to handle this request.
//
IDT.TraceDebug( "Falied to read IP STS policy: {0}", e.ToString() );
throw IDT.ThrowHelperError( new TrustExchangeException( SR.GetString( SR.FailedReadingIPSTSPolicy ), e ) );
}
}
//
// Summary
// Retrieves a token from the system
//
// Parameters
// address - The address of the recipient
// timeout - The time span till the call times out
//
// Returns
// The security token.
//
protected override SecurityToken GetTokenCore( TimeSpan timeout )
{
//
// Retrieve a connection for the card (may be need to fetch ledger entries)
//
StoreConnection connection = StoreConnection.GetConnection();
m_card.Connection = connection;
try
{
m_token = m_tokenFactory.CreateToken( m_card, null, m_policy, false );
if ( null == m_token.SymmetricProof )
{
//
// Private because we need the private key for proof of possesion.
// The regular self-issued case does not need the private key
// in the proof crypto because we hand out the CryptoSession handle
// to do the proof of possession for us.
//
m_proofToken = new SelfIssuedAuthProofToken(
m_card.GetPrivateCryptography( m_policy.Recipient.GetIdentifier() ),
m_token.ExpirationTime );
}
else
{
m_proofToken = new SelfIssuedAuthProofToken(
new InMemorySymmetricSecurityKey( m_token.SymmetricProof.Key ),
m_token.ExpirationTime );
}
return new GenericXmlSecurityToken(
m_token.ProtectedToken,
m_proofToken,
m_token.EffectiveTime,
m_token.ExpirationTime,
new SamlAssertionKeyIdentifierClause( m_token.TokenId ),
null,
null );
}
finally
{
connection.Close();
m_card.Connection = null;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SecurityUtils.cs
- MTConfigUtil.cs
- RectAnimationBase.cs
- AccessedThroughPropertyAttribute.cs
- StackSpiller.Bindings.cs
- CatalogZone.cs
- SharedDp.cs
- DataGridTemplateColumn.cs
- HtmlButton.cs
- GroupQuery.cs
- Argument.cs
- MulticastDelegate.cs
- OptionalColumn.cs
- MembershipPasswordException.cs
- BlockCollection.cs
- InstanceStoreQueryResult.cs
- UrlMappingsSection.cs
- ScriptingRoleServiceSection.cs
- IndexingContentUnit.cs
- OLEDB_Util.cs
- DefaultPrintController.cs
- ContractMapping.cs
- SystemDiagnosticsSection.cs
- ValueTypeFieldReference.cs
- DataGridViewTopLeftHeaderCell.cs
- SafeSecurityHandles.cs
- TraceSection.cs
- AdRotatorDesigner.cs
- DataSourceHelper.cs
- StrongName.cs
- odbcmetadatafactory.cs
- DataControlCommands.cs
- SqlConnectionFactory.cs
- RecordConverter.cs
- BufferManager.cs
- DataGridViewCellPaintingEventArgs.cs
- ProcessHostConfigUtils.cs
- HScrollBar.cs
- SelectionGlyphBase.cs
- SectionInput.cs
- ContainerUtilities.cs
- GregorianCalendarHelper.cs
- DataContractSerializerOperationFormatter.cs
- SecurityPermission.cs
- StringDictionary.cs
- LabelAutomationPeer.cs
- SqlGatherProducedAliases.cs
- EditorZoneBase.cs
- SqlFacetAttribute.cs
- TimeoutTimer.cs
- DependsOnAttribute.cs
- ValidationHelpers.cs
- Font.cs
- LinqDataSourceHelper.cs
- PeerToPeerException.cs
- StrongNameUtility.cs
- WindowCollection.cs
- RegexGroup.cs
- XmlSchemaSimpleContentRestriction.cs
- EventItfInfo.cs
- MsmqPoisonMessageException.cs
- ExpressionNormalizer.cs
- ScanQueryOperator.cs
- FloatUtil.cs
- CellTreeNode.cs
- Walker.cs
- KeyEventArgs.cs
- ImportRequest.cs
- XmlSchemaCompilationSettings.cs
- FontFamily.cs
- PresentationSource.cs
- MulticastNotSupportedException.cs
- XmlSchemaGroupRef.cs
- DesignerHost.cs
- HtmlInputFile.cs
- MenuItemStyle.cs
- DayRenderEvent.cs
- OleDbTransaction.cs
- PropagatorResult.cs
- RuntimeEnvironment.cs
- Camera.cs
- SQLMembershipProvider.cs
- ResourceBinder.cs
- WSHttpTransportSecurityElement.cs
- AnnotationResourceCollection.cs
- ManipulationDeltaEventArgs.cs
- SplineQuaternionKeyFrame.cs
- RijndaelManaged.cs
- HttpCachePolicyElement.cs
- MembershipValidatePasswordEventArgs.cs
- PermissionSetTriple.cs
- DbProviderFactories.cs
- PageStatePersister.cs
- SamlAssertionKeyIdentifierClause.cs
- FloatUtil.cs
- securitycriticaldataformultiplegetandset.cs
- Transform3DGroup.cs
- Facet.cs
- ListControlBoundActionList.cs
- TaskFileService.cs