• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DN类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getUserRoles

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
@Override
public Set<String> getUserRoles(String username) throws Exception {
    LOGGER.debug("getRoles("+username+")");

    Objects.requireNonNull(username);

    Set<String> roles = new HashSet<>();

    String filter = "(uid=" + username + ")";

    SearchRequest searchRequest = new SearchRequest(searchBase, SearchScope.SUB, filter);
    SearchResult searchResult = connectionPool.search(searchRequest);
    List<SearchResultEntry> searchResultEntries = searchResult.getSearchEntries();

    if(searchResultEntries.isEmpty()) {
        LOGGER.warn("No result found roles for user: " + username);
        return new HashSet<String>();
    } else if (searchResultEntries.size() > 1) {
        LOGGER.error("Multiples users found and only one was expected for user: " + username);
        return new HashSet<String>();
    } else {
        for(SearchResultEntry searchResultEntry : searchResultEntries) {
            String[] groups = searchResultEntry.getAttributeValues("memberOf");
            if(null != groups) {
                for(String group : groups) {
                    for (RDN rdn : new DN(group).getRDNs()) {
                        if (rdn.hasAttribute("cn")) {
                            roles.addAll(Arrays.asList(rdn.getAttributeValues()));
                            break;
                        }
                    }
                }
            }
        }
    }

    return roles;
}
 
开发者ID:lightblue-platform,项目名称:lightblue-rest,代码行数:39,代码来源:LdapRolesProvider.java


示例2: getUser

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
public User getUser(String username) {

		User user = new User();

		try {

			List<SearchResultEntry> searchResultEntries = search(getLoginFilter(username));
			if (!searchResultEntries.isEmpty()) {

				SearchResultEntry searchResultEntry = searchResultEntries.get(0);

				user.setUsername(username);
				user.setGivenName(searchResultEntry.getAttributeValue(givenNameAttribute));
				user.setSurName(searchResultEntry.getAttributeValue(surNameAttribute));
				user.setEmail(searchResultEntry.getAttributeValue(mailAttribute));

				List<String> groups = new ArrayList<>();            	
				String[] groupAttributeValues = searchResultEntry.getAttributeValues(groupAttribute);
				for (String groupAttributeValue : groupAttributeValues) {
					DN groupDN = new DN(groupAttributeValue);
					String groupName = groupDN.getRDN().getAttributeValues()[0];
					groups.add(groupName);
				}
				
				user.setGroups(groups);
			}
		}
		catch(Exception e) {
			LOG.error(e.getMessage(), e);
		}

		return user;
	}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:34,代码来源:DirectoryService.java


示例3: getDNDomainComponent

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
public static String getDNDomainComponent(String dn) throws LDAPException {
    StringBuilder ret = new StringBuilder();
    for (RDN rdn : new DN(DN.normalize(dn)).getRDNs()) {
        for (String name : rdn.getAttributeNames()) {
            if ("dc".equals(name)) {
                for (String value : rdn.getAttributeValues()) {
                    if (ret.length() > 0) {
                        ret.append('.');
                    }
                    ret.append(value);
                }
            }
        }
    }
    return ret.toString();
}
 
开发者ID:oVirt,项目名称:ovirt-engine-extension-aaa-ldap,代码行数:17,代码来源:Framework.java


示例4: configureWithPort

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
protected InMemoryDirectoryServer configureWithPort(int port) throws LDAPException,BindException {
    LdapConfiguration config = defaultConfiguration();

    InMemoryListenerConfig listenerConfig = (port > 0) ?
            InMemoryListenerConfig.createLDAPConfig("default", config.port()) :
            InMemoryListenerConfig.createLDAPConfig("default");

    InMemoryDirectoryServerConfig c = new InMemoryDirectoryServerConfig(new DN(config.base().dn()));
    c.setListenerConfigs(listenerConfig);
    c.addAdditionalBindCredentials(config.bindDn(), config.password());
    c.setSchema(null);

    server = new InMemoryDirectoryServer(c);
    try {
        server.startListening();
        return server;
    } catch (LDAPException ldapException) {
        if (ldapException.getMessage().contains("java.net.BindException")) {
            throw new BindException(ldapException.getMessage());
        }
        throw ldapException;
    }
}
 
开发者ID:zoldar,项目名称:ldap-test-server-py4j,代码行数:24,代码来源:LdapPatchedServerResource.java


示例5: newEmbeddedServer

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName,
        String defaultPartitionSuffix, int port) throws Exception {
    InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(
            defaultPartitionSuffix);
    config.addAdditionalBindCredentials("uid=admin,ou=system", "secret");

    config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", port));

    config.setEnforceSingleStructuralObjectClass(false);
    config.setEnforceAttributeSyntaxCompliance(true);

    Entry entry = new Entry(new DN(defaultPartitionSuffix));
    entry.addAttribute("objectClass", "top", "domain", "extensibleObject");
    entry.addAttribute("dc", defaultPartitionName);

    InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config);
    directoryServer.add(entry);
    directoryServer.startListening();
    return new EmbeddedLdapServer(directoryServer);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:21,代码来源:EmbeddedLdapServer.java


示例6: configureWithPort

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
protected InMemoryDirectoryServer configureWithPort(int port) throws LDAPException, BindException {
	InMemoryListenerConfig listenerConfig = (port > 0) ?
			InMemoryListenerConfig.createLDAPConfig("default", config.port()) :
			InMemoryListenerConfig.createLDAPConfig("default");

	InMemoryDirectoryServerConfig c = new InMemoryDirectoryServerConfig(new DN(config.base().dn()));
	c.setListenerConfigs(listenerConfig);
	c.addAdditionalBindCredentials(config.bindDn(), config.password());
	if (!config.useSchema()) {
		c.setSchema(null);
	}
	server = new InMemoryDirectoryServer(c);
	try {
		server.startListening();
		return server;
	} catch (LDAPException ldape) {
		if (ldape.getMessage().contains("BindException")) {
			throw new BindException(ldape.getMessage());
		}
		throw ldape;
	}
}
 
开发者ID:trevershick,项目名称:ldap-test-utils,代码行数:23,代码来源:LdapServerResource.java


示例7: createAnyFilterFromDnList

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
/**
 * Creates any filter to load all objects represented by this dn list.
 *
 * @param p_filterAttributeName filter attribute name
 * @param p_dnList              dn list
 * @return filter
 */
public static Filter createAnyFilterFromDnList(String p_filterAttributeName, List<String> p_dnList) {
    try {
        if (p_dnList != null && !p_dnList.isEmpty()) {
            final StringBuilder sb = new StringBuilder("(|");
            for (String dn : p_dnList) {
                final DN dnObj = new DN(dn);
                final RDN rdn = dnObj.getRDN();
                if (rdn.getAttributeNames()[0].equals(p_filterAttributeName)) {
                    final String[] values = rdn.getAttributeValues();
                    if (values != null && values.length == 1) {
                        sb.append("(");
                        sb.append(p_filterAttributeName).append("=");
                        sb.append(values[0]);
                        sb.append(")");
                    }
                }
            }
            sb.append(")");
            final String filterAsString = sb.toString();
            log.trace("dnList: " + p_dnList + ", ldapFilter: " + filterAsString);
            return Filter.create(filterAsString);
        }
    } catch (LDAPException e) {
        log.trace(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:35,代码来源:LdapUtils.java


示例8: EmbeddedDirectoryServer

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
private EmbeddedDirectoryServer(@NotNull String dn, @NotNull URL ldifStream) throws Exception {
  baseDn = new DN(dn);

  final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(dn);
  server = new InMemoryDirectoryServer(config);

  try (InputStream in = ldifStream.openStream()) {
    server.importFromLDIF(false, new LDIFReader(in));
  }

  server.startListening();
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:13,代码来源:EmbeddedDirectoryServer.java


示例9: getConnectionPoolEntry

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
public ConnectionPoolEntry getConnectionPoolEntry(String name, String dn, Map<String, Object> vars)
throws Exception {
    log.debug("getConnectionPoolEntry Entry name='{}', dn='{}'", name, dn);

    String domainComponent = null;
    if (dn != null && !dn.isEmpty() && DN.isValidDN(dn)) {
        domainComponent = getDNDomainComponent(dn);
        if (domainComponent.isEmpty()) {
            domainComponent = null;
        }
    }

    final String PREFIX_POOL = "pool";
    final String PREFIX_POOL_DC_RESOLVE = "dc-resolve";
    final String VAR_RESOLVE_DOMAIN = "__dc_resolve_domain";
    MapProperties poolProps = new MapProperties(
        props.get(PREFIX_POOL, "default"),
        props.get(PREFIX_POOL, name)
    );
    if (domainComponent != null && !domainComponent.isEmpty()) {
        MapProperties poolPropsDC = new MapProperties(
            poolProps,
            poolProps.get(PREFIX_POOL_DC_RESOLVE, "default"),
            poolProps.get(PREFIX_POOL_DC_RESOLVE, domainComponent.replace('.', '_'))
        );
        if (poolPropsDC.getBoolean(false, PREFIX_POOL_DC_RESOLVE, "enable")) {
            log.debug("getConnectionPoolEntry dc-resolve enabled");
            poolProps = poolPropsDC;
            name += "@" + domainComponent;
            vars.put(VAR_RESOLVE_DOMAIN, domainComponent);
        }
    }

    ConnectionPoolEntry entry = connectionPools.get(name);
    if (entry == null) {
        log.debug("getConnectionPoolEntry no pool for '{}'", name);

        try {
            entry = createConnectionPoolEntry(
                name,
                Util.expandMap(
                    poolProps,
                    "seq",
                    vars
                ),
                vars
            );
            connectionPools.put(entry.name, entry);
        } finally {
            vars.remove(VAR_RESOLVE_DOMAIN);
        }
    }
    return entry;
}
 
开发者ID:oVirt,项目名称:ovirt-engine-extension-aaa-ldap,代码行数:55,代码来源:Framework.java


示例10: isDN

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
public static boolean isDN(String p_dn) {
    return DN.isValidDN(p_dn);
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:4,代码来源:LdapUtils.java


示例11: DefaultLdapDn

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
public DefaultLdapDn(DN dn) {
    this.dn = dn;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:4,代码来源:DefaultLdapDn.java


示例12: InMemoryDirectoryServerConfigWithRootDSEAttributes

import com.unboundid.ldap.sdk.DN; //导入依赖的package包/类
public InMemoryDirectoryServerConfigWithRootDSEAttributes(DN... baseDNs) throws LDAPException {
    super(baseDNs);
}
 
开发者ID:zagyi,项目名称:adsync4j,代码行数:4,代码来源:InMemoryDirectoryServerConfigWithRootDSEAttributes.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Script类代码示例发布时间:2022-05-22
下一篇:
Java DOMInputImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap