标签: userprincipal

HttpClient为Kerberos身份验证设置凭据

我正在尝试使用kerberos/HTTP主机进行身份验证.使用Apache HttpClient作为我的客户端 - 以及此源的略微修改版本. 我的Kerberos身份验证完全正常,我希望知道如何以编程方式设置登录凭据.目前,凭据是通过控制台手动输入的,但我希望在运行时由我选择.[实际上,我希望自动化并加载测试具有大量用户的服务器.].

编辑:这是相关部分的代码片段:

..
        NegotiateSchemeFactory nsf = new NegotiateSchemeFactory();        
        httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, nsf);

        Credentials use_jaas_creds = new Credentials() {

            public String getPassword() {
                return null;
            }

            public Principal getUserPrincipal() {
                return null;
            }    
        };

        httpclient.getCredentialsProvider().setCredentials(
                new AuthScope(null, -1, null),
                use_jaas_creds);

        HttpUriRequest request = new HttpGet("http://kerberoshost/");
        HttpResponse response = httpclient.execute(request);
 .. 
Run Code Online (Sandbox Code Playgroud)

该接口Credentials有两个方法- getPassword()getUserPrincipal(),但是从一些调试我这样做,他们似乎并没有在所有被调用.

我在这里错过了什么?什么是静态设置凭据的更简洁方法?

之前已经提出过一个非常类似的问题,但是keytabs/login.conf hack过于繁琐,并且不适合使用大量用户凭据进行自动负载测试.感谢任何帮助.

java authentication kerberos httpclient userprincipal

16
推荐指数
1
解决办法
2万
查看次数

确定用户是否在.NET 4.0应用程序的AD组中

我试图确定用户是否是内部ASP.NET 4.0应用程序的Active Directory(AD)组的成员.在用户不是AD组成员的情况下,下面的代码在最后一行(return语句)上抛出"尝试访问已卸载的appdomain"异常错误.

public static bool IsInADGroup(string userName, string groupName)
{
    var principalContext = new PrincipalContext(ContextType.Domain);
    UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName);
    if (userPrincipal == null)
        return false;

    GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, groupName);
    if (groupPrincipal == null)
        return false;

      return userPrincipal.IsMemberOf(groupPrincipal);
}
Run Code Online (Sandbox Code Playgroud)

有关如何修复或其他解决方法的任何想法?

.net c# directoryservices userprincipal

14
推荐指数
2
解决办法
8168
查看次数

从UserPrincipal对象获取nETBIOSName

我正在使用.Net库的System.DirectoryServices.AccountManagement部分连接到ActiveDirectory.

在GroupPrincipal对象上调用GetMembers()并过滤结果后,我现在有一个UserPrincipal对象的集合

GroupPrincipal myGroup;  // population of this object omitted here 

foreach (UserPrincipal user in myGroup.GetMembers(false).OfType<UserPrincipal>())
{
    Console.WriteLine(user.SamAccountName);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码示例将打印出"TestUser1"之类的用户名.我需要将这些与来自"DOMAIN\TestUser1"格式的另一个应用程序的列表进行比较.

如何从UserPrincipal对象获取"DOMAIN"部分?

我不能只是附加一个已知的域名,因为涉及多个域,我需要区分DOMAIN1\TestUser1和DOMAIN2\TestUser2.

.net c# active-directory userprincipal

12
推荐指数
1
解决办法
6351
查看次数

如何使用j_security_check获取连接用户的数量及其角色?

我通过托管bean以这种方式获取连接用户的用户名(使用j_security_check):

......
    username =   FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
Run Code Online (Sandbox Code Playgroud)

然后以这种方式在jsf页面中显示它:#{userBean.username} 但我认为无法获得连接用户数量并获得他们的角色.换句话说,除了用户名,用户角色和连接用户数之外,我还要显示. 我怎样才能做到这一点!?在此先感谢您的帮助!

编辑:我现在可以使用托管bean中的namedquery获取连接用户的角色:

public Users getUserRole(){
      try {
            Users auser = (Users)
            em.createNamedQuery("Users.findByUsername").
                    setParameter("username", getRemoteUser()).getSingleResult();
            return auser; 
        } catch (NoResultException nre) {
            JsfUtil.addErrorMessage(nre, "getUserRole Error");
            return null;
        }

    }
Run Code Online (Sandbox Code Playgroud)

并在xhtml页面中:

<h:outputLabel for="rolefacet" value="Role: "/>
  <h:outputFormat id="rolefacet" value="#{UserBean.userRole.ugroup}" /> 
Run Code Online (Sandbox Code Playgroud)

而ugroup是Users实体类中的角色名称.


编辑:一个仍然不适合我的解决方案是在我的web.xml中添加一个HttpSessionListener:

package beans;

/**
 *
 * @author med81
 */

import java.io.Serializable;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.ArrayList;

import javax.faces.context.FacesContext;


public class SessionCounter implements …
Run Code Online (Sandbox Code Playgroud)

jsf j-security-check userprincipal java-ee-5

9
推荐指数
2
解决办法
8252
查看次数

Spring Security:手动设置setUserPrincipal

在使用Spring MVC和Spring Security的Web应用程序中.

有没有办法手动设置UserPrincipal?

我需要通过webapplication的管理部分切换到另一个用户.在我的控制器中,是否可以在请求中设置UserPrincipal?连接好像我是别人一样.

像这样:request.setUserPrincipal().getName()

spring spring-security userprincipal

9
推荐指数
1
解决办法
4005
查看次数

获取给定UserPrincipal的组列表

我想获取用户所在的组列表.

这是我的代码:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "mydomain.ac.uk",   "DC=mydomain,DC=AC,DC=UK", "user", "password");

UserPrincipal user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "MyUser");

PrincipalSearchResult<Principal> results = user.GetGroups();

foreach(Principal p in results)
{
   Response.Write(p.Name);
}
Run Code Online (Sandbox Code Playgroud)

当我跑,我在线上得到以下错误 Response.Write(p.Name);

System.Runtime.InteropServices.COMException:指定的目录服务属性或值不存在.

当我检查结果的计数时,它返回9,第一组是DomainUsers.

如何迭代列表中的所有9个组?谢谢.

以下是我获得的用户列表:

在此输入图像描述

c# active-directory userprincipal

9
推荐指数
2
解决办法
4243
查看次数

System.DirectoryServices.AccountManagement.UserPrincipal - localhost但不是iis

为什么我运行我的Web应用程序localhost时,下面的代码工作正常,但是当我将它安装到IIS服务器时却没有?

using (HostingEnvironment.Impersonate())
{
    UserPrincipal activeUser = UserPrincipal.Current;
    String activeUserSid = activeUser.Sid.ToString();
    String activeUserUPN = activeUser.UserPrincipalName;
}
Run Code Online (Sandbox Code Playgroud)

请不要建议我坚持使用HttpContext.Current.User,因为如果没有额外的Active Directory调用,它就无法访问SID或UPN.

Web应用程序将由来自三个不同域的Windows身份验证用户使用,Web服务器托管在第四个域中.应用程序池配置为在NetworkService标识下运行,Web应用程序配置将标识模拟设置为true.

在IIS上运行时的错误消息是:

Page_Load()中的错误:UserPrincipal.Current.
System.InvalidCastException:无法投射型"System.DirectoryServices.AccountManagement.GroupPrincipal"的目的为类型"System.DirectoryServices.AccountManagement.UserPrincipal".
在System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext上下文,IdentityType identityType,字符串identityValue)
在System.DirectoryServices.AccountManagement.UserPrincipal.get_Current()
在webapp.Details.Default.Page_Load(对象发件人,EventArgs的)

编辑:尝试以下两个,不幸的是得到相同的错误.

UserPrincipal userPrincipal = UserPrincipal.Current;
Response.Write(userPrincipal.Name);
Run Code Online (Sandbox Code Playgroud)
Principal userOrGroup = UserPrincipal.Current;
Response.Write(userOrGroup.Name);
Run Code Online (Sandbox Code Playgroud)

asp.net impersonation userprincipal

9
推荐指数
1
解决办法
8904
查看次数

如何获取列表本地Windows用户(仅显示在Windows登录屏幕中的用户)

如何获取本地Windows用户列表(仅显示在Windows登录屏幕中的用户)

我尝试了很多使用Windows Principle库和WMI Select命令的方法.我一直得到管理员,访客和其他一些奇怪的帐户(VUSRNEIL-DELL,$ HOMEGROUPUSER,ASPNET等等)

登录屏幕上不会显示这3个用户帐户.如何区分这些用户类型?

我在C#中编码

c# wmi user-accounts userprincipal

9
推荐指数
2
解决办法
1万
查看次数

扩展UserPrincipal; FindByIdentity()失败

扩展UserPrincipal以利用其内置属性...当我们重载FindByIdentity()方法时遇到问题.

来自Microsoft的示例http://msdn.microsoft.com/en-us/library/bb384372%28VS.90%29.aspx(为简洁起见,不包括部分):

[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("inetOrgPerson")]
public class InetOrgPerson : UserPrincipal {

   // Implement the overloaded search method FindByIdentity
   public static new InetOrgPerson FindByIdentity(PrincipalContext context, 
                                                  string identityValue) {
       return (InetOrgPerson)FindByIdentityWithType(context,
                                                    typeof(InetOrgPerson),
                                                    identityValue);
   }

   // Implement the overloaded search method FindByIdentity
   public static new InetOrgPerson FindByIdentity(PrincipalContext context, 
                                                  IdentityType identityType, 
                                                  string identityValue) {
       return (InetOrgPerson)FindByIdentityWithType(context, 
                                                    typeof(InetOrgPerson), 
                                                    identityType,
                                                    identityValue);
   } 
}
Run Code Online (Sandbox Code Playgroud)

如果我从MSDN示例中获取确切的代码并将其粘贴到我的应用程序中,它就不起作用.调用InetOrgPerson.FindByIdentity()返回null,如下:

if (null == InetOrgPerson.FindByIdentity(principalContext, UserName)) {
     throw new Exception("bah");
}
Run Code Online (Sandbox Code Playgroud)

实际上,从内部InetOrgPerson.FindByIdentity()调用FindByIdentityWithType()返回null,如下: …

c# directoryservices active-directory account-management userprincipal

8
推荐指数
1
解决办法
5701
查看次数

如何使用System.DirectoryServices.AccountManagement命名空间获取Active Directory用户属性?

我想从用户获取Active Directory属性,我想使用System.DirectoryServices.AccountManagement.

我的代码:

public static void GetUserProperties(string dc,string user) 
        {
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, dc);
            UserPrincipal u = UserPrincipal.FindByIdentity(ctx, user);

            string firstname = u.GivenName;
            string lastname = u.Surname;
            string email = u.EmailAddress;
            string telephone = u.VoiceTelephoneNumber;

            ...//how I can get company and other properties?
        }
Run Code Online (Sandbox Code Playgroud)

c# properties active-directory principal userprincipal

7
推荐指数
1
解决办法
2万
查看次数