-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fairuz Wan Ismail
committed
Dec 26, 2015
1 parent
460d9b9
commit 1bdc267
Showing
6 changed files
with
116 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sample.domain; | ||
|
||
public interface LdapGroupDao { | ||
|
||
public void addMemberToGroup(String groupName, User user); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package sample.domain; | ||
|
||
import javax.naming.Name; | ||
import javax.naming.ldap.LdapName; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.ldap.core.DirContextOperations; | ||
import org.springframework.ldap.core.LdapTemplate; | ||
import org.springframework.ldap.core.support.BaseLdapNameAware; | ||
import org.springframework.ldap.support.LdapNameBuilder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class LdapGroupDaoImpl implements LdapGroupDao, BaseLdapNameAware { | ||
|
||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Autowired | ||
@Qualifier(value = "ldapTemplate") | ||
private LdapTemplate ldapTemplate; | ||
|
||
private LdapName baseLdapPath; | ||
|
||
@Override | ||
public void setBaseLdapPath(LdapName baseLdapPath) { | ||
this.baseLdapPath = baseLdapPath; | ||
} | ||
|
||
private Name buildGroupDn(String groupName) { | ||
return LdapNameBuilder.newInstance() | ||
.add("ou=groups") | ||
.add("cn", groupName).build(); | ||
} | ||
|
||
private Name buildUserDn(String uid) { | ||
return LdapNameBuilder.newInstance(baseLdapPath) | ||
.add("ou", "people") | ||
.add("uid", uid) | ||
.build(); | ||
} | ||
|
||
public void addMemberToGroup(String groupName, User user) { | ||
Name groupDn = buildGroupDn(groupName); | ||
Name userDn = buildUserDn(user.getUid()); | ||
|
||
DirContextOperations ctx = ldapTemplate.lookupContext(groupDn); | ||
ctx.addAttributeValue("uniqueMember", userDn); | ||
ldapTemplate.modifyAttributes(ctx); | ||
} | ||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sample.service; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import sample.domain.LdapGroupDaoImpl; | ||
import sample.domain.User; | ||
|
||
@Component | ||
public class LdapGroupService { | ||
|
||
@Autowired | ||
private LdapGroupDaoImpl ldapGroupDao; | ||
|
||
public void addMemberToGroup(String groupName, User user) { | ||
ldapGroupDao.addMemberToGroup(groupName, user); | ||
} | ||
|
||
} |