org.springframework.ldap.core.AttributesMapper Java Examples

The following examples show how to use org.springframework.ldap.core.AttributesMapper. 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: ContextSourceTransactionManagerNamespaceIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateAndRename() {
	String dn = "cn=Some Person2,ou=company1,ou=Sweden";
	String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
	// Perform test
	dummyDao.updateAndRename(dn, newDn, "Updated description");

	// Verify that entry was moved and updated.
	Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(object).isNotNull();
	dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
}
 
Example #2
Source File: ContextSourceAndDataSourceTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributes() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	// Perform test
	dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");

	// Verify result - check that the operation was not rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
	dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
 
Example #3
Source File: TestContextSourceFactoryBeanTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testServerStartup() throws Exception {
    ctx = new ClassPathXmlApplicationContext("/applicationContext-testContextSource.xml");
    LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class);
    assertThat(ldapTemplate).isNotNull();

    List<String> list = ldapTemplate.search(
            LdapQueryBuilder.query().where("objectclass").is("person"),
            new AttributesMapper<String>() {
                public String mapFromAttributes(Attributes attrs)
                        throws NamingException {
                    return (String) attrs.get("cn").get();
                }
            });
    assertThat(list.size()).isEqualTo(5);
}
 
Example #4
Source File: LdapTemplateAttributesMapperITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
/**
 * Demonstrates how to retrieve all values of a multi-value attribute.
 * 
 * @see LdapTemplateContextMapperITest#testSearch_ContextMapper_MultiValue()
 */
@Test
public void testSearch_AttributesMapper_MultiValue() throws Exception {
	AttributesMapper mapper = new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			LinkedList list = new LinkedList();
			NamingEnumeration enumeration = attributes.get("uniqueMember").getAll();
			while (enumeration.hasMoreElements()) {
				String value = (String) enumeration.nextElement();
				list.add(value);
			}
			String[] members = (String[]) list.toArray(new String[0]);
			return members;
		}
	};
	List result = tested.search("ou=groups", "(&(objectclass=groupOfUniqueNames)(cn=ROLE_USER))", mapper);

	assertThat(result).hasSize(1);

	assertThat(((String[]) result.get(0)).length).isEqualTo(4);
}
 
Example #5
Source File: LdapUtils.java    From geofence with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and LDAP filter from the DAO search filter. Currently only "property = value" filters are supported.
 *
 * @param filter
 * @return
 */
public static String createLDAPFilter(Filter filter, AttributesMapper mapper)
{
    // TODO add other filter types
    if (filter.getOperator() == Filter.OP_EQUAL) {
        String propertyName = filter.getProperty();
        if (mapper instanceof LdapAttributesMapper) {
            propertyName = ((LdapAttributesMapper) mapper)
                    .getLdapAttribute(propertyName);
        }
        return propertyName + "=" + filter.getValue().toString();
    } else {
        LOGGER.error("MISSING IMPLEMENTATION FOR " + filter);
    }
    return null;
}
 
Example #6
Source File: KnoxSSOAuthenticationFilterTest.java    From metron with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void getAuthenticationShouldProperlyPopulateAuthentication() {
  LdapTemplate ldapTemplate = mock(LdapTemplate.class);
  KnoxSSOAuthenticationFilter knoxSSOAuthenticationFilter = spy(new KnoxSSOAuthenticationFilter("ou=people,dc=hadoop,dc=apache,dc=org",
          mock(Path.class),
          "knoxKeyString",
          "knoxCookie",
          ldapTemplate
  ));

  HttpServletRequest request = mock(HttpServletRequest.class);

  when(ldapTemplate.search(any(LdapQuery.class), any(AttributesMapper.class))).thenReturn(Arrays.asList("USER", "ADMIN"));

  Authentication authentication = knoxSSOAuthenticationFilter.getAuthentication("userName", request);
  Object[] grantedAuthorities = authentication.getAuthorities().toArray();
  assertEquals("ROLE_USER", grantedAuthorities[0].toString());
  assertEquals("ROLE_ADMIN", grantedAuthorities[1].toString());
  assertEquals("userName", authentication.getName());
}
 
Example #7
Source File: KnoxSSOAuthenticationFilter.java    From metron with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the Spring Authentication object using the supplied user name and groups looked up from LDAP.  Groups are currently
 * mapped directly to Spring roles by converting to upper case and prepending the name with "ROLE_".
 * @param userName The username to build the Authentication object with.
 * @param httpRequest HttpServletRequest
 * @return Authentication object for the given user.
 */
protected Authentication getAuthentication(String userName, HttpServletRequest httpRequest) {
  String ldapName = LdapNameBuilder.newInstance().add(userSearchBase).add("uid", userName).build().toString();

  // Search ldap for a user's groups and convert to a Spring role
  List<GrantedAuthority> grantedAuths = ldapTemplate.search(query()
          .where("objectclass")
          .is("groupOfNames")
          .and("member")
          .is(ldapName), (AttributesMapper<String>) attrs -> (String) attrs.get("cn").get())
          .stream()
          .map(group -> String.format("%s%s", SECURITY_ROLE_PREFIX, group.toUpperCase()))
          .map(SimpleGrantedAuthority::new).collect(Collectors.toList());

  final UserDetails principal = new User(userName, "", grantedAuths);
  final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
          principal, "", grantedAuths);
  WebAuthenticationDetails webDetails = new WebAuthenticationDetails(httpRequest);
  authentication.setDetails(webDetails);
  return authentication;
}
 
Example #8
Source File: LdapService.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private AttributesMapper getAttributeMapper(final Object... baseArgs) {
	return new AttributesMapper() {

		@Override
		public Object mapFromAttributes(Attributes attrs) throws NamingException {
			LdapEntryVO entry = new LdapEntryVO();
			entry.setUsername((String) attrs.get(USERNAME_ATTRIBUTE_ID).get());
			DistinguishedName dn = new DistinguishedName(getBase(baseArgs));
			dn.add(USERNAME_ATTRIBUTE_ID, entry.getUsername());
			entry.setAbsoluteDn(dn.encode());
			Map<String, Object> attributes = new LinkedHashMap<String, Object>();
			if (searchResultAttributes != null) {
				for (int i = 0; i < searchResultAttributes.length; i++) {
					Attribute attr = attrs.get(searchResultAttributes[i]);
					if (attr != null) {
						attributes.put(searchResultAttributes[i], attr.get());
					}
				}
			}
			entry.setAttributes(attributes);
			return entry;
		}
	};
}
 
Example #9
Source File: ContextSourceTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	log.debug("Verifying result");

	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Person");
			assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
			return new Object();
		}
	});

	assertThat(ldapResult).isNotNull();
}
 
Example #10
Source File: ContextSourceTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateAndRename() {
	String dn = "cn=Some Person2,ou=company1,ou=Sweden";
	String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
	// Perform test
	dummyDao.updateAndRename(dn, newDn, "Updated description");

	// Verify that entry was moved and updated.
	Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(object).isNotNull();
	dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
}
 
Example #11
Source File: ContextSourceTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributesWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		// Perform test
		dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	// Verify result - check that the operation was properly rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Person");
			assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #12
Source File: ContextSourceTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributes() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	// Perform test
	dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");

	// Verify result - check that the operation was not rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #13
Source File: ContextSourceTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnbindWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		// Perform test
		dummyDao.unbindWithException(dn, "Some Person");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	// Verify result - check that the operation was properly rolled back
	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			// Just verify that the entry still exists.
			return new Object();
		}
	});

	assertThat(ldapResult).isNotNull();
}
 
Example #14
Source File: ContextSourceTransactionManagerNamespaceIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	log.debug("Verifying result");

	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Person");
			assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
			return new Object();
		}
	});

	assertThat(ldapResult).isNotNull();
}
 
Example #15
Source File: ContextSourceTransactionManagerNamespaceIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	dummyDao.update(dn, "Some Person", "Updated Person", "Updated description");

	log.debug("Verifying result");
	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated Person");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(ldapResult).isNotNull();

	dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
 
Example #16
Source File: ContextSourceTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	dummyDao.update(dn, "Some Person", "Updated Person", "Updated description");

	log.debug("Verifying result");
	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated Person");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(ldapResult).isNotNull();

	dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
 
Example #17
Source File: ContextSourceTransactionManagerNamespaceIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributesWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		// Perform test
		dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	// Verify result - check that the operation was properly rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Person");
			assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #18
Source File: ContextSourceTransactionManagerNamespaceIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributes() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	// Perform test
	dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");

	// Verify result - check that the operation was not rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #19
Source File: ContextSourceTransactionManagerNamespaceIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnbindWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		// Perform test
		dummyDao.unbindWithException(dn, "Some Person");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	// Verify result - check that the operation was properly rolled back
	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			// Just verify that the entry still exists.
			return new Object();
		}
	});

	assertThat(ldapResult).isNotNull();
}
 
Example #20
Source File: ContextSourceAndHibernateTransactionManagerNamespaceITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
	person.setLastname("Updated Person");
	person.setDescription("Updated description");

	dummyDao.update(person);

	log.debug("Verifying result");
	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated Person");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
	assertThat(updatedPerson.getLastname()).isEqualTo("Updated Person");
	assertThat(updatedPerson.getDescription()).isEqualTo("Updated description");
	assertThat(ldapResult).isNotNull();
}
 
Example #21
Source File: ContextSourceAndHibernateTransactionManagerNamespaceITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateAndRename() {
	String dn = "cn=Some Person2,ou=company1,ou=Sweden";
	String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
	// Perform test
	dummyDao.updateAndRename(dn, newDn, "Updated description");

	// Verify that entry was moved and updated.
	Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(object).isNotNull();
}
 
Example #22
Source File: ContextSourceAndHibernateTransactionManagerNamespaceITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributesWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		// Perform test
		dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	// Verify result - check that the operation was properly rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Person");
			assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #23
Source File: ContextSourceAndHibernateTransactionManagerNamespaceITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributes() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	// Perform test
	dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");

	// Verify result - check that the operation was not rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #24
Source File: ContextSourceAndDataSourceTransactionManagerNamespaceITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributes() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	// Perform test
	dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");

	// Verify result - check that the operation was not rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
	dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
 
Example #25
Source File: ContextSourceAndHibernateTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
	person.setLastname("Updated Person");
	person.setDescription("Updated description");

	dummyDao.update(person);

	log.debug("Verifying result");
	Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated Person");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
	assertThat(updatedPerson.getLastname()).isEqualTo("Updated Person");
	assertThat(updatedPerson.getDescription()).isEqualTo("Updated description");
	assertThat(ldapResult).isNotNull();
}
 
Example #26
Source File: ContextSourceAndHibernateTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateAndRename() {
	String dn = "cn=Some Person2,ou=company1,ou=Sweden";
	String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
	// Perform test
	dummyDao.updateAndRename(dn, newDn, "Updated description");

	// Verify that entry was moved and updated.
	Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(object).isNotNull();
}
 
Example #27
Source File: ContextSourceAndHibernateTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributesWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		// Perform test
		dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	// Verify result - check that the operation was properly rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Person");
			assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #28
Source File: ContextSourceAndHibernateTransactionManagerIntegrationTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributes() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	// Perform test
	dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");

	// Verify result - check that the operation was not rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname");
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #29
Source File: ContextSourceAndDataSourceTransactionManagerNamespaceITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAttributesWithException() {
	String dn = "cn=Some Person,ou=company1,ou=Sweden";
	try {
		// Perform test
		dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
		fail("DummyException expected");
	}
	catch (DummyException expected) {
		assertThat(true).isTrue();
	}

	// Verify result - check that the operation was properly rolled back
	Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("sn").get()).isEqualTo("Person");
			assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
			return new Object();
		}
	});

	assertThat(result).isNotNull();
}
 
Example #30
Source File: ContextSourceAndDataSourceTransactionManagerNamespaceITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateAndRename() {
	String dn = "cn=Some Person2,ou=company1,ou=Sweden";
	String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
	// Perform test
	dummyDao.updateAndRename(dn, newDn, "Updated description");

	// Verify that entry was moved and updated.
	Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			assertThat(attributes.get("description").get()).isEqualTo("Updated description");
			return new Object();
		}
	});

	assertThat(object).isNotNull();
	dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
}