에 대한 사용자 권한 부여를 지정 는 프로그래밍 나는이 링크에서와 같은 일을 할 WCF (NetTcpBinding)
http://www.codeproject.com/KB/WCF/Custom_Authorization_WCF.aspx
그러나 구성 파일을 사용하지 않고
. 아무도 어떻게 보여줄 수 있습니까?편집 : AuthorizationPolicy와 CustomValidator를 모두 구현하고 싶습니다.
에 대한 사용자 권한 부여를 지정 는 프로그래밍 나는이 링크에서와 같은 일을 할 WCF (NetTcpBinding)
http://www.codeproject.com/KB/WCF/Custom_Authorization_WCF.aspx
그러나 구성 파일을 사용하지 않고
. 아무도 어떻게 보여줄 수 있습니까?편집 : AuthorizationPolicy와 CustomValidator를 모두 구현하고 싶습니다.
코드를 통해 AuthorizationPolicy를 추가하는 방법에 대해 언급하고 있습니까? 테스트되지 않은,하지만이 같은 일을해야 믿습니다
ServiceHost host = ...;
var col = new ReadOnlyCollection<IAuthorizationPolicy>(new IAuthorizationPolicy[] { new MyPolicy() });
ServiceAuthorizationBehavior sa = host.Description.Behaviors.Find<ServiceAuthorizationBehavior>();
if (sa == null) {
sa = new ServiceAuthorizationBehavior();
host.Description.Behaviors.Add(sa);
}
sa.ExternalAuthorizationPolicies = col;
는 this topic (WCF Security: Getting the password of the user) by Rory Primrose을 참조하면, 그는 중요한 확장 방법은 CreateSecurityTokenManager
인 당신이 사용자 정의 유효성 검사기를 제공에 대해 문의하고 유사 달성 :
<serviceCredentials type="your.assembly.namespace.PasswordServiceCredentials,
your.assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" >
</serviceCredentials>
01 :
public class PasswordServiceCredentials : ServiceCredentials
{
public PasswordServiceCredentials()
{
}
private PasswordServiceCredentials(PasswordServiceCredentials clone)
: base(clone)
{
}
protected override ServiceCredentials CloneCore()
{
return new PasswordServiceCredentials(this);
}
public override SecurityTokenManager CreateSecurityTokenManager()
{
// Check if the current validation mode is for custom username password validation
if (UserNameAuthentication.UserNamePasswordValidationMode == UserNamePasswordValidationMode.Custom)
{
return new PasswordSecurityTokenManager(this);
}
Trace.TraceWarning(Resources.CustomUserNamePasswordValidationNotEnabled);
return base.CreateSecurityTokenManager();
}
}
, 당신은 같은 구성에
<ServiceCredentials>
의
ConfigurationElement
에 type 속성을 지정해야합니다이 사용자 정의 서비스 자격 증명을 사용하려면
마찬가지로이 type
속성을 프로그래밍 방식으로 설정할 수 있지만 방법에 익숙하지 않습니다.
내 질문을 제대로 읽지 못했습니다. 제발. – jgauffin
죄송하지만, 구성 확장 (ie 확장 요소)을 통해 WCF의 모든 사용자 정의를 완료했습니다. 그러나 tomasr의 리드를 따르면서, 다음을 사용하여 액세스 된 'UserNamePasswordServiceCredential' 객체에서 다음 특성을 설정하여 CustomValidator를 설정할 수 있다고 제안합니다. (UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom' 및'UserNamePasswordValidator = new MyCustomValidator()')를 호출합니다. 희망이 도움이! – Rabid
그가 추천하는 것을 명시 적으로 밝히지는 않았지만 처음부터 자신의 서비스 자격 증명 구성을 구축하고 ('ServiceName', 'UserNameAuthentication'을 포함하여) 관련된 모든 속성을 설정 한 다음 'ServiceCredentials' 'ServiceCredentialsElement.CreateBehaviour()'를 통해 동작을 생성함으로써 기술 된 서비스 호스트 동작 내에 이미 존재합니다 - BehaviorExtensionElement'에서'protected internal abstract Object CreateBehavior()'로 선언 되었기 때문에 직설적이지는 않습니다. – Rabid
감사합니다. 또한 코드로 CustomValidator를 지정하는 방법을 보여줄 수 있습니까? – jgauffin
다시 시도했지만 ServiceCredentials는 다른 서비스 동작이므로 ServiceCredentialsElement의 인스턴스를 만들고 UserNameAuthentication 속성을 설정 한 다음 CreateBehavior()를 호출하고 ServiceHost에 추가 할 수 있어야합니다. – tomasr