Skip to content

Commit 310fcf4

Browse files
Merge pull request #3 from scmenthusiast/master
Major release with improvements and new features
2 parents d93be4a + d4793a1 commit 310fcf4

18 files changed

+208
-246
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<modelVersion>4.0.0</modelVersion>
88
<groupId>com.adsk.jira.ldapgroupsync.plugin</groupId>
99
<artifactId>jira-ldap-group-sync-plugin</artifactId>
10-
<version>6.5</version>
10+
<version>6.6</version>
1111
<developers>
1212
<developer>
1313
<name>Venkat Prasad</name>

src/main/java/com/adsk/jira/ldapgroupsync/plugin/api/LDAPGroupSyncUtil.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Properties;
1111
import java.util.Set;
1212
import javax.naming.directory.SearchControls;
13+
import javax.naming.directory.SearchResult;
1314
import javax.naming.ldap.LdapContext;
1415

1516
/**
@@ -18,11 +19,11 @@
1819
*/
1920
public interface LDAPGroupSyncUtil {
2021

21-
public List<String> getUsersInGroup(LdapContext ctx, String groupName);
22+
public List<String> getUsersInLdapGroup(LdapContext ctx, String groupName);
2223

23-
public List<String> getNestedGroups(LdapContext ctx, String groupName);
24+
public List<String> getNestedLdapGroups(LdapContext ctx, String groupName);
2425

25-
public Set<String> getGroupMembers(LdapContext ctx, String groupName);
26+
public Set<String> getLdapGroupMembers(LdapContext ctx, SearchResult sr, Set<String> users);
2627

2728
public SearchControls getGroupSearchControls();
2829

@@ -41,8 +42,10 @@ public interface LDAPGroupSyncUtil {
4142
public void addUserToJiraGroup(String userName, String groupName);
4243

4344
public void removeUserFromJiraGroup(String userName, String groupName);
44-
45-
public MessageBean sync(LdapContext ctx, String ldap_group, String jira_group);
45+
public Set<String> getLdapGroupStrings(String ldapGroup);
46+
public SearchResult getGroupSearchResult(LdapContext ctx, String groupName);
47+
public long process(LdapContext ctx, String ldap_group, String jira_group);
48+
public MessageBean sync(LdapContext ctx, String ldap_group, String jira_group);
4649

4750
public void setLdapUrl(String ldapUrl);
4851
public void setSecurityPrincipal(String securityPrincipal);

src/main/java/com/adsk/jira/ldapgroupsync/plugin/api/LDAPGroupSyncUtilImpl.java

Lines changed: 86 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public LDAPGroupSyncUtilImpl(ApplicationProperties props, GroupManager groupMana
9999
}
100100
}
101101

102-
public List<String> getUsersInGroup(LdapContext ctx, String groupName) {
102+
public List<String> getUsersInLdapGroup(LdapContext ctx, String groupNameSpace) {
103103
List<String> users = new ArrayList<String>();
104104
try {
105-
String searchFilter = MessageFormat.format(UserMemberSearchFilter, groupName);
105+
String searchFilter = MessageFormat.format(UserMemberSearchFilter, groupNameSpace);
106106

107107
NamingEnumeration answer = ctx.search(baseDn, searchFilter, getMemberSearchControls());
108108
while (answer.hasMoreElements()) {
@@ -125,7 +125,7 @@ public List<String> getUsersInGroup(LdapContext ctx, String groupName) {
125125
return users;
126126
}
127127

128-
public List<String> getNestedGroups(LdapContext ctx, String groupName) {
128+
public List<String> getNestedLdapGroups(LdapContext ctx, String groupName) {
129129
List<String> groups = new ArrayList<String>();
130130
try {
131131
if( ctx != null ) {
@@ -144,8 +144,7 @@ public List<String> getNestedGroups(LdapContext ctx, String groupName) {
144144
return groups;
145145
}
146146

147-
public Set<String> getGroupMembers(LdapContext ctx, String groupName) {
148-
Set<String> users = null;
147+
public SearchResult getGroupSearchResult(LdapContext ctx, String groupName) {
149148
try {
150149
if( ctx != null ) {
151150
String searchFilter = MessageFormat.format(GroupSearchFilter, groupName);
@@ -154,25 +153,37 @@ public Set<String> getGroupMembers(LdapContext ctx, String groupName) {
154153

155154
if (answer.hasMoreElements()) {
156155
SearchResult sr = (SearchResult)answer.next();
157-
logger.debug(">>>" + sr.getNameInNamespace());
156+
return sr;
157+
}
158+
} else {
159+
logger.error("LDAP Connection Null or Failed.");
160+
}
161+
} catch (NamingException e) {
162+
logger.error(e);
163+
}
164+
165+
return null;
166+
}
167+
168+
public Set<String> getLdapGroupMembers(LdapContext ctx, SearchResult sr, Set<String> users)
169+
{
170+
try {
171+
if( ctx != null ) {
172+
if (sr != null) {
173+
logger.debug(" >>>" + sr.getNameInNamespace());
158174

159-
users = new HashSet<String>(); // create set object
160-
161-
List<String> new_users_list = getUsersInGroup(ctx, sr.getNameInNamespace());
162-
if(new_users_list.size() > 0) {
163-
users.addAll(new_users_list);
164-
}
175+
users.addAll(getUsersInLdapGroup(ctx, sr.getNameInNamespace()));
165176

166177
// support nested groups
167178
if("TRUE".equalsIgnoreCase(IsNested)) {
168-
List<String> groups = getNestedGroups(ctx, sr.getNameInNamespace());
169-
if(groups.size() > 0) {
170-
for(String group : groups) {
171-
List<String> nested_user_list = getUsersInGroup(ctx, group);
172-
if(nested_user_list.size() > 0) {
173-
users.addAll(nested_user_list);
174-
}
175-
}
179+
String searchGroupFilter = MessageFormat.format(GroupMemberSearchFilter, sr.getNameInNamespace());
180+
181+
NamingEnumeration groupAnswer = ctx.search(baseDn, searchGroupFilter, getGroupSearchControls());
182+
183+
while (groupAnswer.hasMoreElements()) {
184+
SearchResult gsr = (SearchResult) groupAnswer.next();
185+
logger.debug("*** processing nested group *** "+ gsr.getName());
186+
getLdapGroupMembers(ctx, gsr, users);
176187
}
177188
}
178189
}
@@ -302,8 +313,9 @@ public void createJiraGroup(String groupName) {
302313
}
303314
}
304315

316+
317+
305318
public MessageBean sync(LdapContext ctx, String ldap_group, String jira_group) {
306-
307319
logger.debug(" >>> "+ ldap_group +" : "+ jira_group +" <<< ");
308320
MessageBean message = new MessageBean();
309321

@@ -313,41 +325,67 @@ public MessageBean sync(LdapContext ctx, String ldap_group, String jira_group) {
313325
return message;
314326
}
315327

316-
Set<String> ldap_group_users = getGroupMembers(ctx, ldap_group);
317-
if( ldap_group_users == null ) {
318-
logger.debug("LDAP Group ("+ldap_group+") does not exists.");
319-
message.setMessage("LDAP Group ("+ldap_group+") does not exists.");
320-
message.setStatus(1);
321-
322-
} else {
323-
324-
logger.debug(" >>> Size: "+ ldap_group_users.size());
325-
326-
List<String> jira_group_users = getJiraGroupMembers(jira_group);
327-
if( jira_group_users != null ) {
328-
for(String j : jira_group_users) {
329-
if(!ldap_group_users.contains(j)) {
330-
removeUserFromJiraGroup(j, jira_group);
328+
long index = process(ctx, ldap_group, jira_group);
329+
message.setMessage("Successful. Fetch Size("+index+")");
330+
message.setStatus(0);
331+
332+
return message;
333+
}
334+
335+
public Set<String> getLdapGroupStrings(String ldapGroup) {
336+
Set<String> groups = new HashSet<String>();
337+
String[] fields = ldapGroup.trim().split(",");
338+
for(String f : fields){
339+
groups.add(f.trim());
340+
}
341+
return groups;
342+
}
343+
344+
public long process(LdapContext ctx, String ldap_group, String jira_group) {
345+
346+
long index = 0;
347+
348+
Set<String> ldapGroupStrings = getLdapGroupStrings(ldap_group);
349+
350+
Set<String> ldap_group_users = new HashSet<String>();
351+
352+
for(String lGroup : ldapGroupStrings) {
353+
logger.debug("*** Processing Ldap Group ("+lGroup+").");
354+
SearchResult sr = getGroupSearchResult(ctx, lGroup);
355+
356+
ldap_group_users.addAll(getLdapGroupMembers(ctx, sr, ldap_group_users));
357+
358+
if( ldap_group_users.isEmpty() ) {
359+
logger.debug("LDAP Group ("+lGroup+") does not exists.");
360+
361+
} else {
362+
363+
logger.debug(" >>> Size: "+ ldap_group_users.size());
364+
index = ldap_group_users.size();
365+
366+
List<String> jira_group_users = getJiraGroupMembers(jira_group);
367+
if( jira_group_users != null ) {
368+
for(String j : jira_group_users) {
369+
if(!ldap_group_users.contains(j)) {
370+
removeUserFromJiraGroup(j, jira_group);
371+
}
331372
}
332-
}
333-
for(String i : ldap_group_users) {
334-
if(!jira_group_users.contains(i)) {
373+
for(String i : ldap_group_users) {
374+
if(!jira_group_users.contains(i)) {
375+
addUserToJiraGroup(i, jira_group);
376+
}
377+
}
378+
} else {
379+
logger.debug("JIRA Group members return NULL. So adding LDAP users.");
380+
for(String i : ldap_group_users) {
335381
addUserToJiraGroup(i, jira_group);
336382
}
337383
}
338-
} else {
339-
logger.debug("JIRA Group members return NULL. So adding LDAP users.");
340-
for(String i : ldap_group_users) {
341-
addUserToJiraGroup(i, jira_group);
342-
}
343384
}
344-
345-
message.setMessage("Successful. Fetch Size("+ldap_group_users.size()+")");
346-
message.setStatus(0);
347385

348386
}
349387

350-
return message;
388+
return index;
351389
}
352390

353391
public void setLdapUrl(String ldapUrl) {

src/main/java/com/adsk/jira/ldapgroupsync/plugin/api/LdapGroupResource.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Response getLdapGroupSyncConfigs() {
7373
return Response.status(Response.Status.FORBIDDEN).entity(authError).build();
7474
}
7575

76-
List<LdapGroupSyncMapBean> results = ldapGroupSyncAoMgr.getAllGroupsMapProperties();
76+
List<LdapGroupSyncMapBean> results = ldapGroupSyncAoMgr.getGroupsMapProperties();
7777

7878
long totalTime = System.currentTimeMillis() - startTime;
7979
logger.debug("["+loggedInAppUser.getUsername()+"] Get Config. Took "+ totalTime/ 1000d +" Seconds");
@@ -113,11 +113,6 @@ public Response adminLdapGroupSync(LdapGroupSyncBean syncBean) {
113113
messageBean.setMessage("This plugin does not support JIRA default group ("+syncBean.getJiraGroup()+"). Skipping!");
114114
return Response.ok(messageBean).build();
115115
}
116-
117-
if(ldapGroupSyncAoMgr.isJiraGroupNotInSupport(syncBean.getJiraGroup()) == true) { //skip not supported
118-
messageBean.setMessage("This JIRA group ("+syncBean.getJiraGroup()+") is mapped not to support. Skipping!");
119-
return Response.ok(messageBean).build();
120-
}
121116

122117
MessageBean result = null;
123118
LdapContext ctx = null;
@@ -172,11 +167,6 @@ public Response selfLdapGroupSync(@PathParam("ldapJiraGroup") String ldapJiraGro
172167
return Response.ok(messageBean).build();
173168
}
174169

175-
if(ldapGroupSyncAoMgr.isJiraGroupNotInSupport(ldapJiraGroup) == true) { //skip not supported
176-
messageBean.setMessage("This JIRA group ("+ldapJiraGroup+") is mapped not to support. Skipping!");
177-
return Response.ok(messageBean).build();
178-
}
179-
180170
MessageBean result = null;
181171
LdapContext ctx = null;
182172

src/main/java/com/adsk/jira/ldapgroupsync/plugin/api/LdapGroupSyncAOMgr.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
*/
1616
public interface LdapGroupSyncAOMgr {
1717
public ActiveObjects getActiveObjects();
18-
public List<LdapGroupSyncMapBean> getAllGroupsMapProperties();
19-
public List<LdapGroupSyncMapBean> getSupportedGroupsMapProperties();
18+
public List<LdapGroupSyncMapBean> getGroupsMapProperties();
2019
public LdapGroupSyncMapBean getGroupsMapProperty(long configId);
2120
public void addGroupsMapProperty(LdapGroupSyncMapBean configBean);
2221
public void setGroupsMapProperty(LdapGroupSyncMapBean configBean);
2322
public boolean findGroupsMapProperty(LdapGroupSyncMapBean configBean);
2423
public boolean findGroupsMapProperty2(LdapGroupSyncMapBean configBean);
25-
public boolean isJiraGroupNotInSupport(String jiraGroup);
2624
public void removeGroupsMapProperty(long configId);
2725
}

src/main/java/com/adsk/jira/ldapgroupsync/plugin/api/LdapGroupSyncAOMgrImpl.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,9 @@ private LdapGroupSyncAOMgrImpl(ActiveObjects ao) {
2626

2727
public ActiveObjects getActiveObjects() {
2828
return this.ao;
29-
}
30-
31-
public List<LdapGroupSyncMapBean> getSupportedGroupsMapProperties() {
32-
final LdapGroupSyncMap[] maps = getActiveObjects()
33-
.find(LdapGroupSyncMap.class, Query.select().where("SUPPORT = ?", true));
34-
List<LdapGroupSyncMapBean> configList = new ArrayList<LdapGroupSyncMapBean>();
35-
for(LdapGroupSyncMap map : maps){
36-
LdapGroupSyncMapBean bean = new LdapGroupSyncMapBean();
37-
bean.setConfigId(map.getID());
38-
bean.setLdapGroup(map.getLdapGroup());
39-
bean.setJiraGroup(map.getJiraGroup());
40-
bean.setSupport(map.getSupport());
41-
configList.add(bean);
42-
}
43-
return configList;
44-
}
29+
}
4530

46-
public List<LdapGroupSyncMapBean> getAllGroupsMapProperties() {
31+
public List<LdapGroupSyncMapBean> getGroupsMapProperties() {
4732
final LdapGroupSyncMap[] maps = getActiveObjects()
4833
.find(LdapGroupSyncMap.class, Query.select());
4934
List<LdapGroupSyncMapBean> configList = new ArrayList<LdapGroupSyncMapBean>();
@@ -52,7 +37,6 @@ public List<LdapGroupSyncMapBean> getAllGroupsMapProperties() {
5237
bean.setConfigId(map.getID());
5338
bean.setLdapGroup(map.getLdapGroup());
5439
bean.setJiraGroup(map.getJiraGroup());
55-
bean.setSupport(map.getSupport());
5640
configList.add(bean);
5741
}
5842
return configList;
@@ -62,7 +46,6 @@ public void addGroupsMapProperty(LdapGroupSyncMapBean configBean) {
6246
final LdapGroupSyncMap map = ao.create(LdapGroupSyncMap.class);
6347
map.setLdapGroup(configBean.getLdapGroup());
6448
map.setJiraGroup(configBean.getJiraGroup());
65-
map.setSupport(configBean.isSupport());
6649
map.save();
6750
}
6851

@@ -73,7 +56,6 @@ public void setGroupsMapProperty(LdapGroupSyncMapBean configBean) {
7356
final LdapGroupSyncMap map = maps[0];
7457
map.setLdapGroup(configBean.getLdapGroup());
7558
map.setJiraGroup(configBean.getJiraGroup());
76-
map.setSupport(configBean.isSupport());
7759
map.save();
7860
}
7961
}
@@ -100,12 +82,6 @@ public void removeGroupsMapProperty(long configId) {
10082
ao.delete(map);
10183
}
10284
}
103-
104-
public boolean isJiraGroupNotInSupport(String jiraGroup) {
105-
final LdapGroupSyncMap[] maps = ao.find(LdapGroupSyncMap.class, Query.select()
106-
.where("JIRA_GROUP = ? AND SUPPORT = ?", jiraGroup, false));
107-
return maps.length > 0;
108-
}
10985

11086
public LdapGroupSyncMapBean getGroupsMapProperty(long configId) {
11187
final LdapGroupSyncMap[] maps = ao.find(LdapGroupSyncMap.class, Query.select().where("ID = ?", configId));
@@ -115,7 +91,6 @@ public LdapGroupSyncMapBean getGroupsMapProperty(long configId) {
11591
bean.setConfigId(map.getID());
11692
bean.setLdapGroup(map.getLdapGroup());
11793
bean.setJiraGroup(map.getJiraGroup());
118-
bean.setSupport(map.getSupport());
11994
return bean;
12095
}
12196
return null;

src/main/java/com/adsk/jira/ldapgroupsync/plugin/api/LdapGroupSyncMap.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@ public interface LdapGroupSyncMap extends Entity {
2424

2525
public void setJiraGroup(String jiraGroup);
2626

27-
public boolean getSupport();
28-
29-
public void setSupport(boolean support);
3027
}

src/main/java/com/adsk/jira/ldapgroupsync/plugin/model/LdapGroupSyncMapBean.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public class LdapGroupSyncMapBean {
1111
private String ldapGroup;
1212
@JsonProperty
1313
private String jiraGroup;
14-
@JsonProperty
15-
private boolean support;
1614

1715
public long getConfigId() {
1816
return configId;
@@ -37,14 +35,6 @@ public String getJiraGroup() {
3735
public void setJiraGroup(String jiraGroup) {
3836
this.jiraGroup = jiraGroup;
3937
}
40-
41-
public boolean isSupport() {
42-
return support;
43-
}
44-
45-
public void setSupport(boolean support) {
46-
this.support = support;
47-
}
4838

4939
public void clear() {
5040
this.ldapGroup = null;

0 commit comments

Comments
 (0)