/// <summary> /// Checks authorization for the given operation context. /// </summary> /// <param name="operationContext">Operation context.</param> /// <returns>True if access is granted otherwise false.</returns> public override bool CheckAccess(OperationContext operationContext) { try { if (base.CheckAccess(operationContext) == false) { return(false); } if (operationContext.Host == null || operationContext.Host.Description == null) { return(false); } if (operationContext.ServiceSecurityContext == null || operationContext.ServiceSecurityContext.AuthorizationContext == null || operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets == null) { return(false); } var trustedClaimSets = _authorizationHandler.GetTrustedClaimSets(operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets); _authorizationHandler.Authorize(trustedClaimSets, operationContext.Host.Description.ServiceType); return(true); } catch (Exception ex) { throw new FaultException(Resource.GetExceptionMessage(ExceptionMessage.NotAuthorizedToUseService, ex.Message)); } }
private bool DoAuthorizeRequestToken() { if (RequestToken == null) { throw new InvalidOperationException("Request token must be present"); } // Invoke the authorization handler bool continueOnReturn = false; if (authorizationHandler != null) { continueOnReturn = authorizationHandler.Authorize(RequestToken); } return(continueOnReturn); }
private async Task <HttpResponseMessage> Try(Func <Task <HttpResponseMessage> > makeRequest, CancellationToken cancellationToken) { for (var attempt = 0; attempt < _maxAttempts; ++attempt) { if (_token == null) { _token = await _authorizationHandler.Authorize(cancellationToken); if (_token == null) { throw new AuthenticationException("Authentication failed"); } } try { if (cancellationToken.IsCancellationRequested) { return(null); } _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(BearerAuth, _token); var response = await makeRequest(); if (response.StatusCode == HttpStatusCode.Unauthorized) { _token = null; } else { return(response); } } catch { // on exceptions delay before retrying await Task.Delay(_exceptionRetryDelayMs, cancellationToken); } } throw new RetriesExceededException(); }
public Task Process(TRequest request, CancellationToken cancellationToken) { return(_authorizationHandler.Authorize(request)); }