private static async Task <T> GetTokenAsync <T>(SecurityTokenProvider tokenProvider, TimeSpan timeout) where T : SecurityToken { SecurityToken result = await tokenProvider.GetTokenAsync(timeout); if ((result != null) && !(result is T)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format( SR.InvalidTokenProvided, tokenProvider.GetType(), typeof(T)))); } return(result as T); }
private void SetupServerCertificate(SecurityToken token) { X509SecurityToken x509Token = token as X509SecurityToken; if (x509Token == null) { SecurityUtils.AbortTokenProviderIfRequired(_serverTokenProvider); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format( SR.InvalidTokenProvided, _serverTokenProvider.GetType(), typeof(X509SecurityToken)))); } _serverCertificate = new X509Certificate2(x509Token.Certificate.Handle); }
static T GetToken <T>(SecurityTokenProvider tokenProvider, TimeSpan timeout) where T : SecurityToken { SecurityToken result = tokenProvider.GetToken(timeout); if ((result != null) && !(result is T)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString( SR.InvalidTokenProvided, tokenProvider.GetType(), typeof(T)))); } return(result as T); }
void ResolveSecurityToken() { if ( _securityToken == null ) { lock ( _lock ) { if ( _securityToken == null ) { ClientCredentialsSecurityTokenManager.KerberosSecurityTokenProviderWrapper kerbTokenProvider = _tokenProvider as ClientCredentialsSecurityTokenManager.KerberosSecurityTokenProviderWrapper; if (kerbTokenProvider != null) { _securityToken = kerbTokenProvider.GetToken((new TimeoutHelper(_timeout)).RemainingTime(), _channelBinding); } else { _securityToken = _tokenProvider.GetToken((new TimeoutHelper(_timeout)).RemainingTime()); } } } } if ( _securityToken == null ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SecurityTokenException( SR.GetString( SR.SecurityTokenNotResolved, _tokenProvider.GetType().ToString() ) ) ); } return; }
private static T GetToken <T>(SecurityTokenProvider tokenProvider, TimeSpan timeout) where T : SecurityToken { SecurityToken token = tokenProvider.GetToken(timeout); if ((token != null) && !(token is T)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("InvalidTokenProvided", new object[] { tokenProvider.GetType(), typeof(T) }))); } return(token as T); }
private static async Task <T> GetTokenAsync <T>(SecurityTokenProvider tokenProvider, CancellationToken cancellationToken) where T : SecurityToken { SecurityToken result = await tokenProvider.GetTokenAsync(cancellationToken); if ((result != null) && !(result is T)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format( SRServiceModel.InvalidTokenProvided, tokenProvider.GetType(), typeof(T)))); } return(result as T); }