private DirContextAdapter loadUserAsContext(final DistinguishedName dn, final String username) { return (DirContextAdapter) template.executeReadOnly(new ContextExecutor() { public Object executeWithContext(DirContext ctx) throws NamingException { try { Attributes attrs = ctx.getAttributes(dn, attributesToRetrieve); return new DirContextAdapter(attrs, LdapUtils.getFullDn(dn, ctx)); } catch (NameNotFoundException notFound) { throw new UsernameNotFoundException( "User " + username + " not found", notFound); } } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final Name dn, final ContextMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Object object = ctx.lookup(dn); return mapper.mapFromContext(object); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final String dn, final ContextMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Object object = ctx.lookup(dn); return mapper.mapFromContext(object); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final Name dn, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes attributes = ctx.getAttributes(dn); return mapper.mapFromAttributes(attributes); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final String dn, final String[] attributes, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes filteredAttributes = ctx.getAttributes(dn, attributes); return mapper.mapFromAttributes(filteredAttributes); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final Name dn, final String[] attributes, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes filteredAttributes = ctx.getAttributes(dn, attributes); return mapper.mapFromAttributes(filteredAttributes); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final String dn, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes attributes = ctx.getAttributes(dn); return mapper.mapFromAttributes(attributes); } }); }
/** * {@inheritDoc} */ @Override public Object lookup(final String dn) { return executeReadOnly(new ContextExecutor() { public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { return ctx.lookup(dn); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final String dn, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes attributes = ctx.getAttributes(dn); return mapper.mapFromAttributes(attributes); } }); }
/** * {@inheritDoc} */ @Override public Object lookup(final String dn) { return executeReadOnly(new ContextExecutor() { public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { return ctx.lookup(dn); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final Name dn, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes attributes = ctx.getAttributes(dn); return mapper.mapFromAttributes(attributes); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final String dn, final ContextMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Object object = ctx.lookup(dn); return mapper.mapFromContext(object); } }); }
/** * {@inheritDoc} */ @Override public Object lookup(final Name dn) { return executeReadOnly(new ContextExecutor() { public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { return ctx.lookup(dn); } }); }
/** * {@inheritDoc} */ @Override public Object lookup(final String dn) { return executeReadOnly(new ContextExecutor() { public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { return ctx.lookup(dn); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final String dn, final ContextMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Object object = ctx.lookup(dn); return mapper.mapFromContext(object); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final Name dn, final ContextMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Object object = ctx.lookup(dn); return mapper.mapFromContext(object); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final String dn, final String[] attributes, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes filteredAttributes = ctx.getAttributes(dn, attributes); return mapper.mapFromAttributes(filteredAttributes); } }); }
/** * {@inheritDoc} */ @Override public <T> T lookup(final Name dn, final String[] attributes, final AttributesMapper<T> mapper) { return executeReadOnly(new ContextExecutor<T>() { public T executeWithContext(DirContext ctx) throws javax.naming.NamingException { Attributes filteredAttributes = ctx.getAttributes(dn, attributes); return mapper.mapFromAttributes(filteredAttributes); } }); }
@Test public void testLookupLink() { ContextExecutor executor = new ContextExecutor() { public Object executeWithContext(DirContext ctx) throws NamingException { return ctx.lookupLink("cn=Some Person,ou=company1,ou=Sweden"); } }; Object object = tested.executeReadOnly(executor); assertThat(object instanceof DirContextAdapter).as("Should be a DirContextAdapter").isTrue(); } }
@Test public void testExecuteReadOnly() throws Exception { expectGetReadOnlyContext(); Object object = new Object(); when(contextExecutorMock.executeWithContext(dirContextMock)).thenReturn(object); Object result = tested.executeReadOnly(contextExecutorMock); verify(dirContextMock).close(); assertThat(result).isSameAs(object); }