Java Code Examples for org.springframework.ldap.support.LdapUtils#emptyLdapName()
The following examples show how to use
org.springframework.ldap.support.LdapUtils#emptyLdapName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapTemplateTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void testLookupContextWithName() { final DirContextAdapter expectedResult = new DirContextAdapter(); final LdapName expectedName = LdapUtils.emptyLdapName(); LdapTemplate tested = new LdapTemplate() { public Object lookup(Name dn) { assertThat(dn).isSameAs(dn); return expectedResult; } }; DirContextOperations result = tested.lookupContext(expectedName); assertThat(result).isSameAs(expectedResult); }
Example 2
Source File: LdapTemplateTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void testModifyAttributesWithDirContextOperations() throws Exception { final ModificationItem[] expectedModifications = new ModificationItem[0]; final LdapName epectedDn = LdapUtils.emptyLdapName(); when(dirContextOperationsMock.getDn()).thenReturn(epectedDn); when(dirContextOperationsMock.isUpdateMode()).thenReturn(true); when(dirContextOperationsMock.getModificationItems()).thenReturn(expectedModifications); LdapTemplate tested = new LdapTemplate() { public void modifyAttributes(Name dn, ModificationItem[] mods) { assertThat(dn).isSameAs(epectedDn); assertThat(mods).isSameAs(expectedModifications); } }; tested.modifyAttributes(dirContextOperationsMock); }
Example 3
Source File: AbstractContextSource.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * Set the base suffix from which all operations should origin. If a base * suffix is set, you will not have to (and, indeed, must not) specify the * full distinguished names in any operations performed. * * @param base the base suffix. */ public void setBase(String base) { if (base != null) { this.base = LdapUtils.newLdapName(base); } else { this.base = LdapUtils.emptyLdapName(); } }
Example 4
Source File: LdapTemplate.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public <T> List<T> find(Name base, Filter filter, SearchControls searchControls, final Class<T> clazz) { Filter finalFilter = odm.filterFor(clazz, filter); // Search from the root if we are not told where to search from Name localBase = base; if (base == null || base.size() == 0) { localBase = LdapUtils.emptyLdapName(); } // extend search controls with the attributes to return String[] attributes = odm.manageClass(clazz); searchControls.setReturningAttributes(attributes); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Searching - base=%1$s, finalFilter=%2$s, scope=%3$s", base, finalFilter, searchControls)); } List<T> result = search(localBase, finalFilter.encode(), searchControls, new ContextMapper<T>() { @Override public T mapFromContext(Object ctx) throws javax.naming.NamingException { return odm.mapFromLdapDataEntry((DirContextOperations) ctx, clazz); } }); result.remove(null); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Found %1$s Entries - %2$s", result.size(), result)); } return result; }
Example 5
Source File: DirContextAdapter.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * Create a new adapter from the supplied attributes, dn, base, and referral * url. * @param attrs the attributes. * @param dn the dn. * @param base the base. * @param referralUrl the referral url (if this instance results from a * referral). */ public DirContextAdapter(Attributes attrs, Name dn, Name base, String referralUrl) { if (attrs != null) { this.originalAttrs = new NameAwareAttributes(attrs); } else { this.originalAttrs = new NameAwareAttributes(); } if (dn != null) { this.dn = LdapUtils.newLdapName(dn); } else { this.dn = LdapUtils.emptyLdapName(); } if (base != null) { this.base = LdapUtils.newLdapName(base); } else { this.base = LdapUtils.emptyLdapName(); } if (referralUrl != null) { this.referralUrl = referralUrl; } else { this.referralUrl = EMPTY_STRING; } }
Example 6
Source File: LdapTemplateTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { // Setup ContextSource mock contextSourceMock = mock(ContextSource.class); // Setup LdapContext mock dirContextMock = mock(LdapContext.class); // Setup NamingEnumeration mock namingEnumerationMock = mock(NamingEnumeration.class); // Setup Name mock nameMock = LdapUtils.emptyLdapName(); // Setup Handler mock handlerMock = mock(NameClassPairCallbackHandler.class); contextMapperMock = mock(ContextMapper.class); attributesMapperMock = mock(AttributesMapper.class); contextExecutorMock = mock(ContextExecutor.class); searchExecutorMock = mock(SearchExecutor.class); dirContextProcessorMock = mock(DirContextProcessor.class); dirContextOperationsMock = mock(DirContextOperations.class); authenticatedContextMock = mock(DirContext.class); entryContextCallbackMock = mock(AuthenticatedLdapEntryContextCallback.class); odmMock = mock(ObjectDirectoryMapper.class); query = LdapQueryBuilder.query().base("ou=spring").filter("ou=user"); authContextMapperMock = mock(AuthenticatedLdapEntryContextMapper.class); tested = new LdapTemplate(contextSourceMock); tested.setObjectDirectoryMapper(odmMock); }
Example 7
Source File: DirContextAdapterBugTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testResetAttributeValuesNotReportedAsModifications() { BasicAttributes attrs = new BasicAttributes("myattr", "a"); attrs.get("myattr").add("b"); attrs.get("myattr").add("c"); UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName()); ctx.setAttributeValues("myattr", new String[] { "a", "b" }); ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" }); assertThat(ctx.getModificationItems().length).isEqualTo(0); }
Example 8
Source File: DirContextAdapterBugTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testResetAttributeValuesSameLengthNotReportedAsModifications() { BasicAttributes attrs = new BasicAttributes("myattr", "a"); attrs.get("myattr").add("b"); attrs.get("myattr").add("c"); UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName()); ctx.setAttributeValues("myattr", new String[] { "a", "b", "d" }); ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" }); assertThat(ctx.getModificationItems().length).isEqualTo(0); }
Example 9
Source File: DirContextAdapterBugTest.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * This test starts with an array with a null value in it (because that's * how BasicAttributes will do it), changes to <code>[a]</code>, and then * changes to <code>null</code>. The current code interprets this as a * change and will replace the original array with an empty array. * * TODO Is this correct behaviour? */ @Test public void testResetNullAttributeValuesReportedAsModifications() { BasicAttributes attrs = new BasicAttributes("myattr", null); UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName()); ctx.setAttributeValues("myattr", new String[] { "a" }); ctx.setAttributeValues("myattr", null); assertThat(ctx.getModificationItems().length).isEqualTo(1); }
Example 10
Source File: DirContextAdapterBugTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testResetNullAttributeValueNotReportedAsModification() throws Exception { BasicAttributes attrs = new BasicAttributes("myattr", "b"); UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName()); ctx.setAttributeValue("myattr", "a"); ctx.setAttributeValue("myattr", "b"); assertThat(ctx.getModificationItems().length).isEqualTo(0); }
Example 11
Source File: AbstractLdapTemplateIntegrationTest.java From spring-ldap with Apache License 2.0 | 4 votes |
protected Name getRoot() { return LdapUtils.emptyLdapName(); }