Java Code Examples for org.springframework.ldap.core.DirContextAdapter#setAttributeValues()
The following examples show how to use
org.springframework.ldap.core.DirContextAdapter#setAttributeValues() .
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: LdapTemplateBindUnbindITest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void testBindAndRebindWithDirContextAdapterOnly() { DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN)); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(adapter); verifyBoundCorrectData(); adapter.setAttributeValue("sn", "Person4.Changed"); tested.rebind(adapter); verifyReboundCorrectData(); tested.unbind(DN); verifyCleanup(); }
Example 2
Source File: DummyDaoLdapAndHibernateImpl.java From spring-ldap with Apache License 2.0 | 6 votes |
public void create(OrgPerson person) { DistinguishedName dn = new DistinguishedName(); dn.add("ou", person.getCountry()); dn.add("ou", person.getCompany()); dn.add("cn", person.getFullname()); DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("objectclass", new String[] { "top", "person" }); ctx.setAttributeValue("cn", person.getFullname()); ctx.setAttributeValue("sn", person.getLastname()); ctx.setAttributeValue("description", person.getDescription()); ldapTemplate.bind(dn, ctx, null); this.getHibernateTemplate().saveOrUpdate(person); }
Example 3
Source File: LdapTemplateNoBaseSuffixITest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void testBindAndUnbind_Plain() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind("cn=Some Person4, ou=company1, ou=Sweden," + base, adapter, null); DirContextAdapter result = (DirContextAdapter) tested .lookup("cn=Some Person4, ou=company1, ou=Sweden," + base); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person4"); assertThat(result.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person4,ou=company1,ou=Sweden," + base)); tested.unbind("cn=Some Person4,ou=company1,ou=Sweden," + base); try { tested.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { assertThat(true).isTrue(); } }
Example 4
Source File: PersonDaoImpl.java From spring-ldap with Apache License 2.0 | 5 votes |
private void mapToContext(Person person, DirContextAdapter context) { context.setAttributeValues("objectclass", new String[] { "top", "person" }); context.setAttributeValue("cn", person.getFullName()); context.setAttributeValue("sn", person.getLastName()); context.setAttributeValue("description", person.getDescription()); context.setAttributeValue("telephoneNumber", person.getPhone()); }
Example 5
Source File: LdapClient.java From tutorials with MIT License | 5 votes |
public void create(final String username, final String password) { Name dn = LdapNameBuilder .newInstance() .add("ou", "users") .add("cn", username) .build(); DirContextAdapter context = new DirContextAdapter(dn); context.setAttributeValues("objectclass", new String[]{"top", "person", "organizationalPerson", "inetOrgPerson"}); context.setAttributeValue("cn", username); context.setAttributeValue("sn", username); context.setAttributeValue("userPassword", digestSHA(password)); ldapTemplate.bind(context); }
Example 6
Source File: SimpleLdapTemplateITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testBindAndUnbindWithDirContextAdapter() { DirContextAdapter adapter = new DirContextAdapter(DN); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); ldapTemplate.bind(adapter); verifyBoundCorrectData(); ldapTemplate.unbind(DN); verifyCleanup(); }
Example 7
Source File: SimpleLdapTemplateITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testBindAndUnbindName() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); ldapTemplate.bind(DN, adapter, null); verifyBoundCorrectData(); ldapTemplate.unbind(DN); verifyCleanup(); }
Example 8
Source File: SimpleLdapTemplateITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testBindAndUnbind() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); ldapTemplate.bind(DN_STRING, adapter, null); verifyBoundCorrectData(); ldapTemplate.unbind(DN_STRING); verifyCleanup(); }
Example 9
Source File: LdapTemplateBindUnbindITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testBindAndUnbindWithDirContextAdapterOnly() { DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN)); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(adapter); verifyBoundCorrectData(); tested.unbind(DN); verifyCleanup(); }
Example 10
Source File: LdapTemplateBindUnbindITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testBindAndUnbindWithDirContextAdapterUsingLdapName() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(LdapUtils.newLdapName(DN), adapter, null); verifyBoundCorrectData(); tested.unbind(LdapUtils.newLdapName(DN)); verifyCleanup(); }
Example 11
Source File: LdapTemplateBindUnbindITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testBindAndUnbindWithDirContextAdapter() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(DN, adapter, null); verifyBoundCorrectData(); tested.unbind(DN); verifyCleanup(); }
Example 12
Source File: InvalidBackslashITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Before public void prepareTestedInstance() throws Exception { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some\\Person6"); adapter.setAttributeValue("sn", "Person6"); adapter.setAttributeValue("description", "Some description"); tested.unbind(DN); tested.bind(DN, adapter, null); }
Example 13
Source File: LdapTemplateRenameITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Before public void prepareTestedInstance() throws Exception { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person6"); adapter.setAttributeValue("sn", "Person6"); adapter.setAttributeValue("description", "Some description"); tested.bind(DN, adapter, null); }
Example 14
Source File: LdapAndJdbcDummyDaoImpl.java From spring-ldap with Apache License 2.0 | 5 votes |
public void create(String country, String company, String fullname, String lastname, String description) { DistinguishedName dn = new DistinguishedName(); dn.add("ou", country); dn.add("ou", company); dn.add("cn", fullname); DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("objectclass", new String[] { "top", "person" }); ctx.setAttributeValue("cn", fullname); ctx.setAttributeValue("sn", lastname); ctx.setAttributeValue("description", description); ldapTemplate.bind(dn, ctx, null); jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { fullname, lastname, description }); }
Example 15
Source File: LdapDummyDaoImpl.java From spring-ldap with Apache License 2.0 | 5 votes |
@Override public void createRecursivelyAndUnbindSubnode() { DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("objectclass", new String[]{"top", "organizationalUnit"}); ctx.setAttributeValue("ou", "dummy"); ctx.setAttributeValue("description", "dummy description"); ldapTemplate.bind("ou=dummy", ctx, null); ldapTemplate.bind("ou=dummy,ou=dummy", ctx, null); ldapTemplate.unbind("ou=dummy,ou=dummy"); ldapTemplate.unbind("ou=dummy"); }
Example 16
Source File: LdapDummyDaoImpl.java From spring-ldap with Apache License 2.0 | 5 votes |
public void create(String country, String company, String fullname, String lastname, String description) { DistinguishedName dn = new DistinguishedName(); dn.add("ou", country); dn.add("ou", company); dn.add("cn", fullname); DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("objectclass", new String[] { "top", "person" }); ctx.setAttributeValue("cn", fullname); ctx.setAttributeValue("sn", lastname); ctx.setAttributeValue("description", description); ldapTemplate.bind(dn, ctx, null); }
Example 17
Source File: UserService.java From secure-data-service with Apache License 2.0 | 5 votes |
private void mapUserToContext(DirContextAdapter context, User user) { context.setAttributeValues("objectclass", new String[] { "inetOrgPerson", "posixAccount", "top" }); context.setAttributeValue("givenName", user.getAttributes().get("givenName")); context.setAttributeValue("sn", user.getAttributes().get("sn")); context.setAttributeValue("uid", user.getAttributes().get("uid")); context.setAttributeValue("uidNumber", user.getAttributes().get("uidNumber")); context.setAttributeValue("gidNumber", user.getAttributes().get("gidNumber")); context.setAttributeValue("cn", user.getAttributes().get("userName")); context.setAttributeValue("mail", user.getAttributes().get("mail")); context.setAttributeValue("homeDirectory", user.getAttributes().get("homeDirectory")); context.setAttributeValue("gecos", user.getAttributes().get("resetKey")); context.setAttributeValue("userPassword", user.getAttributes().get("userPassword")); String description = ""; if (user.getAttributes().get("tenant") != null) { description += "tenant=" + user.getAttributes().get("tenant"); } if (user.getAttributes().get("edOrg") != null) { description += ",edOrg=" + user.getAttributes().get("edOrg"); } if (!"".equals(description)) { context.setAttributeValue("description", "tenant=" + user.getAttributes().get("tenant") + "," + "edOrg=" + user.getAttributes().get("edOrg")); } if (user.getAttributes().containsKey("employeeNumber")) { context.setAttributeValue("employeeNumber", user.getAttributes().get("employeeNumber")); } }
Example 18
Source File: LdapServiceImpl.java From secure-data-service with Apache License 2.0 | 4 votes |
private void mapGroupToContext(DirContextAdapter context, Group group) { context.setAttributeValues("memberUid", group.getMemberUids().toArray()); }
Example 19
Source File: LdapServiceImpl.java From secure-data-service with Apache License 2.0 | 4 votes |
/** * This method is used for both create and update operations. For updates, we do not want certain attributes overridden which could bork the LDAP server. * @param context * @param user * @param isCreate boolean to identify if the context is for a create or update. */ private void mapUserToContext(DirContextAdapter context, User user, final boolean isCreate) { LOG.debug("Before mapUserToContext: " + Boolean.toString(isCreate) + ToStringBuilder.reflectionToString(context, ToStringStyle.MULTI_LINE_STYLE)); // TAF 2014-04-01 : Commented out for updates. Why override the ObjectClasses that are returned from LDAP? Should respect what hte LDAP server returns for updates. if (isCreate) { LOG.debug("mapUserToContext (create) -- set OBJECTCLASS array."); context.setAttributeValues(OBJECTCLASS, new String[]{"inetOrgPerson", "posixAccount", "top"}); } context.setAttributeValue("givenName", user.getGivenName()); String surName = user.getSn(); context.setAttributeValue("sn", surName == null ? " " : surName); context.setAttributeValue("uid", user.getUid()); context.setAttributeValue("uidNumber", USER_ID_NUMBER); context.setAttributeValue("gidNumber", GROUP_ID_NUMBER); context.setAttributeValue("loginShell", LOGIN_SHELL); context.setAttributeValue("mail", user.getEmail()); context.setAttributeValue("homeDirectory", user.getHomeDir()); if (user.getStatus() != null && user.getStatus().getStatusString() != null) { context.setAttributeValue("destinationindicator", user.getStatus().getStatusString()); } String description = ""; if (user.getTenant() != null) { description += "tenant=" + user.getTenant(); } if (user.getEdorg() != null) { description += ",edOrg=" + user.getEdorg(); } if (!"".equals(description)) { context.setAttributeValue("description", "tenant=" + user.getTenant() + "," + "edOrg=" + user.getEdorg()); } if (user.getVendor() != null) { context.setAttributeValue("o", user.getVendor()); } LOG.debug("After mapUserToContext: " + ToStringBuilder.reflectionToString(context, ToStringStyle.MULTI_LINE_STYLE)); }
Example 20
Source File: SchemaToJavaAdITest.java From spring-ldap with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { // Create some basic converters and a converter manager converterManager = new ConverterManagerImpl(); Converter ptc = new FromStringConverter(); converterManager.addConverter(String.class, "", Byte.class, ptc); converterManager.addConverter(String.class, "", Short.class, ptc); converterManager.addConverter(String.class, "", Integer.class, ptc); converterManager.addConverter(String.class, "", Long.class, ptc); converterManager.addConverter(String.class, "", Double.class, ptc); converterManager.addConverter(String.class, "", Float.class, ptc); converterManager.addConverter(String.class, "", Boolean.class, ptc); Converter tsc = new ToStringConverter(); converterManager.addConverter(Byte.class, "", String.class, tsc); converterManager.addConverter(Short.class, "", String.class, tsc); converterManager.addConverter(Integer.class, "", String.class, tsc); converterManager.addConverter(Long.class, "", String.class, tsc); converterManager.addConverter(Double.class, "", String.class, tsc); converterManager.addConverter(Float.class, "", String.class, tsc); converterManager.addConverter(Boolean.class, "", String.class, tsc); // Bind to the directory contextSource = new LdapContextSource(); contextSource.setUrl("ldaps://127.0.0.1:" + port); contextSource.setUserDn(USER_DN); contextSource.setPassword(PASSWORD); contextSource.setPooled(false); contextSource.setBase("dc=261consulting,dc=local"); HashMap<String, Object> baseEnvironment = new HashMap<String, Object>() {{ put("java.naming.ldap.attributes.binary", "thumbnailLogo replPropertyMetaData partialAttributeSet registeredAddress userPassword telexNumber partialAttributeDeletionList mS-DS-ConsistencyGuid attributeCertificateAttribute thumbnailPhoto teletexTerminalIdentifier replUpToDateVector dSASignature objectGUID"); }}; contextSource.setBaseEnvironmentProperties(baseEnvironment); contextSource.afterPropertiesSet(); ldapTemplate = new LdapTemplate(contextSource); cleanup(); DirContextAdapter ctx = new DirContextAdapter("cn=William Hartnell,cn=Users"); ctx.setAttributeValues("objectclass", new String[]{"person","inetorgperson","organizationalperson","top"}); ctx.setAttributeValue("cn", "William Hartnell"); ctx.addAttributeValue("description", "First Doctor"); ctx.addAttributeValue("description", "Grumpy"); ctx.addAttributeValue("sn", "Hartnell"); ctx.addAttributeValue("telephonenumber", "1"); ldapTemplate.bind(ctx); }