本文整理汇总了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 ) );
}
示例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;
}
示例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() );
}
}
示例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;
}
示例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;
}
示例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;
}
示例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 );
}
示例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;
}
示例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() );
}
}
示例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() );
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}