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


Java SearchResult类代码示例

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


SearchResult类属于javax.naming.directory包,在下文中一共展示了SearchResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setupMocks

import javax.naming.directory.SearchResult; //导入依赖的package包/类
@Before
public void setupMocks() throws NamingException {
  SearchResult mockUserResult = mock(SearchResult.class);
  when(mockUserNamingEnum.nextElement()).thenReturn(mockUserResult);

  Attribute mockUidNumberAttr = mock(Attribute.class);
  Attribute mockGidNumberAttr = mock(Attribute.class);
  Attribute mockUidAttr = mock(Attribute.class);
  Attributes mockAttrs = mock(Attributes.class);

  when(mockUidAttr.get()).thenReturn("some_user");
  when(mockUidNumberAttr.get()).thenReturn("700");
  when(mockGidNumberAttr.get()).thenReturn("600");
  when(mockAttrs.get(eq("uid"))).thenReturn(mockUidAttr);
  when(mockAttrs.get(eq("uidNumber"))).thenReturn(mockUidNumberAttr);
  when(mockAttrs.get(eq("gidNumber"))).thenReturn(mockGidNumberAttr);

  when(mockUserResult.getAttributes()).thenReturn(mockAttrs);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:TestLdapGroupsMappingWithPosixGroup.java

示例3: sync

import javax.naming.directory.SearchResult; //导入依赖的package包/类
/**
 * Performs the actual sync of the specified user.
 * @param ctx a DirContext
 * @param qm the AlpineQueryManager to use
 * @param sc the SearchControls to use
 * @param user the LdapUser instance to sync
 * @throws NamingException when a problem with the connection with the directory
 */
private void sync(DirContext ctx, AlpineQueryManager qm, SearchControls sc, LdapUser user) throws NamingException {
    final String searchFor = LDAP_ATTRIBUTE_NAME + "=" + formatPrincipal(user.getUsername());

    LOGGER.debug("Syncing: " + user.getUsername());

    final List<SearchResult> results = Collections.list(ctx.search(BASE_DN, searchFor, sc));
    if (results.size() > 0) {
        // Should only return 1 result, but just in case, get the very first one
        final SearchResult result = results.get(0);

        user.setDN(result.getNameInNamespace());
        final Attribute mail = result.getAttributes().get(ATTRIBUTE_MAIL);
        if (mail != null) {
            // user.setMail(mail.get()); //todo
        }
    } else {
        // This is an invalid user - a username that exists in the database that does not exist in LDAP
        user.setDN("INVALID");
        // user.setMail(null); //todo
    }
    qm.updateLdapUser(user);
}
 
开发者ID:stevespringett,项目名称:Alpine,代码行数:31,代码来源:LdapSyncTask.java

示例4: process

import javax.naming.directory.SearchResult; //导入依赖的package包/类
@Override
public void process(SearchResult result) throws NamingException, ParseException
{
    try
    {
        doProcess(result);
    }
    finally
    {
        Object obj = result.getObject();
        
        if (obj != null && obj instanceof Context)
        {
            try
            {
                ((Context)obj).close();
            }
            catch (NamingException e)
            {
                logger.debug("error when closing result block context", e);
            }
            obj = null;
        }
        result = null;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:LDAPUserRegistry.java

示例5: getMockedLDAPSearchResult

import javax.naming.directory.SearchResult; //导入依赖的package包/类
private LDAPInitialDirContextFactoryImpl getMockedLDAPSearchResult(boolean withEmail) throws NamingException
{
    @SuppressWarnings("unchecked")
    NamingEnumeration<SearchResult> mockedNamingEnumeration = mock(NamingEnumeration.class);
    when(mockedNamingEnumeration.hasMore()).thenReturn(true).thenReturn(false);

    BasicAttributes attributes = new BasicAttributes();
    attributes.put(new BasicAttribute("sAMAccountName", "U1"));
    attributes.put(new BasicAttribute("givenName", "U1"));
    if (withEmail)
    {
        attributes.put(new BasicAttribute("mail", "[email protected]"));
    }
    SearchResult mockedSearchResult = new SearchResult("CN:U1", null, attributes);
    mockedSearchResult.setNameInNamespace("CN:U1");

    when(mockedNamingEnumeration.next()).thenReturn(mockedSearchResult);

    InitialDirContext mockedInitialDirContext = mock(InitialDirContext.class);
    when(mockedInitialDirContext.search(any(String.class), any(String.class), any(SearchControls.class))).thenReturn(mockedNamingEnumeration);

    LDAPInitialDirContextFactoryImpl mockedLdapInitialDirContextFactory = mock(LDAPInitialDirContextFactoryImpl.class);
    when(mockedLdapInitialDirContextFactory.getDefaultIntialDirContext(0)).thenReturn(mockedInitialDirContext);
    return mockedLdapInitialDirContextFactory;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:ChainingUserRegistrySynchronizerTest.java

示例6: retrieveName_notRelative

import javax.naming.directory.SearchResult; //导入依赖的package包/类
@Test
public void retrieveName_notRelative() {
    // given
    SearchResult searchResult = new SearchResult(null, null, null, false);
    searchResult.setNameInNamespace("cn=ldap01");
    searchResult
            .setName("ldap://estdevmail1.dev.est.fujitsu.com:389/cn=ldap01");
    ldapProps.put(Context.PROVIDER_URL, "");
    // when
    String name = realmImpl.retrieveName(ldapProps, searchResult);

    // then
    assertEquals("cn=ldap01", name);
    assertEquals("ldap://estdevmail1.dev.est.fujitsu.com:389",
            ldapProps.getProperty(Context.PROVIDER_URL));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:ADMRealmImplTest.java

示例7: 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

示例8: formatUserEnName

import javax.naming.directory.SearchResult; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private List<String> formatUserEnName(SearchResult sResult) {

    if (null == sResult) {
        return Collections.emptyList();
    }

    List<String> result = new ArrayList<String>();
    try {
        String memberKey = ldapConfig.get("memberKey");
        NamingEnumeration namingEnumeration = sResult.getAttributes().getAll();
        while (namingEnumeration.hasMoreElements()) {
            Attribute attr = (Attribute) namingEnumeration.next();
            String attrId = attr.getID();
            if (memberKey.equals(attrId)) {
                List<String> userEnNames = formatUserEnName(attr);
                result.addAll(userEnNames);
            }
        }

    }
    catch (Exception e) {
        loggerError("formatUserEnName 619", "", e);
    }
    return result;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:27,代码来源:GUISSOLdapClient.java

示例9: ldapInjectionSunApi

import javax.naming.directory.SearchResult; //导入依赖的package包/类
public void ldapInjectionSunApi(String input) throws NamingException {
    //Stub instances
    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");

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

    //Two context instances mostly usable with sun specific API
    LdapCtx            context5 = null;
    EventDirContext    context6 = null; //LdapCtx is the only known class to implements to this interface

    NamingEnumeration<SearchResult> answers;
    answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);

    answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:27,代码来源:JndiLdapAdditionalSignature.java

示例10: getUserAttributes

import javax.naming.directory.SearchResult; //导入依赖的package包/类
public static Map<String, String> getUserAttributes(DirContext ctx, String searchBase, String userName,
    String principalDomain, String... attributeNames)
    throws NamingException {
  if (StringUtils.isBlank(userName)) {
    throw new IllegalArgumentException("Username and password can not be blank.");
  }

  if (attributeNames.length == 0) {
    return Collections.emptyMap();
  }

  Attributes matchAttr = new BasicAttributes(true);
  BasicAttribute basicAttr = new BasicAttribute("userPrincipalName", userName + principalDomain);
  matchAttr.put(basicAttr);

  NamingEnumeration<? extends SearchResult> searchResult = ctx.search(searchBase, matchAttr, attributeNames);

  if (ctx != null) {
    ctx.close();
  }

  Map<String, String> result = new HashMap<>();

  if (searchResult.hasMore()) {
    NamingEnumeration<? extends Attribute> attributes = searchResult.next().getAttributes().getAll();

    while (attributes.hasMore()) {
      Attribute attr = attributes.next();
      String attrId = attr.getID();
      String attrValue = (String) attr.get();

      result.put(attrId, attrValue);
    }
  }
  return result;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:37,代码来源:AuthenticationManager.java

示例11: setupMocksBase

import javax.naming.directory.SearchResult; //导入依赖的package包/类
@Before
public void setupMocksBase() throws NamingException {
  mockContext = mock(DirContext.class);
  doReturn(mockContext).when(mappingSpy).getDirContext();

  // We only ever call hasMoreElements once for the user NamingEnum, so
  // we can just have one return value
  when(mockUserNamingEnum.hasMoreElements()).thenReturn(true);

  SearchResult mockGroupResult = mock(SearchResult.class);
  // We're going to have to define the loop here. We want two iterations,
  // to get both the groups
  when(mockGroupNamingEnum.hasMoreElements()).thenReturn(true, true, false);
  when(mockGroupNamingEnum.nextElement()).thenReturn(mockGroupResult);

  // Define the attribute for the name of the first group
  Attribute group1Attr = new BasicAttribute("cn");
  group1Attr.add(testGroups[0]);
  Attributes group1Attrs = new BasicAttributes();
  group1Attrs.put(group1Attr);

  // Define the attribute for the name of the second group
  Attribute group2Attr = new BasicAttribute("cn");
  group2Attr.add(testGroups[1]);
  Attributes group2Attrs = new BasicAttributes();
  group2Attrs.put(group2Attr);

  // This search result gets reused, so return group1, then group2
  when(mockGroupResult.getAttributes()).thenReturn(group1Attrs, group2Attrs);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:31,代码来源:TestLdapGroupsMappingBase.java

示例12: search

import javax.naming.directory.SearchResult; //导入依赖的package包/类
public NamingEnumeration<SearchResult> search(Name name,
                            String filterExpr,
                            Object[] args,
                            SearchControls cons)
throws NamingException {
    DirContextNamePair res = getTargetContext(name);
    return res.getDirContext().search(res.getName(), filterExpr, args,
                                     cons);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ContinuationDirContext.java

示例13: findUserDn

import javax.naming.directory.SearchResult; //导入依赖的package包/类
/**
 * Finds a distinguished name(DN) of a user by querying the active directory LDAP context for the
 * specified username.
 */
protected String findUserDn(LdapContextFactory ldapContextFactory, String username) throws NamingException {
    LdapContext ctx = null;
    try {
        // Binds using the system username and password.
        ctx = ldapContextFactory.getSystemLdapContext();

        final SearchControls ctrl = new SearchControls();
        ctrl.setCountLimit(1);
        ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
        ctrl.setTimeLimit(searchTimeoutMillis);

        final String filter =
                searchFilter != null ? USERNAME_PLACEHOLDER.matcher(searchFilter)
                                                           .replaceAll(username)
                                     : username;
        final NamingEnumeration<SearchResult> result = ctx.search(searchBase, filter, ctrl);
        try {
            if (!result.hasMore()) {
                throw new AuthenticationException("No username: " + username);
            }
            return result.next().getNameInNamespace();
        } finally {
            result.close();
        }
    } finally {
        LdapUtils.closeContext(ctx);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:33,代码来源:SearchFirstActiveDirectoryRealm.java

示例14: search

import javax.naming.directory.SearchResult; //导入依赖的package包/类
public NamingEnumeration<SearchResult> search(Name name,
                            Attributes matchingAttributes,
                            String[] attributesToReturn)
throws NamingException  {
    DirContextNamePair res = getTargetContext(name);
    return res.getDirContext().search(res.getName(), matchingAttributes,
                                     attributesToReturn);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:ContinuationDirContext.java

示例15: getUserByLoginImpl

import javax.naming.directory.SearchResult; //导入依赖的package包/类
@Override
protected Map<String, String> getUserByLoginImpl(String loginId, String password) {

    String suffix = ldapConfig.get("suffix");

    if (loginId.indexOf(suffix) == -1) {
        loginId += suffix;
    }

    boolean login = ldapApiCheck(loginId, password);
    String primaryKey = ldapConfig.get("primaryKey");
    if (!login) {
        return Collections.emptyMap();
    }

    String action = "login";
    String filter = primaryKey + "=" + loginId;

    List<SearchResult> sResultList = ldapApiQuery(action, "", filter);
    // filter userPrincipalName= 只能查询到一个结果
    SearchResult sResult = sResultList.get(0);

    String groupIdStr = formatGroupId(sResult);
    String emailListStr = formatEmailList(sResult);

    Map<String, String> result = new HashMap<String, String>();
    result.put("loginId", loginId);
    result.put("groupId", groupIdStr);
    result.put("emailList", emailListStr);

    return result;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:33,代码来源:GUISSOLdapClient.java


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