我们目前正在开发一个Windows Smartclient,需要使用其AD组成员身份对用户进行身份验证.
我们现在要求一些用户通过VPN连接.有什么方法可以从VPN登录获得AD帐户身份和组?
WindowsIdentity.GetCurrent()返回本地用户帐户而不是VPN帐户信息.
本地帐户名称与用于VPN连接的AD帐户不同.即,用户在他们的家用PC上,并使用他们的工作AD帐户连接到办公室.
在我的应用程序中,我们正在从SecurityContextHolderAuthentication对象捕获每个事务的用户详细信息。
但这UserID似乎是错误的。下面是代码片段供您参考。
SecurityContext.xml
春季安全3.2-
<security:http auto-config="true">
<!-- Restrict URLs based on role -->
<security:headers>
<security:cache-control/>
<security:content-type-options/>
<security:frame-options policy="DENY"/>
<security:xss-protection/>
</security:headers>
<security:intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/logoutSuccess*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/resources/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/web/forgotPwd/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern="/web/**" access="ROLE_USER" />
<security:form-login login-page="/login.html" default-target-url="/web/landing/homePage.html"
always-use-default-target="true" authentication-failure-handler-ref="exceptionTranslationFilter" />
<security:logout delete-cookies="JSESSIONID" invalidate-session="true"
logout-success-url="/logout.html" />
<security:session-management session-fixation-protection="newSession" invalid-session-url="/login.html?login_error=sessionexpired" session-authentication-error-url="/login.html?login_error=alreadyLogin">
<security:concurrency-control max-sessions="1" expired-url="/login.html?login_error=duplicateOrsessionexpired" error-if-maximum-exceeded="false" />
</security:session-management>
<security:csrf />
<security:remember-me token-repository-ref="remembermeTokenRepository" key="myAppKey"/>
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="userDetailsServiceImpl">
<security:password-encoder ref="passwordEncoder" />
</security:authentication-provider>
</security:authentication-manager> …Run Code Online (Sandbox Code Playgroud) 我的问题是关于心理包中的principal()函数.
set.seed(0)
x <- replicate(8, rnorm(10))
pca.x <- principal(x, nf=4, rotate="varimax")
Run Code Online (Sandbox Code Playgroud)
我知道如果我想查看加载表,我可以使用loading.x <-loadings(pca.x),比我将得到以下结果.
> loading.x
Loadings:
RC1 RC3 RC4 RC2
[1,] -0.892 -0.205 0.123
[2,] 0.154 0.158 0.909
[3,] -0.660 0.255 -0.249 0.392
[4,] -0.352 0.412 0.614 -0.481
[5,] 0.950 -0.208 0.117
[6,] -0.302 0.111 0.860
[7,] 0.852 -0.195 -0.358
[8,] -0.109 0.903 0.265
RC1 RC3 RC4 RC2
SS loadings 2.323 1.934 1.373 1.342
Proportion Var 0.290 0.242 0.172 0.168
Cumulative Var 0.290 0.532 0.704 0.871
Run Code Online (Sandbox Code Playgroud)
我的第一个困惑是装载对象.从技术上讲,它是一个矩阵,但看它的尺寸,它是8*4,这意味着下部不包括在内.
基本上,我想要实现的是单独提取这个部分: …
我有一个WCF服务,我使用自定义UserNamePasswordValidator来验证用户.
public override void Validate(string userName, string password)
{
LoginHelper loginHelper = new LoginHelper();
loginHelper.ValidateUserRegularLogin(userName, password);
}
Run Code Online (Sandbox Code Playgroud)
完成此操作后,将触发IAuthorizationPolicy.Evaluate,这是我将主体设置为自定义用户上下文的位置,如下所示:
evaluationContext.Properties["Principal"] = userContext;
Run Code Online (Sandbox Code Playgroud)
问题是我需要2件事来获得正确的usercontext,这是用户名和标题中的值.
我知道我可以使用messageinspector来获取这样的头数据:
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
{
IntegrationHeader integrationHeader;
LoginHandler loginHandler;
UserContextOnService userContext = null;
if (request.Headers.Action == null || request.Headers.Action.ToString().Length < 1)
return null;
foreach (var header in request.Headers)
{
if (header.Namespace == "ns" && header.Name == "SecurityToken")
{
return null;
}
}
throw new SecurityTokenException("Unknown username or invalid password");
}
Run Code Online (Sandbox Code Playgroud)
但我需要在Evaluate方法中获取此信息,以便我可以进行正确的登录(设置主体).可能吗?如果是这样,怎么样?有什么选择?
PS.这将通过调用完成,因此不能使用特定的登录方法. …
我正在尝试physicalDeliveryOfficeName从DirectoryEntryUserPrincipal实例的GetUnderlyingObject方法返回的属性加载:
DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;
Run Code Online (Sandbox Code Playgroud)
这意味着以下语句返回false:
directoryEntry.Properties.Contains("physicalDeliveryOfficeName");
Run Code Online (Sandbox Code Playgroud)
我知道可以通过StringCollection DirectorySearcher.PropertiesToLoad在使用时添加名称来加载此属性DirectorySearcher.
我的问题是,为什么DirectoryEntry方法返回的GetUnderlyingObject所有属性都不包含?如何在不使用DirectorySearcher?的情况下加载此属性?
谢谢你的回答!
在我的WCF服务类的构造函数中,我将当前主体设置为消息头中传递的主体的主体:
Thread.CurrentPrincipal = OperationContext.Current.IncomingMessageHeaders.GetHeader<BBPrincipal>("bbPrincipal", "ns");
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,但是当我在方法中引用主体时,Thread.CurrentPrincipal已恢复为WindowsPrincipal.
据推测,该方法是在不同的线程上触发.如何确保该方法在服务的构造函数中使用主体集?
我希望能够访问经过身份验证的用户(如UserId和FirstName)的自定义属性,而无需每次都查询数据库.我通过Stack Overflow上的帖子找到了这个网站,我喜欢这种方法 - 但我使用IoC /存储库并决定不尝试使用global.asax与数据库进行通信,因为它担心它与存储库模式不兼容.
相反,我创建了一个CustomPrincipal接口,我使用IoC(Castle)创建一个实例并将其传递给控制器(以及随后传递给我的基本控制器).
基本控制器使用我在CustomPrincipal中创建的方法来实现博客作者在global.asax中处理的相同任务.即,CustomPrincipal从数据库或缓存初始化并分配给HttpContext.Current.User.
我的控制器/视图然后可以引用属性如下...
((ICustomPrincipal)(HttpContext.Current.User)).FirstName;
Run Code Online (Sandbox Code Playgroud)
它有效,但我感觉到一些代码味道.首先,如果我从控制器引用HttpContext,我已经杀死了我的单元测试.我正在考虑修改我的CustomPrincipal对象以返回上面的值(这样我可以在我的单元测试中模拟它)但我想知道这是否是一个解决方法而不是一个好的解决方案.
我是以正确的方式来做这件事的吗?我是否可以做一些小的调整以使其成为一个强大的解决方案,或者我应该从头开始使用FormsAuthenticationTicket或其他类似的东西?
谢谢!
我有一个自定义的ServiceAuthorizationManager,我在其中覆盖CheckAccess并验证作为URL一部分的自定义身份验证令牌.验证后,我使用GenericPrincipal设置Thread.CurrentPrincipal.但是当请求最终到达我的服务方法时,Thread.CurrentPrincipal消失了,它不是我在auth管理器中设置的.出了什么问题?
我正在尝试用Matlab学习主成分回归(pcr).我在这里使用本指南:http://www.mathworks.fr/help/stats/examples/partial-least-squares-regression-and-principal-components-regression.html
这真的很好,但我无法理解一步:
我们做PCA和回归,很好很清楚:
[PCALoadings,PCAScores,PCAVar] = princomp(X);
betaPCR = regress(y-mean(y), PCAScores(:,1:2));
Run Code Online (Sandbox Code Playgroud)
然后我们调整第一个系数:
betaPCR = PCALoadings(:,1:2)*betaPCR;
betaPCR = [mean(y) - mean(X)*betaPCR; betaPCR];
yfitPCR = [ones(n,1) X]*betaPCR;
Run Code Online (Sandbox Code Playgroud)
为什么系数需要'mean(y) - mean(X)*betaPCR'为恒定的一个因子?你能解释一下吗?
提前致谢!
我们使用自定义主体和身份类型(ProdigyPrincipal/ProdigyIdentity),因为我们需要在我们的程序和服务中提供额外信息.在程序中,我们设置了主体和身份.与WCF服务通信时,将设置主体和标识,但在转换为我们自己的类型后,主体和标识为空.
我注意到在调试模式和单元测试模式下运行之间存在差异.在调试模式下,主体和标识的类型是WindowsPrincipal和WindowsIdentity类型.在单元测试模式下,类型是GenericPrincipal和GenericIdenity.在转换为自定义类型的两种情况下,值都为null.
设置和获取主体/身份是通过Thread.CurrentPrincipal完成的.在绑定部分的App.configs中,安全模式设置为"传输".
用于设置/获取主体和身份的已用函数:
protected static bool SetProdigyPrincipal()
{
#region require Thread.CurrentPrincipal should not be null
if (Thread.CurrentPrincipal == null) // OK
{
throw new InvalidOperationException("SetProdigyPrincipal(): Thread.CurrentPrincipal should not be null");
}
#endregion require Thread.CurrentPrincipal should not be null
var prodigyPrincipal = Thread.CurrentPrincipal as ProdigyPrincipal;
#region require prodigyPrincipal should not be null
if (prodigyPrincipal == null) // NOT OK
{
throw new InvalidOperationException("SetProdigyPrincipal(): prodigyPrincipal should not be null");
}
#endregion require prodigyPrincipal should not …Run Code Online (Sandbox Code Playgroud) principal ×10
wcf ×4
c# ×3
identity ×2
.net ×1
asp.net-mvc ×1
components ×1
java ×1
login ×1
matlab ×1
pca ×1
psych ×1
r ×1
regression ×1
spring ×1
thread-local ×1
vpn ×1