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 #35 from phaus/master
Browse files Browse the repository at this point in the history
having now the real LDAP Node DN & Code Cleanup
  • Loading branch information
phaus authored Feb 8, 2017
2 parents 5fab5ab + 3612865 commit ce569f1
Show file tree
Hide file tree
Showing 31 changed files with 74 additions and 319 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
innoQ LDAP Client Library
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ For more Examples have a look into the

# Legal

Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
18 changes: 0 additions & 18 deletions ldap-connector/conf/dependencies.yml

This file was deleted.

19 changes: 0 additions & 19 deletions ldap-connector/conf/messages

This file was deleted.

22 changes: 0 additions & 22 deletions ldap-connector/conf/routes

This file was deleted.

4 changes: 2 additions & 2 deletions ldap-connector/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -118,4 +118,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@ public class LdapEntry extends LdapNode implements Comparable<LdapEntry> {

public LdapEntry(String cn, String owner) {
super();
this.cn = cn;
this.owner = owner;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -95,7 +95,7 @@ public boolean isEmpty() {
@Override
public int hashCode() {
int hash = 7;
hash = 79 * hash + (this.cn != null ? this.cn.hashCode() : 0);
hash = 79 * hash + (get("cn") != null ? get("cn").hashCode() : 0);
hash = 79 * hash + (this.attributes != null ? this.attributes.hashCode() : 0);
return hash;
}
Expand All @@ -109,7 +109,7 @@ public boolean equals(Object obj) {
return false;
}
final LdapGroup other = (LdapGroup) obj;
if ((this.cn == null) ? (other.cn != null) : !this.cn.equals(other.cn)) {
if ((get("cn") == null) ? (other.get("cn") != null) : !get("cn").equals(get("cn"))) {
return false;
}
return true;
Expand All @@ -125,7 +125,7 @@ public int compareTo(LdapGroup t) {

@Override
public String toString() {
return this.cn + " # " + attributes.size();
return get("cn") + " # " + attributes.size();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -618,6 +618,7 @@ public boolean checkCredentials(final String uid, final String password) {
*/
public LdapUser getUserTemplate(String uid) {
LdapUser user = new LdapUser(uid, this);
user.set("dn", getDNForNode(user));
for (String oc : userObjectClasses) {
user.addObjectClass(oc.trim());
}
Expand Down Expand Up @@ -662,6 +663,7 @@ public LdapUser getUserTemplate(String uid) {
*/
public LdapGroup getGroupTemplate(String cn) {
LdapGroup group = new LdapGroup(cn, this);
group.set("dn", getDNForNode(group));
for (String oc : groupObjectClasses) {
group.addObjectClass(oc.trim());
}
Expand Down Expand Up @@ -917,6 +919,10 @@ private List<ModificationItem> buildMemberChangeSets(List<ModificationItem> miLi
}
for (LdapUser member : oldLdapGroup.getUsers()) {
if (!newLdapGroup.getUsers().contains(member)) {
if(oldLdapGroup.getUsers().size() == 1) {
Logger.error("Group "+oldLdapGroup.getName()+" has only one member left. Cannot remove "+member.getName());
return miList;
}
a = new BasicAttribute(groupMemberAttribut, member.getDn());
miList.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, a));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
25 changes: 10 additions & 15 deletions ldap-connector/src/main/java/com/innoq/ldap/connector/LdapNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,8 +33,7 @@ public class LdapNode implements Node {
protected Set<String> keys;
protected Set<String> objectClasses;
protected String name;
protected String dn;
protected String cn;
private String dn;

/**
* Basic Constructor.
Expand All @@ -52,9 +51,8 @@ public LdapNode() {
@Override
public String get(String key) {
if("dn".equals(key)) {
return dn;
}
if (key != null
return this.dn;
} else if (key != null
&& attributes != null
&& getKeys().contains(key)
&& attributes.get(key) != null) {
Expand Down Expand Up @@ -82,9 +80,9 @@ public boolean isEmpty() {
*/
@Override
public void set(String key, String value) {
if("dn".equals(key)) {
dn = value;
} else if (value != null
if("dn".equals(key)) {
this.dn = value;
} else if (value != null
&& !value.isEmpty()
&& key != null
&& !key.isEmpty()) {
Expand Down Expand Up @@ -112,11 +110,11 @@ public void setAttributes(BasicAttributes attributes) {
}

public void setCn(String cn) {
this.cn = cn;
set("cn", cn);
}

public String getCn() {
return this.cn == null ? "" : this.cn;
return get("cn");
}

public boolean isNew() {
Expand Down Expand Up @@ -177,14 +175,11 @@ public void addObjectClass(final String objectClass) {

@Override
public String getName() {
return name;
return getCn();
}

@Override
public String getDn() {
if (dn == null) {
dn = LdapHelper.getInstance().getDNForNode(this);
}
return dn;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 4 additions & 0 deletions ldap-connector/src/main/java/com/innoq/ldap/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* This Package contains the ldap Implementation of LiQID.
*/
package com.innoq.ldap;
2 changes: 1 addition & 1 deletion ldap-connector/src/main/java/com/innoq/ldap/util/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ public void testRemoveUserFromGroup() throws Exception {
Utils.removeTestUsers(users);
}

@Test
public void testRemoveUserFromGroupNotAllowed() throws Exception {
LdapGroup g1 = Utils.createTestGroup(CN);
assertTrue(g1.getUsers().size() == 1);
Node principal = HELPER.getPrincipal();
LdapUser principalUser = (LdapUser) principal;
g1.rmUser(principalUser);
HELPER.setGroup(g1);
LdapGroup g2 = Utils.createTestGroup(CN);
assertTrue(g2.getUsers().size() == 1);
Utils.removeTestGroup(g1);
}

@Test
public void testLoadPrincipalUserFromGroup() throws Exception {
LdapGroup g1 = Utils.createTestGroup(CN);
assertTrue(g1.getUsers().size() == 1);
Node principal = HELPER.getPrincipal();
LdapUser principalUser = (LdapUser) principal;
Set<LdapUser> users = g1.getUsers();
assertTrue(users.size() == 1);
for(LdapUser user : users) {
assertEquals(principalUser.getDn(), user.getDn());
}
Utils.removeTestGroup(g1);
}

@Test
public void testAddUsersToGroup() throws Exception {
testUser2 = HELPER.getUserTemplate("U4_" + System.currentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2012 innoQ Deutschland GmbH
# Copyright (C) 2017 innoQ Deutschland GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion model/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion model/src/main/java/com/innoq/liqid/model/Helper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion model/src/main/java/com/innoq/liqid/model/Node.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion utils/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012 innoQ Deutschland GmbH
Copyright (C) 2017 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit ce569f1

Please sign in to comment.