@Override public LdapEntry resolve(final AuthenticationCriteria criteria, final AuthenticationHandlerResponse response) throws LdapException { return new LdapEntry(criteria.getDn()); }
@Override public LdapEntry resolve(final AuthenticationCriteria criteria, final AuthenticationHandlerResponse response) throws LdapException { return new LdapEntry(criteria.getDn()); }
@Override public LdapEntry resolve(final AuthenticationCriteria criteria, final AuthenticationHandlerResponse response) throws LdapException { return new LdapEntry(criteria.getDn()); }
/** * Injects data from the supplied source object into a new instance of ldap entry. * * @param source to read from * * @return ldap entry */ public LdapEntry map(final T source) { final LdapEntry dest = new LdapEntry(); map(source, dest); return dest; }
/** {@inheritDoc} */ @Override public boolean create(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable @Positive Long expiration) throws IOException { if (expiration != null) { throw new UnsupportedOperationException("Expiration not supported"); } final LdapEntry entry = new LdapEntry(context, defaultAttributes); entry.addAttribute(new LdapAttribute(key, value)); try { merge(entry); return true; } catch (LdapException e) { log.error("LDAP merge operation failed", e); throw new IOException(e); } }
/** {@inheritDoc} */ @Override public boolean update(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable @Positive final Long expiration) throws IOException { if (expiration != null) { throw new UnsupportedOperationException("Expiration not supported"); } final LdapEntry entry = new LdapEntry(context, defaultAttributes); entry.addAttribute(new LdapAttribute(key, value)); try { merge(entry); return true; } catch (LdapException e) { log.error("LDAP merge operation failed", e); throw new IOException(e); } }
/** * @param object initialized with data * @param entry to compare with mapped entry * @param mapper to invoke * * @throws Exception On test failure. */ @Test(groups = {"beans"}, dataProvider = "objects") public void mapToLdapEntry( final CustomObject object, final LdapEntry entry, final LdapEntryMapper<CustomObject> mapper) throws Exception { final LdapEntry mapped = new LdapEntry(); object.initialize(); mapper.map(object, mapped); Assert.assertEquals(entry, mapped); }
/** @throws Exception On test failure. */ @Test(groups = {"cache"}, threadPoolSize = 5, invocationCount = 100, timeOut = 60000) public void get() throws Exception { SearchResult result = cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=3"))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=3,ou=test,dc=ldaptive,dc=org")), result); result = cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=4"))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=4,ou=test,dc=ldaptive,dc=org")), result); result = cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=5"))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=5,ou=test,dc=ldaptive,dc=org")), result); }
@Override public Response<Void> merge(final T object) throws LdapException { final LdapEntry entry = new LdapEntry(); getLdapEntryMapper().map(object, entry); final MergeRequest request = new MergeRequest(entry); try (Connection conn = getConnectionFactory().getConnection()) { conn.open(); final MergeOperation merge = new MergeOperation(conn); return merge.execute(request); } }
@Override protected void insert(final Map<String, Object> attributes) { attributes.put("objectClass", "person"); final LdapEntry ldapEntry = new LdapEntry(getEntryId(attributes)); ldapEntry.addAttributes(getLdapAttributes(attributes)); Connection connection = null; try { connection = connectionFactory.getConnection(); connection.open(); final AddOperation add = new AddOperation(connection); add.execute(new AddRequest(ldapEntry.getDn(), ldapEntry.getAttributes())); } catch (final LdapException e) { throw new TechnicalException(e); } finally { if (connection != null) { connection.close(); } } }
@Override public Response<Void> add(final T object) throws LdapException { final LdapEntry entry = new LdapEntry(); getLdapEntryMapper().map(object, entry); final AddRequest request = new AddRequest(entry.getDn(), entry.getAttributes()); try (Connection conn = getConnectionFactory().getConnection()) { conn.open(); final AddOperation add = new AddOperation(conn); return add.execute(request); } }
/** * Tests ordered sort behavior. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void orderedSortBehavior(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry(SortBehavior.ORDERED); AssertJUnit.assertEquals(SortBehavior.ORDERED, le.getSortBehavior()); le.addAttribute(attr2, attr1); final LdapAttribute[] attrs = le.getAttributes().toArray(new LdapAttribute[2]); AssertJUnit.assertEquals(attr2, attrs[0]); AssertJUnit.assertEquals(attr1, attrs[1]); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
/** * Tests sorted sort behavior. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void sortedSortBehavior(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry(SortBehavior.SORTED); AssertJUnit.assertEquals(SortBehavior.SORTED, le.getSortBehavior()); le.addAttribute(attr2, attr1); final LdapAttribute[] attrs = le.getAttributes().toArray(new LdapAttribute[2]); AssertJUnit.assertEquals(attr1, attrs[0]); AssertJUnit.assertEquals(attr2, attrs[1]); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
/** * Tests create with a collection. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void createCollection(final LdapAttribute attr1, final LdapAttribute attr2) { final Set<LdapAttribute> s = new HashSet<>(); s.add(attr1); final LdapEntry le = new LdapEntry("uid=1", s); le.addAttribute(attr2); AssertJUnit.assertEquals(attr1, le.getAttribute("GIVENNAME")); AssertJUnit.assertEquals(attr2, le.getAttribute("sn")); AssertJUnit.assertEquals(2, le.getAttributeNames().length); AssertJUnit.assertEquals(2, le.size()); AssertJUnit.assertEquals(le, new LdapEntry("uid=1", attr1, attr2)); le.removeAttribute("GIVENNAME"); AssertJUnit.assertEquals(1, le.size()); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
/** * Tests create with one entry. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void createOne(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry("uid=1", attr1); AssertJUnit.assertEquals(attr1, le.getAttribute()); AssertJUnit.assertEquals(attr1, le.getAttribute("givenName")); AssertJUnit.assertEquals(attr1, le.getAttribute("givenname")); AssertJUnit.assertEquals("givenName", le.getAttributeNames()[0]); AssertJUnit.assertEquals(1, le.size()); AssertJUnit.assertEquals(le, new LdapEntry("uid=1", attr1)); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
/** * Tests create with two entries. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void createTwo(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry("uid=1", attr2, attr1); AssertJUnit.assertEquals(attr1, le.getAttribute("givenName")); AssertJUnit.assertEquals(attr2, le.getAttribute("SN")); AssertJUnit.assertEquals(2, le.getAttributeNames().length); AssertJUnit.assertEquals(2, le.size()); AssertJUnit.assertEquals(le, new LdapEntry("uid=1", attr1, attr2)); le.removeAttribute(attr2); AssertJUnit.assertEquals(1, le.size()); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
@Override public Response<Void> add(final AddRequest request) throws LdapException { Response<Void> response = null; try { final ApacheLdapUtils bu = new ApacheLdapUtils(); final AddRequestImpl ari = new AddRequestImpl(); if (request.getControls() != null) { ari.addAllControls(config.getControlProcessor().processRequestControls(request.getControls())); } ari.setEntry(bu.fromLdapEntry(new LdapEntry(request.getDn(), request.getLdapAttributes()))); final AddResponse ar = connection.add(ari); throwOperationException(request, ar); response = createResponse(request, null, ar); } catch (LdapOperationException e) { processLdapOperationException(e); } catch (org.apache.directory.api.ldap.model.exception.LdapException e) { processLdapException(e); } return response; }
/** Tests default sort behavior. */ @Test(groups = {"bean"}) public void defaultSortBehavior() { final LdapEntry le = new LdapEntry("uid=1"); AssertJUnit.assertEquals(SortBehavior.getDefaultSortBehavior(), le.getSortBehavior()); AssertJUnit.assertEquals(0, le.size()); AssertJUnit.assertNull(le.getAttribute()); AssertJUnit.assertEquals("uid=1", le.getDn()); le.setDn("uid=2"); AssertJUnit.assertEquals("uid=2", le.getDn()); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
/** * Tests attribute rename. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void renameAttribute(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry("uid=1", attr2, attr1); AssertJUnit.assertEquals("givenName", le.getAttribute("givenname").getName()); le.renameAttribute(null, "firstName"); AssertJUnit.assertEquals("givenName", le.getAttribute("givenname").getName()); le.renameAttribute("noName", "firstName"); AssertJUnit.assertEquals("givenName", le.getAttribute("givenname").getName()); final LdapAttribute la = le.getAttribute("givenName"); le.renameAttribute("givenName", "firstName"); AssertJUnit.assertNull(le.getAttribute("givenName")); AssertJUnit.assertNotNull(le.getAttribute("firstName")); AssertJUnit.assertEquals("firstName", la.getName()); AssertJUnit.assertEquals("firstName", le.getAttribute("firstName").getName()); } }