Fish


From msdn

This piece of code will fish the saml token out of the message, assume this class has a member data of samltoken.

 


protected

override

SecurityToken
GetTokenCore(
TimeSpan
timeout)

{


if
(
this
.samlSecurityToken ==
null
)

{


lock
(
this
.samlSecurityTokenLock)


if
(
this
.samlSecurityToken ==
null
)

{


SecurityMessageProperty
securityMessageProperty =
OperationContext
.Current.RequestContext.RequestMessage.Properties.Security;


// if protection token is not found or not a SamlSecurityToken, look in supporting tokens.


if
(securityMessageProperty.ProtectionToken ==
null
|| (!(securityMessageProperty.ProtectionToken.SecurityToken
is

SamlSecurityToken
)))

{


SecurityMessageProperty
smp =
OperationContext
.Current.RequestContext.RequestMessage.Properties.Security;


if
(securityMessageProperty.HasIncomingSupportingTokens)

{


foreach
(
SupportingTokenSpecification
supportingToken
in

OperationContext
.Current.RequestContext.RequestMessage.Properties.Security.IncomingSupportingTokens)

{


if
(supportingToken.SecurityToken
is

SamlSecurityToken
)

{


this
.samlSecurityToken = supportingToken.SecurityToken
as

SamlSecurityToken
;


break
;

}

}

}

}


else


this
.samlSecurityToken = securityMessageProperty.ProtectionToken.SecurityToken
as

SamlSecurityToken
;

}


if
(
this
.samlSecurityToken ==
null
)


throw

new

Exception
(
“Expecting a valid SAML token as Protection or Supporting token.”
);

}


return

this
.samlSecurityToken;


 

Advertisements

About home_pw@msn.com

Computer Programmer who often does network administration with focus on security servers. Very strong in Microsoft Azure cloud!
This entry was posted in coding theory. Bookmark the permalink.