ASP.Net WCF 서비스의 스레드에 있습니다.CurrentPrincipal 은 발생되는 멀리하여 어떤 요격에 페더레이션(WIF)환경

StackOverflow https://stackoverflow.com/questions/1932424

  •  20-09-2019
  •  | 
  •  

문제

내가 당화 WCF 서비스에서 개최 IIS(.svc).에서 서비스의 생성자,나는 설정 스레드가 있습니다.CurrentPrincipal=HttpContext.현재 있습니다.사용자 당로 이 문서.이 경우에는 HttpContext.현재 있습니다.사용자 의 형식 Microsoft.IdentityModel.Claims.사용자 고 있는 클레임을 보낸 뒤에서 나의 주문 수동 STS.

그러나,빨리 나가 단계로 서비스를 운영 및 검사 스레드가 있습니다.CurrentPrincipal, 면서,이 물체가 여전히의 유형 Microsoft.IdentityModel.Claims.ClaimsIdentity, 개체 자체는 더 이상의 동일한으로 HttpContext.현재 있습니다.사용자 (IsAuthenticated=false,형=""그 이름은 null 에서 스레드가 있습니다.CurrentPrincipal.정체성음)반면 이 값은 모든 여전히 채워지에서 올바르게 HttpContext.현재 있습니다.사용자.이게 무언가입을 차단하는 전화를 운영하고 잘못을 변경하는 현재의 교장 일반,빈,인증되지 않은 청구합니다.

체크레드 ID 생성자에서 뿐 아니라 작업에서 그리고 모두에서 동일한 장소,그리고 평가 스레드가 있습니다.CurrentPrincipal 직접 실행 창에서 할당한 후에서 HttpContext.현재 있습니다.사용자 쇼는 스레드 정체성되고 올바르게 설정에서 생성자,그래서 뭔가 확실히 실행하는 사이에서 생성자 및 방법,그리고 무언가 변하고 나 스레드가 있습니다.CurrentPrincipal.

누군가가 어떤 생각이 무엇을 하고 있는 이와할 수 있는 방법에 대해 이동을 방지/고정이 행동?

도움이 되었습니까?

해결책 2

을 구성하는 경우 서비스에 대한 WIF federation,당신은 전화

FederatedServiceCredentials.ConfigureServiceHost(this);

의 일부 다른 설정 사용자 지정 ServiceAuthorizationManager 의 유형 IdentityModelServiceAuthorizationmanager 에서 서비스 호스트.이 관리자 권한이 나타납하라 사이에서 인증(건설)의 인스턴스를 실행하는 작업,그리고 그것을 덮어 스레드가 있습니다.CurrentPrincipal 의 인스턴스 IClaimsPrincipal, 지만,그것은 보이지 않는다는 것을 깨닫게 이에서 실행 ASP.NET 환 모드,그래서 그것을 당기지 않을 주서 HttpContext.현재 있습니다.사용자.

할 수 있었을 우회 이동에 의해서 파생 IdentityModelServiceAuthorizationmanager 과 재정의 CheckAccess 방법은 다음과 같다:

public class CustomAuthorizationManager : IdentityModelServiceAuthorizationManager
{
    public override bool CheckAccess(System.ServiceModel.OperationContext operationContext, ref System.ServiceModel.Channels.Message message)
    {
        var result = base.CheckAccess(operationContext, ref message);

        var properties = operationContext.ServiceSecurityContext.AuthorizationContext.Properties;
        properties["Principal"] = System.Web.HttpContext.Current.User;

        return result;
    }
}

이 다음에 적용되는 호스트 서비스는 다음과 같다:

protected override void InitializeRuntime()
{
    FederatedServiceCredentials.ConfigureServiceHost(this);
    this.Authorization.ServiceAuthorizationManager = new CustomAuthorizationManager();
    base.InitializeRuntime();
}

그리고 이제 내가 입력한 내 서비스 작업에,나는 올바른 IClaimsPrincipal스레드가 있습니다.CurrentPrincipal, 도록 선언 PrincipalPermission 지금 예상대로 작동합니다.

다른 팁

나는 그냥으로 실행할 경우 비슷한 문제가 발생합니다.내가 사용자 정의 주체에서 생성자의 내 WCF 서비스입니다.때 난 생성자를 입력 방법은 나라,thread.currentprincipal 었으로 재정의 빈 하나입니다.내가 이것을 해결을 추가하여 다음과 같은 문제가 발생합니다.

<serviceAuthorization principalPermissionMode="None"></serviceAuthorization>

이 일이 있습니다.

confguration 에 대한 설정을 통화 FederatedServiceCredentials.ConfigureServiceHost(이);

은 아래와 같이 에서는 시스템입니다.논 다음에 추가

<extensions>
      <behaviorExtensions>
        <add name="federatedServiceHostConfiguration" type="Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </behaviorExtensions>
    </extensions>

아래에 내가 다음 줄을

<behavior name="serviceBehavior">
          <federatedServiceHostConfiguration name="MyService" />

내 생각에는 아무것을 차단합니다.중 CurrentPrincipal 다시 설정해 시간은 당신이 검사하거나 당신에 다른 스레드가 있습니다.

체크인 CurrentPrincipal 바로 할당한 후에 그것을 당신이 볼에 올바른 값입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top