@Override public void setRequestControls(Control[] requestControls) throws NamingException { if ( ! (delegating instanceof LdapContext)) throw Assert.unsupported(); ((LdapContext) delegating).setRequestControls(requestControls); }
try { LdapContext ctx = new InitialLdapContext(env, null); ctx.setRequestControls(null); NamingEnumeration<?> namingEnum = ctx.search("ou=people,dc=example,dc=com", "(objectclass=user)", getSimpleSearchControls()); while (namingEnum.hasMore ()) { SearchResult result = (SearchResult) namingEnum.next (); Attributes attrs = result.getAttributes (); System.out.println(attrs.get("cn")); } namingEnum.close(); } catch (Exception e) { e.printStackTrace(); } private SearchControls getSimpleSearchControls() { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setTimeLimit(30000); //String[] attrIDs = {"objectGUID"}; //searchControls.setReturningAttributes(attrIDs); return searchControls; }
private NamingEnumeration<SearchResult> searchWithPagination() throws NamingException, IOException { Control[] controlsBackup = null; Object binaryAttributesBackup = null; // backup and set environment if (pageSize != 0 && context instanceof LdapContext) { controlsBackup = ((LdapContext)context).getRequestControls(); ((LdapContext)context).setRequestControls(new Control[]{ new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } if (binaryAttributes != null && binaryAttributes.size() != 0) { // set attributes which should be returned in binary form binaryAttributesBackup = context.getEnvironment().get(ENV_BINARY_ATTRIBUTES); context.addToEnvironment(ENV_BINARY_ATTRIBUTES, String.join(" ", binaryAttributes)); } NamingEnumeration<SearchResult> results = context.search(new LdapName(searchDn), filter, filterArgs, createSearchControls()); // revert environment change if (binaryAttributes != null && binaryAttributes.size() != 0) { if (binaryAttributesBackup == null) { context.removeFromEnvironment(ENV_BINARY_ATTRIBUTES); } else { context.addToEnvironment(ENV_BINARY_ATTRIBUTES, binaryAttributesBackup); } } if (pageSize != 0 && context instanceof LdapContext) { ((LdapContext)context).setRequestControls(controlsBackup); } return results; }
ctx.setRequestControls(baseRequestControls); ctx.setRequestControls(requestControls); } while (cookie != null); ctx2.setRequestControls(baseRequestControls); ctx2.setRequestControls(requestControls); } while (cookie != null); try { if (ctx != null) { ctx.setRequestControls(null); ctx.close(); ctx2.setRequestControls(null); ctx2.close();
return Collections.emptyList(); ctx.setRequestControls(searchControl); try { if (ctx != null) { ctx.setRequestControls(null); ctx.close();
ctx.setRequestControls(baseRequestControls); ctx.setRequestControls(requestControls); } while (cookie != null && (lastRes == -1 || count <= lastRes)); ctx2.setRequestControls(baseRequestControls); ctx2.setRequestControls(requestControls); } while (cookie != null && (lastRes == -1 || count <= lastRes)); try { if (ctx != null) { ctx.setRequestControls(null); ctx.close(); ctx2.setRequestControls(null); ctx2.close();
new SortControl(new String[]{manager.getGroupNameField()}, Control.NONCRITICAL) }; ctx.setRequestControls(searchControl); try { if (ctx != null) { ctx.setRequestControls(null); ctx.close();
@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. } } }
protected void applyRequestControls(AbstractQuery<?, ?> query) { try { List<Control> controls = new ArrayList<>(); List<QueryOrderingProperty> orderBy = query.getOrderingProperties(); if(orderBy != null) { for (QueryOrderingProperty orderingProperty : orderBy) { String propertyName = orderingProperty.getQueryProperty().getName(); if(UserQueryProperty.USER_ID.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserIdAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.EMAIL.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserEmailAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.FIRST_NAME.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserFirstnameAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.LAST_NAME.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserLastnameAttribute(), Control.CRITICAL)); } } } initialContext.setRequestControls(controls.toArray(new Control[0])); } catch (Exception e) { throw new IdentityProviderException("Exception while setting paging settings", e); } }
context.setRequestControls(new Control[]{new PagedResultsControl(pageSize, Control.NONCRITICAL)}); final List<LdapUser> users = new ArrayList<LdapUser>(); NamingEnumeration<SearchResult> results; s_logger.info("No controls were sent from the ldap server"); context.setRequestControls(new Control[] {new PagedResultsControl(pageSize, cookie, Control.CRITICAL)}); } while (cookie != null);
@Override public Object operation() throws NamingException { ((LdapContext) getDelegate()).setRequestControls(requestControls); return null; } }.perform();
@Override public void setRequestControls(Control[] requestControls) throws NamingException { if ( ! (delegating instanceof LdapContext)) throw Assert.unsupported(); ((LdapContext) delegating).setRequestControls(requestControls); }
@Override public Object operation() throws NamingException { ((LdapContext) getDelegate()).setRequestControls(requestControls); return null; } }.perform();
public void setRequestControls(Control[] requestControls) throws NamingException { assertOpen(); getDelegateLdapContext().setRequestControls(requestControls); } }
public void setRequestControls(Control[] requestControls) throws NamingException { assertOpen(); getDelegateLdapContext().setRequestControls(requestControls); } }
@Test public void testPreProcessWithNullControlsShouldAdd() throws NamingException { when(ldapContextMock.getRequestControls()).thenReturn(null); tested.preProcess(ldapContextMock); verify(ldapContextMock).setRequestControls(new Control[] { requestControlMock }); }
@Test public void testPreProcessWithExistingControlOfSameClassShouldReplace() throws Exception { when(ldapContextMock.getRequestControls()).thenReturn(new Control[]{requestControl2Mock}); tested.preProcess(ldapContextMock); verify(ldapContextMock).setRequestControls(new Control[] { requestControlMock }); }
@Test public void testPreProcessWithExistingControlOfDifferentClassShouldAdd() throws Exception { SortControl existingControl = new SortControl(new String[] { "cn" }, true); when(ldapContextMock.getRequestControls()).thenReturn(new Control[]{existingControl}); tested.preProcess(ldapContextMock); verify(ldapContextMock).setRequestControls(new Control[] { existingControl, requestControlMock }); }
@Test public void testPreProcessWithExistingControlOfSameClassAndPropertyFalseShouldAdd() throws Exception { when(ldapContextMock.getRequestControls()).thenReturn(new Control[] { requestControl2Mock }); tested.setReplaceSameControlEnabled(false); tested.preProcess(ldapContextMock); verify(ldapContextMock).setRequestControls(new Control[]{requestControl2Mock, requestControlMock}); }
@Test public void testSupportedMethodsAllowedToCall() throws Exception { final MutableDelegatingLdapContext delegatingLdapContext = new MutableDelegatingLdapContext( keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY); delegatingLdapContext.setRequestControls(null); verify(ldapContextMock).setRequestControls(null); } }