当前位置: 首页>>代码示例>>Java>>正文


Java SearchResult.getNameInNamespace方法代码示例

本文整理汇总了Java中javax.naming.directory.SearchResult.getNameInNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.getNameInNamespace方法的具体用法?Java SearchResult.getNameInNamespace怎么用?Java SearchResult.getNameInNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.directory.SearchResult的用法示例。


在下文中一共展示了SearchResult.getNameInNamespace方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dnFromUser

import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
private static String dnFromUser(String username) throws NamingException {
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    props.put(Context.PROVIDER_URL, "ldap://ldap.example.com");
    props.put(Context.REFERRAL, "ignore");

    InitialDirContext context = new InitialDirContext(props);

    SearchControls ctrls = new SearchControls();
    ctrls.setReturningAttributes(new String[]{"givenName", "sn"});
    ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    NamingEnumeration<SearchResult> answers = context.search("dc=People,dc=example,dc=com", "(uid=" + username + ")", ctrls);
    SearchResult result = answers.next();

    return result.getNameInNamespace();
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:18,代码来源:JndiLdap.java

示例2: retrieveName

import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
String retrieveName(Properties ldapProps, SearchResult res) {
    String name = "";
    if (res.isRelative()) {
        name = res.getName();
    } else {
        name = res.getNameInNamespace();
        String urlName = res.getName();
        int index = urlName.lastIndexOf("/");
        if (index > 0) {
            ldapProps.put(Context.PROVIDER_URL,
                    urlName.substring(0, index));
        }

    }
    return name;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:ADMRealmImpl.java

示例3: getUserLogin

import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
/**
 * @param csUser: specific user we want to login
 * @param csPassword: specific password
 * @param bUseGenericUser: true if connecting using generic user, not the specific user (csUser / csPassword); in that case csUser/csPassword is ignored   
 * @return String UserDN; set to null or empty if user did not login correctly.
 */
public String getUserLogin(String csUser, String csPassword, boolean bUseGenericUser)
{
	String csUserLogin = csUser;
	String csPasswordLogin = csPassword;
	if (bUseGenericUser)
	{
		csUserLogin = m_csLDAPGenericUser;
		csPasswordLogin = m_csLDAPGenericPassword;
	}
	
	if (!validateLogin(csUserLogin, csPasswordLogin))
	{
		return null ;
	}
	if (m_ldap == null)
	{
		return null ;
	}
	
	NamingEnumeration enumer = m_ldap.searchSubtree(m_csLDAPRootOU, "sAMAccountName="+csUser) ;
	if (enumer.hasMoreElements())
	{
		SearchResult res = (SearchResult)enumer.nextElement() ;
		String name = res.getNameInNamespace() ;
		return name ;
	}
	return null;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:35,代码来源:LdapRequester.java

示例4: doGetGroups

import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
List<String> doGetGroups(String user) throws NamingException {
  List<String> groups = new ArrayList<String>();

  DirContext ctx = getDirContext();

  // Search for the user. We'll only ever need to look at the first result
  NamingEnumeration<SearchResult> results = ctx.search(baseDN,
      userSearchFilter,
      new Object[]{user},
      SEARCH_CONTROLS);
  if (results.hasMoreElements()) {
    SearchResult result = results.nextElement();
    String userDn = result.getNameInNamespace();

    NamingEnumeration<SearchResult> groupResults =
        ctx.search(baseDN,
            "(&" + groupSearchFilter + "(" + groupMemberAttr + "={0}))",
            new Object[]{userDn},
            SEARCH_CONTROLS);
    while (groupResults.hasMoreElements()) {
      SearchResult groupResult = groupResults.nextElement();
      Attribute groupName = groupResult.getAttributes().get(groupNameAttr);
      groups.add(groupName.get().toString());
    }
  }

  return groups;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:29,代码来源:LdapGroupsMapping.java

示例5: doGetGroups

import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
List<String> doGetGroups(String user) throws NamingException {
  List<String> groups = new ArrayList<String>();

  DirContext ctx = getDirContext();

  // Search for the user. We'll only ever need to look at the first result
  NamingEnumeration<SearchResult> results = ctx.search(baseDN,
      userSearchFilter,
      new Object[]{user},
      SEARCH_CONTROLS);
  if (results.hasMoreElements()) {
    SearchResult result = results.nextElement();
    String userDn = result.getNameInNamespace();

    NamingEnumeration<SearchResult> groupResults = null;

    if (isPosix) {
      String gidNumber = null;
      String uidNumber = null;
      Attribute gidAttribute = result.getAttributes().get(posixGidAttr);
      Attribute uidAttribute = result.getAttributes().get(posixUidAttr);
      if (gidAttribute != null) {
        gidNumber = gidAttribute.get().toString();
      }
      if (uidAttribute != null) {
        uidNumber = uidAttribute.get().toString();
      }
      if (uidNumber != null && gidNumber != null) {
        groupResults =
            ctx.search(baseDN,
                "(&"+ groupSearchFilter + "(|(" + posixGidAttr + "={0})" +
                    "(" + groupMemberAttr + "={1})))",
                new Object[] { gidNumber, uidNumber },
                SEARCH_CONTROLS);
      }
    } else {
      groupResults =
          ctx.search(baseDN,
              "(&" + groupSearchFilter + "(" + groupMemberAttr + "={0}))",
              new Object[]{userDn},
              SEARCH_CONTROLS);
    }
    if (groupResults != null) {
      while (groupResults.hasMoreElements()) {
        SearchResult groupResult = groupResults.nextElement();
        Attribute groupName = groupResult.getAttributes().get(groupNameAttr);
        groups.add(groupName.get().toString());
      }
    }
  }

  return groups;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:54,代码来源:LdapGroupsMapping.java

示例6: mapToNode

import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
private NodeDescription mapToNode(Map<String, String> attributeMapping, Map<String, String> attributeDefaults,
        SearchResult result) throws NamingException
{
    NodeDescription nodeDescription = new NodeDescription(result.getNameInNamespace());
    Attributes ldapAttributes = result.getAttributes();

    // Parse the timestamp
    Attribute modifyTimestamp = ldapAttributes.get(this.modifyTimestampAttributeName);
    if (modifyTimestamp != null)
    {
        try
        {
            nodeDescription.setLastModified(this.timestampFormat.parse(modifyTimestamp.get().toString()));
        }
        catch (ParseException e)
        {
            throw new AlfrescoRuntimeException("Failed to parse timestamp.", e);
        }
    }

    // Apply the mapped attributes
    PropertyMap properties = nodeDescription.getProperties();
    for (String key : attributeMapping.keySet())
    {
        QName keyQName = QName.createQName(key, this.namespaceService);

        // cater for null
        String attributeName = attributeMapping.get(key);
        if (attributeName != null)
        {
            Attribute attribute = ldapAttributes.get(attributeName);
            String defaultAttribute = attributeDefaults.get(key);
            
            if (attribute != null)
            {
                String value = (String) attribute.get(0);
                if (value != null)
                {
                    properties.put(keyQName, value);
                }
            }
            else if (defaultAttribute != null)
            {
                properties.put(keyQName, defaultAttribute);
            }
            else
            {
                // Make sure that a 2nd sync, updates deleted ldap attributes(MNT-14026)
                properties.put(keyQName, null);
            }
        }
        else
        {
            String defaultValue = attributeDefaults.get(key);
            if (defaultValue != null)
            {
                properties.put(keyQName, defaultValue);
            }
        }
    }
    return nodeDescription;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:63,代码来源:LDAPUserRegistry.java

示例7: PersonCollection

import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
/**
 * Instantiates a new person collection.
 * 
 * @param modifiedSince
 *            if non-null, then only descriptions of users modified since this date should be returned; if
 *            <code>null</code> then descriptions of all users should be returned.
 */
public PersonCollection(Date modifiedSince)
{
    // Choose / generate the appropriate query
    if (modifiedSince == null)
    {
        this.query = LDAPUserRegistry.this.personQuery;
    }
    else
    {
        this.query = MessageFormat.format(LDAPUserRegistry.this.personDifferentialQuery,
                LDAPUserRegistry.this.timestampFormat.format(modifiedSince));
    }

    // Estimate the size of this collection by running the entire query once, if progress
    // estimation is enabled
    if (LDAPUserRegistry.this.enableProgressEstimation)
    {
        class CountingCallback extends AbstractSearchCallback
        {
            int count;

            /*
             * (non-Javadoc)
             * @see
             * org.alfresco.repo.security.sync.ldap.LDAPUserRegistry.SearchCallback#process(javax.naming.directory
             * .SearchResult)
             */
            protected void doProcess(SearchResult result) throws NamingException, ParseException
            {
                this.count++;
                if (LDAPUserRegistry.logger.isDebugEnabled())
                {
                    String personName = result.getNameInNamespace();
                    LDAPUserRegistry.logger.debug("Processing person: " + personName);
                }
            }

            /*
             * (non-Javadoc)
             * @see org.alfresco.repo.security.sync.ldap.LDAPUserRegistry.SearchCallback#close()
             */
            public void close() throws NamingException
            {
            }

        }
        CountingCallback countingCallback = new CountingCallback();
        processQuery(countingCallback, LDAPUserRegistry.this.userSearchBase, this.query, new String[] {});
        this.totalEstimatedSize = countingCallback.count;
    }
    else
    {
        this.totalEstimatedSize = -1;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:63,代码来源:LDAPUserRegistry.java


注:本文中的javax.naming.directory.SearchResult.getNameInNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。