diff --git a/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapHelper.java b/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapHelper.java index 68013ad..4c4985f 100644 --- a/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapHelper.java +++ b/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapHelper.java @@ -293,7 +293,7 @@ public Node getUser(final String uid) { SearchResult searchResult; Attributes attributes; SearchControls controls = new SearchControls(); - controls.setReturningAttributes(new String[]{LdapKeys.ASTERISK, LdapKeys.MODIFY_TIMESTAMP, LdapKeys.MODIFIERS_NAME}); + controls.setReturningAttributes(new String[]{LdapKeys.ASTERISK, LdapKeys.MODIFY_TIMESTAMP, LdapKeys.MODIFIERS_NAME, LdapKeys.ENTRY_UUID}); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration results = ctx.search("", query, controls); queryCount++; @@ -372,7 +372,7 @@ public Node getGroup(final String cn) { SearchResult searchResult; Attributes attributes; SearchControls controls = new SearchControls(); - controls.setReturningAttributes(new String[]{LdapKeys.ASTERISK, LdapKeys.MODIFY_TIMESTAMP, LdapKeys.MODIFIERS_NAME}); + controls.setReturningAttributes(new String[]{LdapKeys.ASTERISK, LdapKeys.MODIFY_TIMESTAMP, LdapKeys.MODIFIERS_NAME, LdapKeys.ENTRY_UUID}); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration results = ctx.search("", query, controls); queryCount++; @@ -1104,6 +1104,8 @@ private LdapUser fillAttributesInUser(LdapUser user, Attributes attributes) { user.setModifyTimestamp(getAttributeOrNa(attributes, key)); } else if (LdapKeys.MODIFIERS_NAME.equals(key)) { user.setModifiersName(getAttributeOrNa(attributes, key)); + } else if (LdapKeys.ENTRY_UUID.equals(key)) { + user.setEntryUUID(getAttributeOrNa(attributes, key)); } else if (LdapKeys.USER_PASSWORD.equals(key)) { user.addAttribute(new BasicAttribute(LdapKeys.USER_PASSWORD, null)); } else { @@ -1128,6 +1130,8 @@ private LdapGroup fillAttributesInGroup(LdapGroup group, Attributes attributes) group.setModifyTimestamp(getAttributeOrNa(attributes, key)); } else if (LdapKeys.MODIFIERS_NAME.equals(key)) { group.setModifiersName(getAttributeOrNa(attributes, key)); + } else if (LdapKeys.ENTRY_UUID.equals(key)) { + group.setEntryUUID(getAttributeOrNa(attributes, key)); } else { group.addAttribute((BasicAttribute) attributes.get(key)); } diff --git a/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapKeys.java b/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapKeys.java index 014dd00..48e8a96 100644 --- a/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapKeys.java +++ b/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapKeys.java @@ -18,30 +18,28 @@ public class LdapKeys { - public static final String USER_OBJECTCLASS = "person"; - public static final String ASTERISK = "*"; - public static final String OWNER = "owner"; - public static final String MODIFIERS_NAME = "modifiersName"; - public static final String GROUP_OBJECTCLASS = "groupOfNames"; public static final String ADMIN_GROUP_CN = "Administratoren"; + public static final String ATTR_OU_PEOPLE = ".ou_people"; + public static final String ASTERISK = "*"; + public static final String DEFAULT_JABBER_SERVER = "jabber.example.com"; public static final String DEFAULT_SSH_KEY = ""; - public static final String JPEG_PHOTO = "jpegPhoto"; public static final String ENTRY_CN_FORMAT = "%s=%s,%s"; - public static final String USER_PASSWORD = "userPassword"; - public static final String USER_ID_ATTRIBUTE = "uid"; - public static final String OBJECT_CLASS = "objectClass"; - public static final String MODIFY_TIMESTAMP = "modifyTimestamp"; - public static final String GROUP_ID_ATTRIBTUE = "cn"; + public static final String ENTRY_UUID = "entryUUID"; public static final String GROUP_CN_FORMAT = "%s=%s,%s"; - - public static final String ATTR_OU_PEOPLE = ".ou_people"; - - // DEFAULT Values + public static final String GROUP_ID_ATTRIBTUE = "cn"; public static final String GROUP_MEMBER_ATTRIBUTE = "member"; - public static final String DEFAULT_JABBER_SERVER = "jabber.example.com"; - public static final String USER_UID_FORMAT = "%s=%s,%s"; - + public static final String GROUP_OBJECTCLASS = "groupOfNames"; + public static final String JPEG_PHOTO = "jpegPhoto"; public static final String LDAP_ATTRIBUTES_BINARY = "java.naming.ldap.attributes.binary"; + public static final String MODIFIERS_NAME = "modifiersName"; + public static final String MODIFY_TIMESTAMP = "modifyTimestamp"; + public static final String OBJECT_CLASS = "objectClass"; + public static final String OWNER = "owner"; + public static final String USER_ID_ATTRIBUTE = "uid"; + public static final String USER_OBJECTCLASS = "person"; + public static final String USER_PASSWORD = "userPassword"; + public static final String USER_UID_FORMAT = "%s=%s,%s"; + private LdapKeys() {} } diff --git a/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapNode.java b/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapNode.java index 9b9c86f..0f6e4c3 100644 --- a/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapNode.java +++ b/ldap-connector/src/main/java/com/innoq/ldap/connector/LdapNode.java @@ -36,6 +36,7 @@ public class LdapNode implements Node { protected String dn; protected String modifyTimestamp; protected String modifiersName; + protected String entryUUID; protected String cn; /** @@ -203,7 +204,15 @@ public void setModifiersName(final String modifiersName) { this.modifiersName = modifiersName.trim(); } - public String getModifiersName() { + public String getEntryUUID() { + return entryUUID; + } + + public void setEntryUUID(String entryUUID) { + this.entryUUID = entryUUID; + } + + public String getModifiersName() { return this.modifiersName; } diff --git a/ldap-connector/src/test/java/com/innoq/ldap/connector/TestGroup.java b/ldap-connector/src/test/java/com/innoq/ldap/connector/TestGroup.java index 36f94c9..8a583ce 100644 --- a/ldap-connector/src/test/java/com/innoq/ldap/connector/TestGroup.java +++ b/ldap-connector/src/test/java/com/innoq/ldap/connector/TestGroup.java @@ -75,18 +75,34 @@ public void testGroupLoad() { @Test public void testCreateGroup() throws Exception { - Node g1 = HELPER.getGroup(CN); - assertTrue(g1.isEmpty()); - LdapGroup t1 = Utils.getTestGroup("test"); - t1 = Utils.updatedGroup(t1, CN); - if (HELPER.setGroup(t1)) { + Node n1 = HELPER.getGroup(CN); + assertTrue(n1.isEmpty()); + LdapGroup g1 = Utils.getTestGroup("test"); + g1 = Utils.updatedGroup(g1, CN); + if (HELPER.setGroup(g1)) { LOG.log(Level.INFO, "created Group {0}", CN); } - g1 = HELPER.getGroup(CN); - assertFalse(g1.isEmpty()); - + n1 = HELPER.getGroup(CN); + assertFalse(n1.isEmpty()); + Utils.removeTestGroup(g1); } + @Test + public void testCreateGroupWithMetadata() throws Exception { + LdapGroup g1 = Utils.createTestGroup(CN); + String[] parts; + g1 = (LdapGroup) HELPER.getGroup(CN); + assertNotNull(g1.getModifiersName()); + parts = g1.getModifiersName().split("="); + assertTrue(parts.length > 0); + assertNotNull(g1.getEntryUUID()); + parts = g1.getEntryUUID().split("-"); + assertTrue(parts.length > 0); + assertNotNull(g1.getModifyTimestamp()); + assertTrue(g1.getModifyTimestamp().contains("Z")); + Utils.removeTestGroup(g1); + } + @Test public void testAddUserToGroup() throws Exception { LdapGroup g1 = Utils.createTestGroup(CN); diff --git a/ldap-connector/src/test/java/com/innoq/ldap/connector/TestUser.java b/ldap-connector/src/test/java/com/innoq/ldap/connector/TestUser.java index e7e4f0c..c92a2c3 100644 --- a/ldap-connector/src/test/java/com/innoq/ldap/connector/TestUser.java +++ b/ldap-connector/src/test/java/com/innoq/ldap/connector/TestUser.java @@ -43,7 +43,6 @@ public TestUser() { @Test public void testCreateUser() throws Exception { - //String uid = "newTestUser"; Node u1 = HELPER.getUser(UID); assertTrue(u1.isEmpty()); LdapUser t1 = Utils.getTestUser(UID); @@ -54,6 +53,22 @@ public void testCreateUser() throws Exception { assertFalse(u1.isEmpty()); Utils.removeTestUser(t1); } + + @Test + public void testCreateUserWithMetadata() throws Exception { + LdapUser u1 = Utils.createTestUser(UID); + String[] parts; + u1 = (LdapUser) HELPER.getUser(UID); + assertNotNull(u1.getModifiersName()); + parts = u1.getModifiersName().split("="); + assertTrue(parts.length > 0); + parts = u1.getEntryUUID().split("-"); + assertNotNull(u1.getEntryUUID()); + assertTrue(parts.length > 0); + assertNotNull(u1.getModifyTimestamp()); + assertTrue(u1.getModifyTimestamp().contains("Z")); + Utils.removeTestUser(u1); + } @Test public void testLoginWithNull() throws Exception {