@Test public void testGetMandatoryAttributes() throws ClientException { if (USE_EXTERNAL_TEST_LDAP_SERVER) { LDAPSession session = (LDAPSession) getLDAPDirectory( "userDirectory").getSession(); try { List<String> mandatoryAttributes = session.getMandatoryAttributes(); assertEquals(Arrays.asList("sn", "cn"), mandatoryAttributes); } finally { session.close(); } session = (LDAPSession) getLDAPDirectory("groupDirectory").getSession(); try { List<String> mandatoryAttributes = session.getMandatoryAttributes(); if (mandatoryAttributes.size() == 2) { Collections.sort(mandatoryAttributes); assertEquals(Arrays.asList("cn", "uniqueMember"), mandatoryAttributes); } else { assertEquals(Arrays.asList("cn"), mandatoryAttributes); } } finally { session.close(); } } }
@SuppressWarnings("unchecked") protected List<String> getMandatoryAttributes( Attribute objectClassesAttribute) throws DirectoryException { try { List<String> mandatoryAttributes = new ArrayList<String>(); DirContext schema = dirContext.getSchema(""); List<String> objectClasses = new ArrayList<String>(); if (objectClassesAttribute == null) { objectClasses.addAll(Arrays.asList(directory.getConfig().getCreationClasses())); } else { NamingEnumeration<Object> values = null; try { values = (NamingEnumeration<Object>) objectClassesAttribute.getAll(); while (values.hasMore()) { objectClasses.add(values.next().toString().trim()); } } catch (NamingException e) { throw new DirectoryException(e); } finally { if (values != null) { values.close(); } } } objectClasses.remove("top"); for (String creationClass : objectClasses) { Attributes attributes = schema.getAttributes("ClassDefinition/" + creationClass); Attribute attribute = attributes.get("MUST"); if (attribute != null) { NamingEnumeration<String> values = (NamingEnumeration<String>) attribute.getAll(); try { while (values.hasMore()) { String value = values.next(); mandatoryAttributes.add(value); } } finally { values.close(); } } } return mandatoryAttributes; } catch (NamingException e) { throw new DirectoryException("getMandatoryAttributes failed", e); } }
LDAPSession extends BaseSession implements EntrySource { @SuppressWarnings("unchecked") protected List<String> getMandatoryAttributes( Attribute objectClassesAttribute) throws DirectoryException { try { List<String> mandatoryAttributes = new ArrayList<String>(); DirContext schema = dirContext.getSchema(""); List<String> objectClasses = new ArrayList<String>(); if (objectClassesAttribute == null) { objectClasses.addAll(Arrays.asList(directory.getConfig().getCreationClasses())); } else { NamingEnumeration<Object> values = null; try { values = (NamingEnumeration<Object>) objectClassesAttribute.getAll(); while (values.hasMore()) { objectClasses.add(values.next().toString().trim()); } } catch (NamingException e) { throw new DirectoryException(e); } finally { if (values != null) { values.close(); } } } objectClasses.remove("top"); for (String creationClass : objectClasses) { Attributes attributes = schema.getAttributes("ClassDefinition/" + creationClass); Attribute attribute = attributes.get("MUST"); if (attribute != null) { NamingEnumeration<String> values = (NamingEnumeration<String>) attribute.getAll(); try { while (values.hasMore()) { String value = values.next(); mandatoryAttributes.add(value); } } finally { values.close(); } } } return mandatoryAttributes; } catch (NamingException e) { throw new DirectoryException("getMandatoryAttributes failed", e); } } }
LDAPSession extends BaseSession implements EntrySource { @SuppressWarnings("unchecked") protected List<String> getMandatoryAttributes( Attribute objectClassesAttribute) throws DirectoryException { try { List<String> mandatoryAttributes = new ArrayList<String>(); DirContext schema = dirContext.getSchema(""); List<String> objectClasses = new ArrayList<String>(); if (objectClassesAttribute == null) { objectClasses.addAll(Arrays.asList(directory.getConfig().getCreationClasses())); } else { NamingEnumeration<Object> values = null; try { values = (NamingEnumeration<Object>) objectClassesAttribute.getAll(); while (values.hasMore()) { objectClasses.add(values.next().toString().trim()); } } catch (NamingException e) { throw new DirectoryException(e); } finally { if (values != null) { values.close(); } } } objectClasses.remove("top"); for (String creationClass : objectClasses) { Attributes attributes = schema.getAttributes("ClassDefinition/" + creationClass); Attribute attribute = attributes.get("MUST"); if (attribute != null) { NamingEnumeration<String> values = (NamingEnumeration<String>) attribute.getAll(); try { while (values.hasMore()) { String value = values.next(); mandatoryAttributes.add(value); } } finally { values.close(); } } } return mandatoryAttributes; } catch (NamingException e) { throw new DirectoryException("getMandatoryAttributes failed", e); } } LDAPSession(LDAPDirectory directory, DirContext dirContext); }
LDAPSession extends BaseSession implements EntrySource { @SuppressWarnings("unchecked") protected List<String> getMandatoryAttributes( Attribute objectClassesAttribute) throws DirectoryException { try { List<String> mandatoryAttributes = new ArrayList<String>(); DirContext schema = dirContext.getSchema(""); List<String> objectClasses = new ArrayList<String>(); if (objectClassesAttribute == null) { objectClasses.addAll(Arrays.asList(directory.getConfig().getCreationClasses())); } else { NamingEnumeration<Object> values = null; try { values = (NamingEnumeration<Object>) objectClassesAttribute.getAll(); while (values.hasMore()) { objectClasses.add(values.next().toString().trim()); } } catch (NamingException e) { throw new DirectoryException(e); } finally { if (values != null) { values.close(); } } } objectClasses.remove("top"); for (String creationClass : objectClasses) { Attributes attributes = schema.getAttributes("ClassDefinition/" + creationClass); Attribute attribute = attributes.get("MUST"); if (attribute != null) { NamingEnumeration<String> values = (NamingEnumeration<String>) attribute.getAll(); try { while (values.hasMore()) { String value = values.next(); mandatoryAttributes.add(value); } } finally { values.close(); } } } return mandatoryAttributes; } catch (NamingException e) { throw new DirectoryException("getMandatoryAttributes failed", e); } } LDAPSession(LDAPDirectory directory, DirContext dirContext); void setSubStringMatchType(String type); Directory getDirectory(); DirContext getContext(); @Override @SuppressWarnings("unchecked") DocumentModel createEntry(Map<String, Object> fieldMap); @Override DocumentModel getEntry(String id); @Override DocumentModel getEntry(String id, boolean fetchReferences); @Override DocumentModel getEntryFromSource(String id, boolean fetchReferences); @Override boolean hasEntry(String id); @Override DocumentModelList getEntries(); @Override @SuppressWarnings("unchecked") void updateEntry(DocumentModel docModel); @Override void deleteEntry(DocumentModel dm); @Override void deleteEntry(String id); @Override void deleteEntry(String id, Map<String, String> map); DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, boolean fetchReferences,
            Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy,
            boolean fetchReferences); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext); @Override void close(); @Override List<String> getProjection(Map<String, Serializable> filter,
            String columnName); @Override List<String> getProjection(Map<String, Serializable> filter,
            Set<String> fulltext, String columnName); @Override boolean authenticate(String username, String password); @Override String getIdField(); @Override String getPasswordField(); @Override boolean isAuthenticating(); @Override boolean isReadOnly(); boolean rdnMatchesIdField(); @Override // useful for the log function String toString(); @Override DocumentModel createEntry(DocumentModel entry); }
LDAPSession extends BaseSession implements EntrySource { @SuppressWarnings("unchecked") protected List<String> getMandatoryAttributes( Attribute objectClassesAttribute) throws DirectoryException { try { List<String> mandatoryAttributes = new ArrayList<String>(); DirContext schema = dirContext.getSchema(""); List<String> objectClasses = new ArrayList<String>(); if (objectClassesAttribute == null) { objectClasses.addAll(Arrays.asList(directory.getConfig().getCreationClasses())); } else { NamingEnumeration<Object> values = null; try { values = (NamingEnumeration<Object>) objectClassesAttribute.getAll(); while (values.hasMore()) { objectClasses.add(values.next().toString().trim()); } } catch (NamingException e) { throw new DirectoryException(e); } finally { if (values != null) { values.close(); } } } objectClasses.remove("top"); for (String creationClass : objectClasses) { Attributes attributes = schema.getAttributes("ClassDefinition/" + creationClass); Attribute attribute = attributes.get("MUST"); if (attribute != null) { NamingEnumeration<String> values = (NamingEnumeration<String>) attribute.getAll(); try { while (values.hasMore()) { String value = values.next(); mandatoryAttributes.add(value); } } finally { values.close(); } } } return mandatoryAttributes; } catch (NamingException e) { throw new DirectoryException("getMandatoryAttributes failed", e); } } LDAPSession(LDAPDirectory directory, DirContext dirContext); void setSubStringMatchType(String type); Directory getDirectory(); DirContext getContext(); @Override @SuppressWarnings("unchecked") DocumentModel createEntry(Map<String, Object> fieldMap); @Override DocumentModel getEntry(String id); @Override DocumentModel getEntry(String id, boolean fetchReferences); @Override DocumentModel getEntryFromSource(String id, boolean fetchReferences); @Override boolean hasEntry(String id); @Override DocumentModelList getEntries(); @Override @SuppressWarnings("unchecked") void updateEntry(DocumentModel docModel); @Override void deleteEntry(DocumentModel dm); @Override void deleteEntry(String id); @Override void deleteEntry(String id, Map<String, String> map); DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, boolean fetchReferences,
            Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy,
            boolean fetchReferences); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext); @Override void close(); @Override List<String> getProjection(Map<String, Serializable> filter,
            String columnName); @Override List<String> getProjection(Map<String, Serializable> filter,
            Set<String> fulltext, String columnName); @Override boolean authenticate(String username, String password); @Override String getIdField(); @Override String getPasswordField(); @Override boolean isAuthenticating(); @Override boolean isReadOnly(); boolean rdnMatchesIdField(); @Override // useful for the log function String toString(); @Override DocumentModel createEntry(DocumentModel entry);  }