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


Java EntryCursor类代码示例

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


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

示例1: search

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes )
    throws LdapException
{
    if ( baseDn == null )
    {
        LOG.debug( "received a null dn for a search" );
        throw new IllegalArgumentException( "The base Dn cannot be null" );
    }

    // Create a new SearchRequest object
    SearchRequest searchRequest = new SearchRequestImpl();

    searchRequest.setBase( baseDn );
    searchRequest.setFilter( filter );
    searchRequest.setScope( scope );
    searchRequest.addAttributes( attributes );
    searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );

    // Process the request in blocking mode
    return new EntryCursorImpl( search( searchRequest ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:26,代码来源:LdapNetworkConnection.java

示例2: getDN

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
@Override
public String getDN(String baseDn, String attributeName, String attributeValue) throws LdapException {

	LdapConnection connection = null;
	EntryCursor cursor = null;

	String filter = "(" + attributeName + "=" + attributeValue + ")";

	try {
		connection = getConnection();
		cursor = connection.search(baseDn, filter, SearchScope.SUBTREE);
		while (cursor.next()) {
			return cursor.get().getDn().getName();
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		throw new LdapException(e);
	} finally {
		if (cursor != null) {
			cursor.close();
		}
		releaseConnection(connection);
	}

	return null;
}
 
开发者ID:Pardus-LiderAhenk,项目名称:lider,代码行数:27,代码来源:LDAPServiceImpl.java

示例3: readStringAttribute

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
public String readStringAttribute( final String entryDN, final String attribute )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    activityPreCheck();
    getInputValidator().readStringAttribute( entryDN, attribute );

    try
    {
        final EntryCursor entries = connection.search(
                entryDN,
                ChaiConstant.FILTER_OBJECTCLASS_ANY,
                org.apache.directory.api.ldap.model.message.SearchScope.OBJECT,
                attribute
        );
        final Entry entry = entries.iterator().next();
        final Attribute attr = entry.get( attribute );
        return attr == null ? null : attr.getString();

    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
开发者ID:ldapchai,项目名称:ldapchai,代码行数:25,代码来源:ApacheLdapProviderImpl.java

示例4: getUserRoles

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
@Override
public Set<String> getUserRoles(String userId) throws UserException {
    Set<String> roles = new HashSet<String>();
    try {
        String filter = "(" + config.getGroupFilter().replace("{0}", userDn(userId)) + ")";
        EntryCursor cursor = connection.search(config.getGroupSearchBase(), filter, 
                SearchScope.SUBTREE);

        while(cursor.next()) {
            Entry entry = cursor.get();
            roles.add(entry.get("cn").getString());
        }
    } catch (LdapException | CursorException e) {
        throw new UserException(e);
    }
    return roles;
}
 
开发者ID:Comcast,项目名称:dawg,代码行数:18,代码来源:LdapUserService.java

示例5: getChildList

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
/**
 * Get child list
 *
 * @param entryDN The distinguished name of an Entry in the LDAP
 * @param connection An initialized LDAP-Context
 * @return All child's of an Entry
 * @throws IOException
 * @throws CursorException
 * @throws LdapException
 */
private List<String> getChildList(String entryDN, LdapConnection connection) throws CursorException, IOException, LdapException {
    List<String> childs = new ArrayList<String>();

    EntryCursor cursor = connection.search("ou=system", "(objectclass=*)", SearchScope.ONELEVEL);
    while (cursor.next()) {
        Entry entry = cursor.get();
        childs.add(entry.get("distinguishedName").getString());
    }

    //SearchResultDone done = cursor.getSearchResultDone();
    //ResultCodeEnum resultCode = done.getLdapResult().getResultCode();
    cursor.close();
    // ResultCodeEnum.SUCCESS == resultCode
    return childs;
}
 
开发者ID:apache,项目名称:marmotta,代码行数:26,代码来源:LdapFoafProvider.java

示例6: getAccountData

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
/**
 * Get account data
 *
 * @param accountDN The distinguished Name of the Account (e.g
 *            "cn=Daniel  Trabe,ou=USERS,ou=SRFG,dc=salzburgresearch,dc=at")
 * @param connection An initialized LDAP-Context
 * @return a Map of Attributes and Values of an Account
 * @throws DataRetrievalException
 * @throws IOException
 * @throws CursorException
 * @throws LdapException
 */
private Map<String, List<String>> getAccountData(String accountDN, LdapConnection connection) throws DataRetrievalException, LdapException, CursorException, IOException {
    Map<String, List<String>> account = new HashMap<String, List<String>>();
    Dn dn = new Dn(accountDN);
    EntryCursor cursor = connection.search(dn, accountDN, SearchScope.ONELEVEL, (String[])null);
    if (cursor.next()) {
        //FIXME: only the first entry?
        Entry entry = cursor.get();
        for (Attribute attr : entry.getAttributes()) {
            String id = attr.getId();
            List<String> values;
            if (account.containsKey(id)) {
                values = account.get(id);
            } else {
                values = new ArrayList<String>();
            }
            values.add(attr.get().getValue().toString());
            account.put(id, values);
        }
    }
    return account;
}
 
开发者ID:apache,项目名称:marmotta,代码行数:34,代码来源:LdapFoafProvider.java

示例7: search

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes )
    throws LdapException
{
    return connection.search( baseDn, filter, scope, attributes );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:10,代码来源:LdapConnectionWrapper.java

示例8: queryEntrys

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
/**
 * 查询条目。
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-02-16
 * @version     v1.0
 *
 * @param i_DN           条目标识
 * @param i_SearchScope  查询范围
 *                       搜索范围01:SearchScope.OBJECT    返回输入给定DN,如果它存在的话。
 *                       搜索范围02:SearchScope.ONELEVEL  返回低于目前DN的所有子元素,不包括当前DN,也不包括与当前DN无直接关系的DN,即树目录深度为1。
 *                       搜索范围03:SearchScope.SUBTREE   返回所有元素从给出的DN,包括与DN相关的元素,无论树的深度。
 * @return
 */
private List<?> queryEntrys(String i_DN ,SearchScope i_SearchScope)
{
    LdapConnection v_Conn   = null;
    EntryCursor    v_Cursor = null;
    List<Object>   v_Ret    = new ArrayList<Object>();
    
    try
    {
        v_Conn   = this.getConnection();
        v_Cursor = v_Conn.search(new Dn(i_DN) ,"(" + LDAP.$ObjectClass + "=*)" ,i_SearchScope);
        
        while ( v_Cursor.next() )
        {
            Entry     v_Entry     = v_Cursor.get();
            LdapEntry v_LdapEntry = getLdapEntry(v_Entry);
            
            if ( v_LdapEntry != null )
            {
                v_Ret.add(v_LdapEntry.toObject(v_Entry));
            }
        }
    }
    catch (Exception exce)
    {
        exce.printStackTrace();
    }
    finally
    {
        LDAP.closeCursor(    v_Cursor);
        this.closeConnection(v_Conn);
    }
    
    return v_Ret;
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.ldap,代码行数:49,代码来源:LDAP.java

示例9: readMultiAttribute

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
private List<Value> readMultiAttribute( final String entryDN, final String attribute )
        throws ChaiOperationException
{
    try
    {
        final EntryCursor entries = connection.search(
                entryDN,
                ChaiConstant.FILTER_OBJECTCLASS_ANY,
                org.apache.directory.api.ldap.model.message.SearchScope.OBJECT,
                attribute
        );
        final Entry entry = entries.iterator().next();
        final List<Value> returnSet = new ArrayList<>();
        final Attribute attr = entry.get( attribute );
        if ( attr == null )
        {
            return null;
        }
        for ( final Value value : attr )
        {
            if ( value != null )
            {
                returnSet.add( value );
            }
        }
        return Collections.unmodifiableList( returnSet );

    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }

}
 
开发者ID:ldapchai,项目名称:ldapchai,代码行数:35,代码来源:ApacheLdapProviderImpl.java

示例10: readStringAttributes

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
public Map<String, String> readStringAttributes( final String entryDN, final Set<String> attributes )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    activityPreCheck();
    getInputValidator().readStringAttributes( entryDN, attributes );

    try
    {
        final EntryCursor entries = connection.search(
                entryDN,
                ChaiConstant.FILTER_OBJECTCLASS_ANY,
                org.apache.directory.api.ldap.model.message.SearchScope.OBJECT,
                attributes.toArray( new String[attributes.size()] )
        );
        final Entry entry = entries.iterator().next();
        final Collection<Attribute> attrs = entry.getAttributes();
        final Map<String, String> returnMap = new LinkedHashMap<>();
        for ( final Attribute attr : attrs )
        {
            final String name = attr.getId();
            final String value = attr.getString();
            returnMap.put( name, value );
        }

        return returnMap;

    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
开发者ID:ldapchai,项目名称:ldapchai,代码行数:33,代码来源:ApacheLdapProviderImpl.java

示例11: closeCursor

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
public static void closeCursor(EntryCursor cursor) {
	try {
		cursor.close();
	} catch (IOException e) {
		// Log the error, but otherwise ignore it. This is unlikely to cause
		// any serious harm for the operation.
		LOG.warn("Error closing the search cursor (continuing the operation anyway):", e);
	}		
}
 
开发者ID:Evolveum,项目名称:connector-ldap,代码行数:10,代码来源:LdapUtil.java

示例12: lookupUser

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
private Entry lookupUser(String username) throws LdapException {
	StringBuilder userQuery = new StringBuilder();
	userQuery.append("(&(objectclass=");
	userQuery.append(userObjectClass);
	userQuery.append(")(|");
	boolean hasCondition = false;
	for (String lookupAttr : lookupAttrs) {
		String attrName = lookupAttr.trim();
		if (!attrName.isEmpty()) {
			userQuery.append('(').append(attrName).append('=').append(username).append(')');
			hasCondition = true;
		}
	}
	userQuery.append("))");

	if (!hasCondition) {
		return null;
	}

	logger.debug("LDAP user query " + userQuery.toString());

	EntryCursor responseCursor = connection.search(userDn, userQuery.toString(), SearchScope.SUBTREE);
	try {
		try {
			if (responseCursor != null && responseCursor.next()) {
				Entry match = responseCursor.get();
				logger.debug("LDAP user query result: " + match.getDn());
				return match;
			}
		} catch (CursorException e) {
			logger.debug("LDAP search error", e);
			return null;
		}
	} finally {
		responseCursor.close();
	}
	return null;
}
 
开发者ID:caelum,项目名称:mamute,代码行数:39,代码来源:LDAPApi.java

示例13: testLdapConnectionIsOnlyHitOnce

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
@Test
	public void testLdapConnectionIsOnlyHitOnce() throws Exception {
		LdapConnection ldapConnection = EasyMock
				.createMock(LdapConnection.class);
		EntryCursor cursor = EasyMock.createMock(EntryCursor.class);
		DefaultEntry entry = new DefaultEntry();
		entry.add("uid", "foo");
		entry.add("userpassword", "bar");

		ldapConnection.setTimeOut(30000);

		EasyMock.expect(
				ldapConnection.search("ou=users,ou=system", "(uid=foo)",
						SearchScope.SUBTREE)).andReturn(cursor);

		EasyMock.expect(cursor.next()).andReturn(true);

		EasyMock.expect(cursor.get()).andReturn(entry);

		cursor.close();

//		ldapConnection.bind("randomUser", "randomPassword");
		//ldapConnection.unBind();
		//EasyMock.expect(ldapConnection.close()).andReturn(true);

		EasyMock.replay(ldapConnection, cursor);

		@SuppressWarnings("resource")
		// Closed in the implementation
		// TODO Redesign the API
		LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(
				ldapConnection, "randomUser", "randomPassword");

		Assert.assertTrue(ldapAuthenticationProvider.authenticate("foo", "bar"));
		Assert.assertTrue(ldapAuthenticationProvider.authenticate("foo", "bar"));

		EasyMock.verify(ldapConnection, cursor);
	}
 
开发者ID:datacleaner,项目名称:easydq_webservice_proxy,代码行数:39,代码来源:LdapAuthenticationProviderTest.java

示例14: testAuthenticationSuccess

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
@Test
	public void testAuthenticationSuccess() throws Exception {
		LdapConnection ldapConnection = EasyMock
				.createMock(LdapConnection.class);
		EntryCursor cursor = EasyMock.createMock(EntryCursor.class);
		DefaultEntry entry = new DefaultEntry();
		entry.add("uid", "foo");
		entry.add("userpassword", "bar");

		ldapConnection.setTimeOut(30000);

		EasyMock.expect(
				ldapConnection.search("ou=users,ou=system", "(uid=foo)",
						SearchScope.SUBTREE)).andReturn(cursor);

		EasyMock.expect(cursor.next()).andReturn(true);
		EasyMock.expect(cursor.get()).andReturn(entry);
//		ldapConnection.bind("randomUser", "randomPassword");
//		ldapConnection.unBind();
//		EasyMock.expect(ldapConnection.close()).andReturn(true);

		cursor.close();

		EasyMock.replay(ldapConnection, cursor);

		@SuppressWarnings("resource")
		// Closed in the implementation
		// TODO Redesign the API
		LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(
				ldapConnection, "randomUser", "randomPassword");

		Assert.assertTrue(ldapAuthenticationProvider.authenticate("foo", "bar"));

		EasyMock.verify(ldapConnection, cursor);

	}
 
开发者ID:datacleaner,项目名称:easydq_webservice_proxy,代码行数:37,代码来源:LdapAuthenticationProviderTest.java

示例15: getUser

import org.apache.directory.api.ldap.model.cursor.EntryCursor; //导入依赖的package包/类
@Override
public Optional<SingularityUser> getUser(String user) {
  if (configuration.isStripUserEmailDomain()) {
    user = user.split("@")[0];
  }

  final Set<String> groups = new HashSet<>();

  try {
    final LdapConnection connection = connectionPool.getConnection();

    try {
      checkState(connection.isConnected(), "not connected");
      checkState(connection.isAuthenticated(), "not authenticated");
      connection.bind();

      final long startTime = System.currentTimeMillis();
      try {
        final EntryCursor userCursor = connection.search(configuration.getUserBaseDN(),
                String.format(configuration.getUserFilter(), user),
                SearchScope.ONELEVEL, configuration.getUserNameAttribute(), configuration.getUserEmailAttribute());

        if (!userCursor.next()) {
          return Optional.absent();
        }

        final Entry userEntry = userCursor.get();

        // get group info
        final EntryCursor cursor = connection.search(configuration.getGroupBaseDN(),
                String.format(configuration.getGroupFilter(), user),
                configuration.getGroupSearchScope(), configuration.getGroupNameAttribute());

        while (cursor.next()) {
          groups.add(cursor.get().get(configuration.getGroupNameAttribute()).getString());
        }

        return Optional.of(new SingularityUser(user, Optional.fromNullable(Strings.emptyToNull(userEntry.get(configuration.getUserNameAttribute()).getString())), Optional.fromNullable(Strings.emptyToNull(userEntry.get(configuration.getUserEmailAttribute()).getString())), groups));
      } finally {
        LOG.info("Loaded {}'s user data in {}ms", user, System.currentTimeMillis() - startTime);
        connection.unBind();
      }
    } finally {
      connectionPool.releaseConnection(connection);
    }
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:50,代码来源:SingularityLDAPDatastore.java


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