@Test public void testCreateEntry() throws Exception { assumeTrue(isExternalServer()); try (Session session = userDir.getSession()) { assertNotNull(session); Map<String, Object> map = new HashMap<>(); map.put("username", "user0"); map.put("password", "pass0"); map.put("firstName", "User"); map.put("lastName", ""); map.put("intField", Long.valueOf(0)); map.put("dn", "cn=this,ou=is,ou=a,ou=fake,o=dn"); map.put("email", "nobody@nowhere.com"); map.put("employeeType", Arrays.asList("item1", "item2")); map.put("groups", Arrays.asList("members", "administrators")); DocumentModel dm = session.createEntry(map); dm = session.getEntry("user0"); assertNotNull(dm); String id = dm.getId(); assertNotNull(id); String[] schemaNames = dm.getSchemas(); assertEquals(1, schemaNames.length); assertEquals(USER_SCHEMANAME, schemaNames[0]); assertEquals("user0", dm.getProperty(USER_SCHEMANAME, "username")); assertEquals("User", dm.getProperty(USER_SCHEMANAME, "firstName")); assertEquals("", dm.getProperty(USER_SCHEMANAME, "lastName")); assertEquals(Long.valueOf(0), dm.getProperty(USER_SCHEMANAME, "intField")); assertEquals("uid=user0,ou=people,dc=example,dc=com", dm.getProperty(USER_SCHEMANAME, "dn")); assertEquals("nobody@nowhere.com", dm.getProperty(USER_SCHEMANAME, "email")); assertEquals(Arrays.asList("item1", "item2"), dm.getProperty(USER_SCHEMANAME, "employeeType")); assertEquals(Arrays.asList("administrators", "members"), dm.getProperty(USER_SCHEMANAME, "groups")); assertTrue(session.authenticate("user0", "pass0")); } try (Session session = groupDir.getSession()) { DocumentModel entry = session.getEntry("administrators"); assertNotNull(entry); assertEquals(Arrays.asList("Administrator", "user0"), entry.getProperty(GROUP_SCHEMANAME, "members")); entry = session.getEntry("members"); assertNotNull(entry); assertEquals(Arrays.asList("Administrator", "user0", "user1", "user2"), entry.getProperty(GROUP_SCHEMANAME, "members")); } }
@Override public DocumentModel createEntry(DocumentModel entry) { Map<String, Object> fieldMap = entry.getProperties(directory.getSchema()); Map<String, Object> simpleNameFieldMap = new HashMap<>(); for (Map.Entry<String, Object> fieldEntry : fieldMap.entrySet()) { String fieldKey = fieldEntry.getKey(); if (fieldKey.contains(":")) { fieldKey = fieldKey.split(":")[1]; } simpleNameFieldMap.put(fieldKey, fieldEntry.getValue()); } return createEntry(simpleNameFieldMap); }
LDAPSession extends BaseSession { @Override public DocumentModel createEntry(DocumentModel entry) { Map<String, Object> fieldMap = entry.getProperties(directory.getSchema()); Map<String, Object> simpleNameFieldMap = new HashMap<>(); for (Map.Entry<String, Object> fieldEntry : fieldMap.entrySet()) { String fieldKey = fieldEntry.getKey(); if (fieldKey.contains(":")) { fieldKey = fieldKey.split(":")[1]; } simpleNameFieldMap.put(fieldKey, fieldEntry.getValue()); } return createEntry(simpleNameFieldMap); } }
LDAPSession extends BaseSession { @Override public DocumentModel createEntry(DocumentModel entry) { Map<String, Object> fieldMap = entry.getProperties(directory.getSchema()); Map<String, Object> simpleNameFieldMap = new HashMap<>(); for (Map.Entry<String, Object> fieldEntry : fieldMap.entrySet()) { String fieldKey = fieldEntry.getKey(); if (fieldKey.contains(":")) { fieldKey = fieldKey.split(":")[1]; } simpleNameFieldMap.put(fieldKey, fieldEntry.getValue()); } return createEntry(simpleNameFieldMap); } LDAPSession(LDAPDirectory directory); }
LDAPSession extends BaseSession { @Override public DocumentModel createEntry(DocumentModel entry) { Map<String, Object> fieldMap = entry.getProperties(directory.getSchema()); Map<String, Object> simpleNameFieldMap = new HashMap<>(); for (Map.Entry<String, Object> fieldEntry : fieldMap.entrySet()) { String fieldKey = fieldEntry.getKey(); if (fieldKey.contains(":")) { fieldKey = fieldKey.split(":")[1]; } simpleNameFieldMap.put(fieldKey, fieldEntry.getValue()); } return createEntry(simpleNameFieldMap); } LDAPSession(LDAPDirectory directory); @Override LDAPDirectory getDirectory(); DirContext getContext(); @Override void deleteEntryWithoutReferences(String id); @Override boolean hasEntry(String id); @Override void deleteEntry(String id, Map<String, String> map); @Override DocumentModel getEntryFromSource(String id, boolean fetchReferences); @Override DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, Map<String, String> orderBy,
            boolean fetchReferences, int limit, int offset); @Override DocumentModelList query(QueryBuilder queryBuilder, boolean fetchReferences); @Override List<String> queryIds(QueryBuilder queryBuilder); @Override void close(); @Override boolean authenticate(String username, String password); @Override boolean isAuthenticating(); boolean rdnMatchesIdField(); @Override // useful for the log function String toString(); @Override DocumentModel createEntry(DocumentModel entry); }
LDAPSession extends BaseSession { @Override public DocumentModel createEntry(DocumentModel entry) { Map<String, Object> fieldMap = entry.getProperties(directory.getSchema()); Map<String, Object> simpleNameFieldMap = new HashMap<>(); for (Map.Entry<String, Object> fieldEntry : fieldMap.entrySet()) { String fieldKey = fieldEntry.getKey(); if (fieldKey.contains(":")) { fieldKey = fieldKey.split(":")[1]; } simpleNameFieldMap.put(fieldKey, fieldEntry.getValue()); } return createEntry(simpleNameFieldMap); } LDAPSession(LDAPDirectory directory); @Override LDAPDirectory getDirectory(); DirContext getContext(); @Override void deleteEntryWithoutReferences(String id); @Override boolean hasEntry(String id); @Override void deleteEntry(String id, Map<String, String> map); @Override DocumentModel getEntryFromSource(String id, boolean fetchReferences); @Override DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, Map<String, String> orderBy,
            boolean fetchReferences, int limit, int offset); @Override DocumentModelList query(QueryBuilder queryBuilder, boolean fetchReferences); @Override List<String> queryIds(QueryBuilder queryBuilder); @Override void close(); @Override boolean authenticate(String username, String password); @Override boolean isAuthenticating(); boolean rdnMatchesIdField(); @Override // useful for the log function String toString(); @Override DocumentModel createEntry(DocumentModel entry);  }