Java Code Examples for org.springframework.ldap.core.DirContextAdapter#addAttributeValue()

The following examples show how to use org.springframework.ldap.core.DirContextAdapter#addAttributeValue() . 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: IncrementalAttributeMapperITest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
private void createUser(String username) throws UnsupportedEncodingException {
    DirContextAdapter ctx = new DirContextAdapter(new DistinguishedName(OU_DN).append("cn", username));

    ctx.addAttributeValue("objectclass", "top");
    ctx.addAttributeValue("objectclass", "person");
    ctx.addAttributeValue("objectclass", "organizationalPerson");
    ctx.addAttributeValue("objectclass", "user");

    ctx.setAttributeValue("givenName", username);
    ctx.setAttributeValue("userPrincipalName", username + "@example.com");
    ctx.setAttributeValue("cn", username);
    ctx.setAttributeValue("description", "Dummy user");
    ctx.setAttributeValue("sAMAccountName", username.toUpperCase() + "." + username.toUpperCase());
    ctx.setAttributeValue("userAccountControl", "512");

    String newQuotedPassword = "\"" + DEFAULT_PASSWORD + "\"";
    ctx.setAttributeValue("unicodePwd", newQuotedPassword.getBytes("UTF-16LE"));

    ldapTemplate.bind(ctx);
}
 
Example 2
Source File: LdapTemplateBindUnbindITest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindGroupOfUniqueNamesWithNameValues() {
    DirContextAdapter ctx = new DirContextAdapter(LdapUtils.newLdapName("cn=TEST,ou=groups"));
    ctx.addAttributeValue("cn", "TEST");
    ctx.addAttributeValue("objectclass", "top");
    ctx.addAttributeValue("objectclass", "groupOfUniqueNames");
    ctx.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base));
    tested.bind(ctx);
}
 
Example 3
Source File: IncrementalAttributeMapperITest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
private void createGroup() {
    DirContextAdapter ctx = new DirContextAdapter(GROUP_DN);

    ctx.addAttributeValue("objectclass", "top");
    ctx.addAttributeValue("objectclass", "group");
    ctx.addAttributeValue("cn", "testgroup");
    ctx.addAttributeValue("sAMAccountName", "TESTGROUP");

    for (int i = 0; i < 1501; i++) {
        ctx.addAttributeValue("member", buildUserRefDn("test" + i));
    }

    ldapTemplate.bind(ctx);
}
 
Example 4
Source File: IncrementalAttributeMapperITest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
private void createOu() {
    DirContextAdapter ctx = new DirContextAdapter(OU_DN);

    ctx.addAttributeValue("objectClass", "top");
    ctx.addAttributeValue("objectClass", "organizationalUnit");

    ctx.setAttributeValue("ou", "dummy");
    ctx.setAttributeValue("description", "dummy description");

    ldapTemplate.bind(ctx);
}
 
Example 5
Source File: SchemaToJavaAdITest.java    From spring-ldap with Apache License 2.0 4 votes vote down vote up
@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);
}