- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个使用自定义 ServiceAuthorizationManager
的 WCF 服务。自定义身份验证管理器已设置为处理 Windows 和表单例份验证。
但是,如果我连接到设置为 UserName
auth 的客户端,我似乎无法在任何地方找到用户名。
客户端代码如下所示:
this.ClientCredentials.UserName.UserName = "user";
this.ClientCredentials.UserName.Password = "pass";
this.Open();
this.MyMethod(); // my actual contract method
this.Close();
然后在服务器上,我有我的自定义授权管理器:
public sealed class AppAuthorizationManager : ServiceAuthorizationManager
{
public override bool CheckAccess(OperationContext operationContext, ref Message message)
{
// would like to check user/pwd here...
}
}
这可能吗?
Thread.CurrentPrincipal
,operationContext.ServiceSecurityContext.PrimaryIdentity
未设置。operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets
为空。 用户/密码应该在任何地方都可用吗?还是我也必须添加自定义 UsernamePasswordValidator
?
更新:所以我添加了一个自定义 UserNamePasswordValidator
和一个 IAuthorizationPolicy
。我更新的 WCF 配置如下所示:
<behavior name="Server2ServerBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="MyApp.AuthManager, MyApp">
<authorizationPolicies>
<add policyType="MyApp.TokenAuthorizationPolicy, MyApp" />
</authorizationPolicies>
</serviceAuthorization>
<serviceCredentials>
<userNameAuthentication customUserNamePasswordValidatorType="MyApp.PFUserNameValidator, MyApp" />
</serviceCredentials>
</behavior>
如果我在所有 3 个类中设置断点,WCF 将抛出异常:
LogonUser failed for the 'username' user. Ensure that the user has a valid Windows account.
at System.IdentityModel.Selectors.WindowsUserNameSecurityTokenAuthenticator.ValidateUserNamePasswordCore(String userName, String password)
在它们运行之前。嗯……
最佳答案
这通常在 UsernamePasswordValidator 中处理- 这是您唯一可以访问密码的地方。但是,这不是您设置委托(delegate)人的地方 - 它应该在 IAuthorizationPolicy
的 Evaluate
方法中,它可能类似于:
bool IAuthorizationPolicy.Evaluate(
EvaluationContext evaluationContext, ref object state)
{
IList<IIdentity> idents;
object identsObject;
if (evaluationContext.Properties.TryGetValue(
"Identities", out identsObject) && (idents =
identsObject as IList<IIdentity>) != null)
{
foreach (IIdentity ident in idents)
{
if (ident.IsAuthenticated &&
ident.AuthenticationType == TrustedAuthType)
{
evaluationContext.Properties["Principal"]
= //TODO our principal
return true;
}
}
}
if (!evaluationContext.Properties.ContainsKey("Principal"))
{
evaluationContext.Properties["Principal"] = //TODO anon
}
return false;
}
(其中 TrustedAuthType
是我们的密码验证器的名称)
有了这个,线程的主体将被设置,我们可以识别自己(并使用基于角色的安全性等)
关于c# - WCF 用户名身份验证 : Can I get the Username in a custom ServiceAuthorizationManager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/529485/
这是我第一次使用 php 学习 session ,我正在尽可能地制作最简单的登录页面。 因此,只要用户永远不会关闭网页,理论上这是否可以让任何给定的字符串 $username 始终存储在 $_SESS
我已在Windows 10中更改了用户名,现在我需要自动将更改后的用户名作为Powershell脚本获取 但是我尝试的所有操作都返回了我的旧用户名,除了一些与AD相关的查询。 例子: $env
我的 html 页面上有这个链接,可以在特定用户上打开 Instagram 应用程序: Link to Instagram Profile 我一直在寻找自动运行 url 'instagram://us
此代码似乎不适用于 Windows 7/8? Public Function UserName() UserName = Environ$("UserName") End Function 有
Excel宏:如何编写此“如果用户名[示例代码:Environ(“用户名”)]等于此范围内的值之一[示例:我从工作簿创建的范围:范围(“Authorized_Users”)]然后。 ..“谢谢! 最佳
PowerShell的$env:username有什么区别和 [environment]::username和 为什么他们可能会返回不同的用户 ? (我知道还有其他方法可以获取当前用户) 一些背景:
与大多数网站的工作方式相同,我将“UsErNaMe”存储在数据库中,但让用户使用“用户名”登录。 这是一个相当明显且必要的功能,很多人似乎都问过它,但我不断遇到的解决方案似乎与 Devise 自己的文
在终端中输入 psql 后,用户通常会以 username=# 的形式出现在控制台中。但后来我注意到它说username-#,其中等号被连字符替换,但它似乎仍然以相同的方式执行。 我知道这是一个简单的
在终端中输入 psql 后,用户通常会以 username=# 的形式出现在控制台中。但后来我注意到它说username-#,其中等号被连字符替换,但它似乎仍然以相同的方式执行。 我知道这是一个简单的
这个问题已经有答案了: Reference - What does this error mean in PHP? (38 个回答) 已关闭 5 年前。 我是 PHP 的初学者,我一整天都在尝试修复这
我正在尝试从表 users 中取出 url 并将其插入到表 images 的 url> 来自当前登录的用户。此代码无法在 images 表中插入 url。 $uploaduser = $_SESSIO
我很难让 WebDriver 在 PayPal 网站的用户名框中键入内容。我已经尝试过 xpath、id、css,但这里一定有我遗漏的东西,因为它应该很简单。文本框是代码最底部的 input = "e
我正在使用 iOs 社交框架从某个用户那里检索 facebook 提要。为此,在进行身份验证后,我将执行以下操作: NSURL *requestURL = [NSURL URLWithString:@
我有一个 WCF web 服务托管在 IIS 中。这是相同的配置: 当我尝试在我的 WinForms 客户端中使用此特定服务(作为服务引用添加时)时,它会抛出此异常: The username is
def login_page(request): form = LoginForm(request.POST or None) context = { "form":
更新我想我很快就假设了 voodoo jquery 之谜。我注意到我确实使用了两次“用户名”ID,这就是问题所在。第二个用户名 id 是通过从 php 注入(inject)页面的 html 代码添加到
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
到目前为止,下面显示的第一个 $sql = “INSERT INTO MySQLtable 语句将插入一个包含静态文本的新行 VALUES ('statictext', 'statictext') 。
我几乎完成了我的大型项目的开发,但是如果我能做到而不是让用户配置文件页面位于:http://example.com/profile/username/USERNAME<,我会很高兴 (我目前正在使用
(注意我是 Scala 的新手,仍然在为集合操作的最常见操作而苦苦挣扎。) 我想将 List[Task] 转换为 Map。以下是一些详细信息: // assignee may be null case
我是一名优秀的程序员,十分优秀!