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


Java LdapContext.setRequestControls方法代码示例

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


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

示例1: getGroup

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
public Group getGroup(String groupName) throws GroupNotFoundException {
    LdapContext ctx = null;
    try {
        String groupDN = manager.findGroupDN(groupName);
        // Load record.
        ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
        Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);

        return processGroup(ctx, attrs);
    }
    catch (Exception e) {
        Log.error(e.getMessage(), e);
        throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
    }
    finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:27,代码来源:LdapGroupProvider.java

示例2: prepareNextPage

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
private boolean prepareNextPage(LdapContext ldapContext) throws Exception {
    Control[] responseControls = ldapContext.getResponseControls();

    byte[] cookie = null;
    if (responseControls != null) {
        for (Control responseControl : responseControls) {
            if (responseControl instanceof PagedResultsResponseControl) {
                PagedResultsResponseControl prrc = (PagedResultsResponseControl) responseControl;
                cookie = prrc.getCookie();
            }
        }
    }

    if (cookie == null) {
        return false;
    } else {
        ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pageSize, cookie, Control.CRITICAL)});
        return true;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:LdapProducer.java

示例3: pagedSearch

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
private List<SearchResult> pagedSearch(LdapContext ldapContext, String searchFilter) throws Exception {
    List<SearchResult> data = new ArrayList<SearchResult>();

    log.trace("Using paged ldap search, pageSize={}", pageSize);

    Control[] requestControls = new Control[]{new PagedResultsControl(pageSize, Control.CRITICAL)};
    ldapContext.setRequestControls(requestControls);
    do {
        List<SearchResult> pageResult = simpleSearch(ldapContext, searchFilter);
        data.addAll(pageResult);
        log.trace("Page returned {} entries", pageResult.size());
    } while (prepareNextPage(ldapContext));

    if (log.isDebugEnabled()) {
        log.debug("Found a total of {} entries for ldap filter {}", data.size(), searchFilter);
    }

    return data;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:LdapProducer.java

示例4: getCookie

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
private byte[] getCookie(final LdapContext ctx) throws NamingException, IOException {
    byte[] cookie = null;
    // Examine the paged results control response
    final Control[] controls = ctx.getResponseControls();
    if (controls != null) {
        for (int i = 0; i < controls.length; i++) {
            if (controls[i] instanceof PagedResultsResponseControl) {
                final PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i];
                cookie = prrc.getCookie();
            }
        }
    }
    // Re-activate paged results
    ctx.setRequestControls(new Control[] { new PagedResultsControl(PAGE_SIZE, cookie, Control.CRITICAL) });
    return cookie;
}
 
开发者ID:huihoo,项目名称:olat,代码行数:17,代码来源:LDAPLoginManagerImpl.java

示例5: userList

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
public static ArrayList<String> userList()
{
		loadAdmindetails();
		System.out.println("Details Loaded");

		Properties props = new Properties();
		props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
		props.put(Context.PROVIDER_URL, url);
		props.put(Context.SECURITY_PRINCIPAL, "cn="+ldapadminuname+",dc=serverless,dc=com");//adminuser - User with special priviledge, dn user
		props.put(Context.SECURITY_CREDENTIALS, ldapadminpassword);//dn user password

		ArrayList<String> resp = new ArrayList<String>();
		try {
			LdapContext ctx = new InitialLdapContext(props, null);
			ctx.setRequestControls(null);
			NamingEnumeration<?> namingEnum = ctx.search("ou=ias,dc=serverless,dc=com", "(objectclass=posixAccount)", AuthenticationService.getSimpleSearchControls());
			while (namingEnum.hasMore ()) {
				SearchResult result = (SearchResult) namingEnum.next ();    
				Attributes attrs = result.getAttributes ();
				resp.add(attrs.get("cn").toString().substring(4));
			} 
			namingEnum.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resp;
	}
 
开发者ID:hemantverma1,项目名称:ServerlessPlatform,代码行数:28,代码来源:AuthenticationService.java

示例6: getGroup

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
@Override
public Group getGroup(String groupName) throws GroupNotFoundException {
    LdapContext ctx = null;
    try {
        String groupDN = manager.findGroupDN(groupName);
        // Load record.
        ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
        Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);

        return processGroup(ctx, attrs);
    }
    catch (Exception e) {
        Log.error(e.getMessage(), e);
        throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
    }
    finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:28,代码来源:LdapGroupProvider.java

示例7: hasNextPage

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
public boolean hasNextPage(DirContext ctx, int pageSize)
{
    if (pageSize > 0)
    {
        try
        {
            LdapContext ldapContext = (LdapContext) ctx;
            Control[] controls = ldapContext.getResponseControls();

            // Retrieve the paged result cookie if there is one
            if (controls != null)
            {
                for (Control control : controls)
                {
                    if (control instanceof PagedResultsResponseControl)
                    {
                        byte[] cookie = ((PagedResultsResponseControl) control).getCookie();
                        if (cookie != null)
                        {
                            // Prepare for next page
                            ldapContext.setRequestControls(new Control[]
                            {
                                new PagedResultsControl(pageSize, cookie, Control.CRITICAL)
                            });
                            return true;
                        }
                    }
                }
            }
        }
        catch (NamingException nx)
        {
            throw new AuthenticationException("Unable to connect to LDAP Server; check LDAP configuration", nx);
        }
        catch (IOException e)
        {
            throw new AuthenticationException(
                    "Unable to encode LDAP v3 request controls; check LDAP configuration", e);
        }

    }
    return false;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:44,代码来源:LDAPInitialDirContextFactoryImpl.java

示例8: searchUsers

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
@Override
public List<LdapUser> searchUsers(final String username, final LdapContext context) throws NamingException, IOException {

    final SearchControls searchControls = new SearchControls();

    searchControls.setSearchScope(_ldapConfiguration.getScope());
    searchControls.setReturningAttributes(_ldapConfiguration.getReturnAttributes());

    final String basedn = _ldapConfiguration.getBaseDn();
    if (StringUtils.isBlank(basedn)) {
        throw new IllegalArgumentException("ldap basedn is not configured");
    }
    byte[] cookie = null;
    final int pageSize = _ldapConfiguration.getLdapPageSize();
    context.setRequestControls(new Control[]{new PagedResultsControl(pageSize, Control.NONCRITICAL)});
    final List<LdapUser> users = new ArrayList<>();
    NamingEnumeration<SearchResult> results;
    do {
        results = context.search(basedn, generateSearchFilter(username), searchControls);
        while (results.hasMoreElements()) {
            final SearchResult result = results.nextElement();
            if (!isUserDisabled(result)) {
                users.add(createUser(result));
            }
        }
        final Control[] contextControls = context.getResponseControls();
        if (contextControls != null) {
            for (final Control control : contextControls) {
                if (control instanceof PagedResultsResponseControl) {
                    final PagedResultsResponseControl prrc = (PagedResultsResponseControl) control;
                    cookie = prrc.getCookie();
                }
            }
        } else {
            s_logger.info("No controls were sent from the ldap server");
        }
        context.setRequestControls(new Control[]{new PagedResultsControl(pageSize, cookie, Control.CRITICAL)});
    } while (cookie != null);

    return users;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:42,代码来源:OpenLdapUserManagerImpl.java

示例9: hasNextPage

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
// copied from default Alfresco class
public boolean hasNextPage(final DirContext ctx, final int pageSize)
{
    if (pageSize > 0)
    {
        try
        {
            final LdapContext ldapContext = (LdapContext) ctx;
            final Control[] controls = ldapContext.getResponseControls();

            // Retrieve the paged result cookie if there is one
            if (controls != null)
            {
                for (final Control control : controls)
                {
                    if (control instanceof PagedResultsResponseControl)
                    {
                        final byte[] cookie = ((PagedResultsResponseControl) control).getCookie();
                        if (cookie != null)
                        {
                            // Prepare for next page
                            ldapContext
                                    .setRequestControls(new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });
                            return true;
                        }
                    }
                }
            }
        }
        catch (final NamingException nx)
        {
            throw new AuthenticationException("Unable to connect to LDAP Server; check LDAP configuration", nx);
        }
        catch (final IOException e)
        {
            throw new AuthenticationException("Unable to encode LDAP v3 request controls; check LDAP configuration", e);
        }

    }
    return false;
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:46,代码来源:LDAPInitialDirContextFactoryImpl.java

示例10: getSample

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
/**
 * Returns a list of usernames with a sample of the users found in LDAP.
 *
 * @param maxSample the max size of the sample to return.
 * @return a list of usernames with a sample of the users found in LDAP.
 * @throws NamingException if something goes wrong....
 */
public List<String> getSample(int maxSample) throws NamingException {
    List<String> usernames = new ArrayList<>();
    LdapContext ctx = null;

    try {
        ctx = manager.getContext();

        // Sort on username field.
        Control[] searchControl;
        try {
            searchControl = new Control[]{
                    new SortControl(new String[]{manager.getUsernameField()}, Control.NONCRITICAL)
            };
        } catch (IOException e) {
            Log.error(e.getMessage(), e);
            return Collections.emptyList();
        }
        ctx.setRequestControls(searchControl);

        // Search for the dn based on the username.
        SearchControls searchControls = new SearchControls();
        // See if recursive searching is enabled. Otherwise, only search one level.
        if (manager.isSubTreeSearch()) {
            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        } else {
            searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        }
        searchControls.setReturningAttributes(new String[]{manager.getUsernameField()});
        // Limit results to those we'll need to process
        searchControls.setCountLimit(maxSample);
        String filter = MessageFormat.format(manager.getSearchFilter(), "*");
        NamingEnumeration answer = ctx.search("", filter, searchControls);

        while (answer.hasMoreElements()) {
            // Get the next userID.
            String username = (String) ((SearchResult) answer.next()).getAttributes().get(
                    manager.getUsernameField()).get();
            // Escape username and add to results.
            usernames.add(JID.escapeNode(username));
        }
        // Close the enumeration.
        answer.close();
    } finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
    return usernames;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:63,代码来源:LdapUserTester.java

示例11: getSample

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
/**
 * Returns a list of usernames with a sample of the users found in LDAP.
 *
 * @param maxSample the max size of the sample to return.
 * @return a list of usernames with a sample of the users found in LDAP.
 * @throws NamingException if something goes wrong....
 */
public List<String> getSample(int maxSample) throws NamingException {
    List<String> usernames = new ArrayList<String>();
    LdapContext ctx = null;

    try {
        ctx = manager.getContext();

        // Sort on username field.
        Control[] searchControl;
        try {
            searchControl = new Control[]{
                    new SortControl(new String[]{manager.getUsernameField()}, Control.NONCRITICAL)
            };
        } catch (IOException e) {
            Log.error(e.getMessage(), e);
            return Collections.emptyList();
        }
        ctx.setRequestControls(searchControl);

        // Search for the dn based on the username.
        SearchControls searchControls = new SearchControls();
        // See if recursive searching is enabled. Otherwise, only search one level.
        if (manager.isSubTreeSearch()) {
            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        } else {
            searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        }
        searchControls.setReturningAttributes(new String[]{manager.getUsernameField()});
        // Limit results to those we'll need to process
        searchControls.setCountLimit(maxSample);
        String filter = MessageFormat.format(manager.getSearchFilter(), "*");
        NamingEnumeration answer = ctx.search("", filter, searchControls);

        while (answer.hasMoreElements()) {
            // Get the next userID.
            String username = (String) ((SearchResult) answer.next()).getAttributes().get(
                    manager.getUsernameField()).get();
            // Escape username and add to results.
            usernames.add(JID.escapeNode(username));
        }
        // Close the enumeration.
        answer.close();
    } finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
    return usernames;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:63,代码来源:LdapUserTester.java

示例12: searchUsers

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
@Override
public List<LdapUser> searchUsers(final String username, final LdapContext context, Long domainId) throws NamingException, IOException {

    final SearchControls searchControls = new SearchControls();

    searchControls.setSearchScope(_ldapConfiguration.getScope());
    searchControls.setReturningAttributes(_ldapConfiguration.getReturnAttributes(domainId));

    String basedn = _ldapConfiguration.getBaseDn(domainId);
    if (StringUtils.isBlank(basedn)) {
        throw new IllegalArgumentException("ldap basedn is not configured");
    }
    byte[] cookie = null;
    int pageSize = _ldapConfiguration.getLdapPageSize(domainId);
    context.setRequestControls(new Control[]{new PagedResultsControl(pageSize, Control.NONCRITICAL)});
    final List<LdapUser> users = new ArrayList<LdapUser>();
    NamingEnumeration<SearchResult> results;
    do {
        results = context.search(basedn, generateSearchFilter(username, domainId), searchControls);
        while (results.hasMoreElements()) {
            final SearchResult result = results.nextElement();
            if (!isUserDisabled(result)) {
                users.add(createUser(result, domainId));
            }
        }
        Control[] contextControls = context.getResponseControls();
        if (contextControls != null) {
            for (Control control : contextControls) {
                if (control instanceof PagedResultsResponseControl) {
                    PagedResultsResponseControl prrc = (PagedResultsResponseControl) control;
                    cookie = prrc.getCookie();
                }
            }
        } else {
            s_logger.info("No controls were sent from the ldap server");
        }
        context.setRequestControls(new Control[] {new PagedResultsControl(pageSize, cookie, Control.CRITICAL)});
    } while (cookie != null);

    return users;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:42,代码来源:OpenLdapUserManagerImpl.java


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