本文整理汇总了C#中SecurityTokenRequirement.TryGetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityTokenRequirement.TryGetProperty方法的具体用法?C# SecurityTokenRequirement.TryGetProperty怎么用?C# SecurityTokenRequirement.TryGetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecurityTokenRequirement
的用法示例。
在下文中一共展示了SecurityTokenRequirement.TryGetProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSecurityTokenProvider
public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
{
if (String.IsNullOrWhiteSpace(tokenRequirement.TokenType) ||
tokenRequirement.TokenType == SecurityTokenTypes.Saml ||
tokenRequirement.TokenType == "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1")
{
SecurityBindingElement sbe = null;
if (!tokenRequirement.TryGetProperty<SecurityBindingElement>("http://schemas.microsoft.com/ws/2006/05/servicemodel/securitytokenrequirement/SecurityBindingElement", out sbe))
{
throw new InvalidOperationException("Could not retreive the Security Binding Element!");
}
// If the token requirement is for a SymmetricKey based token..
if (tokenRequirement.KeyType != SecurityKeyType.AsymmetricKey) throw new NotSupportedException("Only Asymmetric keys are supported");
//TODO:Add more
IssuedSecurityTokenParameters sessionTokenParams = null;
if (sbe is AsymmetricSecurityBindingElement)
{
sessionTokenParams = (IssuedSecurityTokenParameters) ((AsymmetricSecurityBindingElement)sbe).InitiatorTokenParameters;
}
if (sbe is TransportSecurityBindingElement)
{
sessionTokenParams = (IssuedSecurityTokenParameters)((TransportSecurityBindingElement)sbe).EndpointSupportingTokenParameters.Endorsing[0];
}
return new SsoSecurityTokenProvider((SsoClientCredentials)ClientCredentials, sessionTokenParams);
}
else
{
// otherwise use base implementation
return base.CreateSecurityTokenProvider(tokenRequirement);
}
}
示例2: TryGetPropertyTypeBaseMatch
public void TryGetPropertyTypeBaseMatch ()
{
SecurityTokenRequirement r =
new SecurityTokenRequirement ();
r.Properties ["urn:foo"] = 1;
object o;
r.TryGetProperty<object> ("urn:foo", out o);
}
示例3: TryGetPropertyTypeMismatch
public void TryGetPropertyTypeMismatch ()
{
SecurityTokenRequirement r =
new SecurityTokenRequirement ();
r.Properties ["urn:foo"] = 1;
string s;
r.TryGetProperty<string> ("urn:foo", out s);
}
示例4: CreateSecurityTokenAuthenticator
public override SecurityTokenAuthenticator CreateSecurityTokenAuthenticator (
SecurityTokenRequirement requirement,
out SecurityTokenResolver outOfBandTokenResolver)
{
outOfBandTokenResolver = null;
if (requirement.TokenType == SecurityTokenTypes.UserName)
return CreateUserNameAuthenticator (requirement);
if (requirement.TokenType == SecurityTokenTypes.X509Certificate)
return CreateX509Authenticator (requirement);
if (requirement.TokenType == SecurityTokenTypes.Rsa)
return new RsaSecurityTokenAuthenticator ();
if (requirement.TokenType == ServiceModelSecurityTokenTypes.SecureConversation) {
SecurityBindingElement binding;
if (!requirement.TryGetProperty<SecurityBindingElement> (ReqType.SecurityBindingElementProperty, out binding))
throw new ArgumentException ("SecurityBindingElement is required in the security token requirement");
SecureConversationSecurityTokenParameters issuedParams;
if (!requirement.TryGetProperty<SecureConversationSecurityTokenParameters> (ReqType.IssuedSecurityTokenParametersProperty, out issuedParams))
throw new ArgumentException ("IssuedSecurityTokenParameters are required in the security token requirement");
BindingContext issuerBC;
if (!requirement.TryGetProperty<BindingContext> (ReqType.IssuerBindingContextProperty, out issuerBC))
throw new ArgumentException ("IssuerBindingContext is required in the security token requirement");
SecurityTokenVersion secVer;
if (!requirement.TryGetProperty<SecurityTokenVersion> (ReqType.MessageSecurityVersionProperty, out secVer))
throw new ArgumentException ("MessageSecurityVersion property (of type SecurityTokenVersion) is required in the security token requirement");
// FIXME: get parameters from somewhere
SecurityContextSecurityTokenResolver resolver =
new SecurityContextSecurityTokenResolver (0x1000, true);
outOfBandTokenResolver = resolver;
SecurityContextSecurityTokenAuthenticator sc =
new SecurityContextSecurityTokenAuthenticator ();
return new SecureConversationSecurityTokenAuthenticator (requirement, sc, resolver);
}
if (requirement.TokenType == ServiceModelSecurityTokenTypes.AnonymousSslnego)
return CreateSslTokenAuthenticator (requirement);
if (requirement.TokenType == ServiceModelSecurityTokenTypes.MutualSslnego)
return CreateSslTokenAuthenticator (requirement);
if (requirement.TokenType == ServiceModelSecurityTokenTypes.Spnego)
return CreateSpnegoTokenAuthenticator (requirement);
else
throw new NotImplementedException ("Not implemented token type: " + requirement.TokenType);
}
示例5: CreateSecurityTokenProvider
/// <summary>
/// Creates the custom SecurityTokenProvider when SAML tokens are specified in the tokenRequirement
/// </summary>
/// <param name="tokenRequirement">A SecurityTokenRequirement </param>
/// <returns>The appropriate SecurityTokenProvider</returns>
public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
{
// If token requirement matches SAML token return the custom SAML token provider
if (tokenRequirement.TokenType == SecurityTokenTypes.Saml ||
tokenRequirement.TokenType == "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1")
{
// Retrieve the SAML assertion and proof token from the client credentials
SamlAssertion assertion = this.samlClientCredentials.Assertion;
SecurityToken prooftoken = this.samlClientCredentials.ProofToken;
// If either the assertion of proof token is null...
if (assertion == null || prooftoken == null)
{
// ...get the SecurityBindingElement and then the specified algorithm suite
SecurityBindingElement sbe = null;
SecurityAlgorithmSuite sas = null;
if (tokenRequirement.TryGetProperty<SecurityBindingElement>("http://schemas.microsoft.com/ws/2006/05/servicemodel/securitytokenrequirement/SecurityBindingElement", out sbe))
{
sas = sbe.DefaultAlgorithmSuite;
}
// If the token requirement is for a SymmetricKey based token..
if (tokenRequirement.KeyType == SecurityKeyType.SymmetricKey)
{
// Create a symmetric proof token
prooftoken = SamlUtilities.CreateSymmetricProofToken(tokenRequirement.KeySize);
// and a corresponding assertion based on the claims specified in the client credentials
assertion = SamlUtilities.CreateSymmetricKeyBasedAssertion(this.samlClientCredentials.Claims,
new X509SecurityToken(samlClientCredentials.ClientCertificate.Certificate),
new X509SecurityToken(samlClientCredentials.ServiceCertificate.DefaultCertificate),
(BinarySecretSecurityToken)prooftoken,
sas);
}
// otherwise...
else
{
// Create an asymmetric proof token
prooftoken = SamlUtilities.CreateAsymmetricProofToken();
// and a corresponding assertion based on the claims specified in the client credentials
assertion = SamlUtilities.CreateAsymmetricKeyBasedAssertion(this.samlClientCredentials.Claims, prooftoken, sas);
}
}
// Create a SamlSecurityTokenProvider based on the assertion and proof token
return new SamlSecurityTokenProvider(assertion, prooftoken);
}
// otherwise use base implementation
else
{
return base.CreateSecurityTokenProvider(tokenRequirement);
}
}
示例6: TryGetPropertyTypeConvertible
public void TryGetPropertyTypeConvertible ()
{
SecurityTokenRequirement r =
new SecurityTokenRequirement ();
r.Properties ["urn:foo"] = 1;
double d;
r.TryGetProperty<double> ("urn:foo", out d);
}
示例7: IsIssuedSecurityTokenRequirement
protected internal bool IsIssuedSecurityTokenRequirement (
SecurityTokenRequirement requirement)
{
SecurityTokenParameters ret;
if (!requirement.TryGetProperty<SecurityTokenParameters> (ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty, out ret))
return false;
return ret is IssuedSecurityTokenParameters;
}
示例8: CreateIssuedTokenProvider
IssuedSecurityTokenProvider CreateIssuedTokenProvider (SecurityTokenRequirement requirement)
{
IssuedSecurityTokenProvider p =
new IssuedSecurityTokenProvider ();
// FIXME: fill properties
EndpointAddress address;
if (requirement.TryGetProperty<EndpointAddress> (ReqType.IssuerAddressProperty, out address))
p.IssuerAddress = address;
if (requirement.TryGetProperty<EndpointAddress> (ReqType.TargetAddressProperty, out address))
p.TargetAddress = address;
Binding binding;
if (requirement.TryGetProperty<Binding> (ReqType.IssuerBindingProperty, out binding))
p.IssuerBinding = binding;
MessageSecurityVersion ver;
if (requirement.TryGetProperty<MessageSecurityVersion> (ReqType.MessageSecurityVersionProperty, out ver))
p.SecurityTokenSerializer = CreateSecurityTokenSerializer (ver.SecurityTokenVersion);
SecurityAlgorithmSuite suite;
if (requirement.TryGetProperty<SecurityAlgorithmSuite> (ReqType.SecurityAlgorithmSuiteProperty, out suite))
p.SecurityAlgorithmSuite = suite;
return p;
}
示例9: CreateIssuedProviderBase
IssuedSecurityTokenProvider CreateIssuedProviderBase (SecurityTokenRequirement r)
{
IssuedSecurityTokenProvider p =
new IssuedSecurityTokenProvider ();
p.TargetAddress = r.GetProperty<EndpointAddress> (ReqType.TargetAddressProperty);
// FIXME: use it somewhere, probably to build
// IssuerBinding. However, there is also IssuerBinding
// property. SecureConversationSecurityBindingElement
// as well.
SecurityBindingElement sbe =
r.GetProperty<SecurityBindingElement> (ReqType.SecurityBindingElementProperty);
// I doubt the binding is acquired this way ...
Binding binding;
if (!r.TryGetProperty<Binding> (ReqType.IssuerBindingProperty, out binding))
binding = new CustomBinding (sbe,
new TextMessageEncodingBindingElement (),
new HttpTransportBindingElement ());
p.IssuerBinding = binding;
// not sure if it is used only for this purpose though ...
BindingContext ctx = r.GetProperty<BindingContext> (ReqType.IssuerBindingContextProperty);
foreach (IEndpointBehavior b in ctx.BindingParameters.FindAll<IEndpointBehavior> ())
p.IssuerChannelBehaviors.Add (b);
SecurityTokenVersion ver =
r.GetProperty<SecurityTokenVersion> (ReqType.MessageSecurityVersionProperty);
p.SecurityTokenSerializer =
CreateSecurityTokenSerializer (ver);
// seems like they are optional here ... (but possibly
// used later)
EndpointAddress address;
if (!r.TryGetProperty<EndpointAddress> (ReqType.IssuerAddressProperty, out address))
address = p.TargetAddress;
p.IssuerAddress = address;
// It is somehow not checked as mandatory ...
SecurityAlgorithmSuite suite = null;
r.TryGetProperty<SecurityAlgorithmSuite> (ReqType.SecurityAlgorithmSuiteProperty, out suite);
p.SecurityAlgorithmSuite = suite;
return p;
}
示例10: CreateX509SecurityTokenProvider
X509SecurityTokenProvider CreateX509SecurityTokenProvider (SecurityTokenRequirement requirement)
{
bool isInitiator;
requirement.TryGetProperty<bool> (ReqType.IsInitiatorProperty, out isInitiator);
// when it is initiator, then it is for MutualCertificateDuplex.
X509Certificate2 cert;
if (isInitiator) {
cert = credentials.ClientCertificate.Certificate;
if (cert == null)
throw new InvalidOperationException ("Client certificate is not provided in ServiceCredentials.");
if (cert.PrivateKey == null)
throw new ArgumentException ("Client certificate for MutualCertificateDuplex does not have a private key which is required for key exchange.");
} else {
cert = credentials.ServiceCertificate.Certificate;
if (cert == null)
throw new InvalidOperationException ("Service certificate is not provided in ServiceCredentials.");
if (cert.PrivateKey == null)
throw new ArgumentException ("Service certificate does not have a private key which is required for key exchange.");
}
X509SecurityTokenProvider p =
new X509SecurityTokenProvider (cert);
return p;
}
示例11: FindFederatedChannelParameters
/// <summary>
/// Looks for the first FederatedClientCredentialsParameters object in the ChannelParameterCollection
/// property on the tokenRequirement.
/// </summary>
internal FederatedClientCredentialsParameters FindFederatedChannelParameters(SecurityTokenRequirement tokenRequirement)
{
FederatedClientCredentialsParameters issuedTokenClientCredentialsParameters = null;
ChannelParameterCollection channelParameterCollection = null;
if (tokenRequirement.TryGetProperty<ChannelParameterCollection>(
ServiceModelSecurityTokenRequirement.ChannelParametersCollectionProperty,
out channelParameterCollection))
{
if (channelParameterCollection != null)
{
foreach (object obj in channelParameterCollection)
{
issuedTokenClientCredentialsParameters = obj as FederatedClientCredentialsParameters;
if (issuedTokenClientCredentialsParameters != null)
{
break;
}
}
}
}
return issuedTokenClientCredentialsParameters;
}
示例12: GetSspiIssuanceChannelParameter
SspiIssuanceChannelParameter GetSspiIssuanceChannelParameter(SecurityTokenRequirement initiatorRequirement)
{
ChannelParameterCollection channelParameters;
if (initiatorRequirement.TryGetProperty<ChannelParameterCollection>(ServiceModelSecurityTokenRequirement.ChannelParametersCollectionProperty, out channelParameters))
{
if (channelParameters != null)
{
for (int i = 0; i < channelParameters.Count; ++i)
{
if (channelParameters[i] is SspiIssuanceChannelParameter)
{
return (SspiIssuanceChannelParameter)channelParameters[i];
}
}
}
}
return null;
}
示例13: GetServiceCertificate
X509Certificate2 GetServiceCertificate (SecurityTokenRequirement requirement)
{
// try X509CertificateEndpointIdentity,
// ServiceCertificate.ScopedCertificate and
// ServiceCertificate.DefaultCertificate.
X509Certificate2 cert = null;
EndpointAddress address = null;
requirement.TryGetProperty (ReqType.TargetAddressProperty, out address);
if (address != null) {
X509CertificateEndpointIdentity ident = address.Identity as X509CertificateEndpointIdentity;
if (ident != null && ident.Certificates.Count > 0)
cert = ident.Certificates [0];
if (cert == null)
credentials.ServiceCertificate.ScopedCertificates.TryGetValue (address.Uri, out cert);
}
if (cert == null)
cert = credentials.ServiceCertificate.DefaultCertificate;
return cert;
}
示例14: CreateX509SecurityTokenProvider
X509SecurityTokenProvider CreateX509SecurityTokenProvider (SecurityTokenRequirement requirement)
{
// - When the request is as an initiator, then
// - if the purpose is key exchange, then
// the initiator wants the service certificate
// to encrypt the message with its public key.
// - otherwise, the initiator wants the client
// certificate to sign the message with the
// private key.
// - otherwise
// - if the purpose is key exchange, then
// the recipient wants the client certificate
// to encrypt the message with its public key.
// - otherwise, the recipient wants the service
// certificate to sign the message with the
// private key.
bool isInitiator;
if (!requirement.TryGetProperty<bool> (ReqType.IsInitiatorProperty, out isInitiator))
isInitiator = false;
X509Certificate2 cert;
bool isClient;
if (isInitiator)
isClient = requirement.KeyUsage == SecurityKeyUsage.Signature;
else {
if (!requirement.Properties.ContainsKey (SecurityTokenRequirement.KeyUsageProperty))
throw new NotSupportedException (String.Format ("Cannot create a security token provider from this requirement '{0}'", requirement));
isClient = requirement.KeyUsage == SecurityKeyUsage.Exchange;
}
if (isClient)
cert = credentials.ClientCertificate.Certificate;
else
cert = GetServiceCertificate (requirement);
if (cert == null) {
if (isClient)
throw new InvalidOperationException ("Client certificate is not provided in ClientCredentials.");
else
throw new InvalidOperationException ("Service certificate is not provided.");
}
X509SecurityTokenProvider p =
new X509SecurityTokenProvider (cert);
return p;
}
示例15: CreateSecurityTokenProvider
public override SecurityTokenProvider CreateSecurityTokenProvider (SecurityTokenRequirement requirement)
{
if (IsIssuedSecurityTokenRequirement (requirement))
return CreateIssuedTokenProvider (requirement);
bool isInitiator;
// huh, they are not constants but properties.
if (requirement.TokenType == SecurityTokenTypes.X509Certificate)
return CreateX509SecurityTokenProvider (requirement);
else if (requirement.TokenType == ServiceModelSecurityTokenTypes.SecureConversation)
return CreateSecureConversationProvider (requirement);
else if (requirement.TokenType == ServiceModelSecurityTokenTypes.AnonymousSslnego) {
if (requirement.TryGetProperty<bool> (ReqType.IsInitiatorProperty, out isInitiator) && isInitiator)
return CreateSslnegoProvider (requirement);
} else if (requirement.TokenType == ServiceModelSecurityTokenTypes.MutualSslnego) {
if (requirement.TryGetProperty<bool> (ReqType.IsInitiatorProperty, out isInitiator) && isInitiator)
return CreateSslnegoProvider (requirement);
} else if (requirement.TokenType == ServiceModelSecurityTokenTypes.SecurityContext) {
// FIXME: implement
} else if (requirement.TokenType == ServiceModelSecurityTokenTypes.Spnego) {
return CreateSpnegoProvider (requirement);
} else if (requirement.TokenType == ServiceModelSecurityTokenTypes.SspiCredential) {
// FIXME: implement
} else if (requirement.TokenType == SecurityTokenTypes.Rsa) {
// FIXME: implement
} else if (requirement.TokenType == SecurityTokenTypes.Saml) {
// FIXME: implement
} else if (requirement.TokenType == SecurityTokenTypes.UserName)
return CreateUserNameProvider (requirement);
else if (requirement.TokenType == SecurityTokenTypes.Kerberos) {
return CreateKerberosProvider (requirement);
}
throw new NotSupportedException (String.Format ("Token type '{0}' is not supported", requirement.TokenType));
}