Skip to content
This repository has been archived by the owner on Apr 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #31 from phaus/master
Browse files Browse the repository at this point in the history
this fixes #30 using entryUUID as source for UUID
  • Loading branch information
phaus authored Jan 30, 2017
2 parents 61cd125 + 9aee879 commit 08d0f8c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchResult> results = ctx.search("", query, controls);
queryCount++;
Expand Down Expand Up @@ -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<SearchResult> results = ctx.search("", query, controls);
queryCount++;
Expand Down Expand Up @@ -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 {
Expand All @@ -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));
}
Expand Down
34 changes: 16 additions & 18 deletions ldap-connector/src/main/java/com/innoq/ldap/connector/LdapKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<!-- no 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() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class LdapNode implements Node {
protected String dn;
protected String modifyTimestamp;
protected String modifiersName;
protected String entryUUID;
protected String cn;

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit 08d0f8c

Please sign in to comment.