Skip to content
Browse files

Added mailman group membership tracking

  • Loading branch information...
1 parent 8eca421 commit afe414a8ce0a47e136ad5a3346f728adaeec7aec @codders committed
View
2 slingtests/osgikernel/bundles/mailman/pom.xml
@@ -37,7 +37,7 @@
<instructions>
<Bundle-Category> sakai-kernel </Bundle-Category>
<Private-Package> org.sakaiproject.kernel.mailman.* </Private-Package>
- <Import-Package>sun.io;resolution:=optional,*</Import-Package>
+ <Import-Package>sun.io;resolution:=optional,org.w3c.dom;resolution:=optional,*</Import-Package>
<Embed-Dependency>nekohtml,xercesImpl,xml-resolver,xml-apis</Embed-Dependency>
</instructions>
</configuration>
View
33 ...ikernel/bundles/mailman/src/main/java/org/sakaiproject/kernel/mailman/MailmanManager.java
@@ -1,18 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.sakaiproject.kernel.mailman;
-import org.apache.commons.httpclient.HttpException;
import org.sakaiproject.kernel.mailman.impl.MailmanException;
-import org.xml.sax.SAXException;
-import java.io.IOException;
import java.util.List;
public interface MailmanManager {
- public boolean isServerActive() throws HttpException, IOException, MailmanException, SAXException;
- public List<String> getLists() throws HttpException, IOException, MailmanException, SAXException;
- public void createList(String listName, String ownerEmail, String password) throws MailmanException, HttpException, IOException;
- public void deleteList(String listName, String listPassword) throws HttpException, IOException, MailmanException;
- public boolean listHasMember(String listName, String listPassword, String memberEmail) throws HttpException, IOException, MailmanException, SAXException;
- public boolean addMember(String listName, String listPassword, String userEmail) throws HttpException, IOException, MailmanException, SAXException;
- public boolean removeMember(String listName, String listPassword, String userEmail) throws HttpException, IOException, MailmanException, SAXException;
+ public boolean isServerActive() throws MailmanException;
+ public List<String> getLists() throws MailmanException;
+ public void createList(String listName, String ownerEmail, String password) throws MailmanException;
+ public void deleteList(String listName, String listPassword) throws MailmanException;
+ public boolean listHasMember(String listName, String listPassword, String memberEmail) throws MailmanException;
+ public boolean addMember(String listName, String listPassword, String userEmail) throws MailmanException;
+ public boolean removeMember(String listName, String listPassword, String userEmail) throws MailmanException;
}
View
26 .../bundles/mailman/src/main/java/org/sakaiproject/kernel/mailman/impl/MailmanException.java
@@ -1,11 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.sakaiproject.kernel.mailman.impl;
public class MailmanException extends Exception {
private static final long serialVersionUID = 1L;
+ private Throwable underlying;
+ public MailmanException(String string, Exception e) {
+ this(string);
+ underlying = e;
+ }
+
public MailmanException(String string) {
super(string);
}
+ public Throwable getUnderlying() {
+ return underlying;
+ }
+
}
View
83 ...ndles/mailman/src/main/java/org/sakaiproject/kernel/mailman/impl/MailmanGroupManager.java
@@ -1,17 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.sakaiproject.kernel.mailman.impl;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.sakaiproject.kernel.api.user.AuthorizableEvent;
+import org.sakaiproject.kernel.api.user.AuthorizableEvent.Operation;
import org.sakaiproject.kernel.mailman.MailmanManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Dictionary;
+import javax.jcr.RepositoryException;
+
/**
* @scr.component immediate="true" label="MailManagerImpl"
* description="Interface to mailman"
@@ -20,6 +41,8 @@
* @scr.property name="service.vendor" value="The Sakai Foundation"
* @scr.property name="event.topics" values.0="org/apache/sling/jackrabbit/usermanager/event/create"
* values.1="org/apache/sling/jackrabbit/usermanager/event/delete"
+ * values.2="org/apache/sling/jackrabbit/usermanager/event/join"
+ * values.3="org/apache/sling/jackrabbit/usermanager/event/part"
* @scr.service interface="org.osgi.service.event.EventHandler"
*/
public class MailmanGroupManager implements EventHandler, ManagedService {
@@ -36,17 +59,61 @@
public void handleEvent(Event event) {
LOGGER.info("Got event on topic: " + event.getTopic());
- if ((AuthorizableEvent.TOPIC + "create").equals(event.getTopic())) {
- String principalName = event.getProperty(AuthorizableEvent.PRINCIPAL_NAME).toString();
- LOGGER.info("Got authorizable creation: " + principalName);
- if (principalName.startsWith("g-")) {
- LOGGER.info("Got group creation. Creating mailman list");
+ Operation operation = (Operation) event.getProperty(AuthorizableEvent.OPERATION);
+ String principalName = event.getProperty(AuthorizableEvent.PRINCIPAL_NAME).toString();
+ switch (operation) {
+ case create:
+ LOGGER.info("Got authorizable creation: " + principalName);
+ if (principalName.startsWith("g-")) {
+ LOGGER.info("Got group creation. Creating mailman list");
+ try {
+ mailmanManager.createList(principalName, principalName + "@example.com", listManagementPassword);
+ } catch (Exception e) {
+ LOGGER.error("Unable to create mailman list for group", e);
+ }
+ }
+ break;
+ case delete:
+ LOGGER.info("Got authorizable deletion: " + principalName);
+ if (principalName.startsWith("g-")) {
+ LOGGER.info("Got group deletion. Deleting mailman list");
+ try {
+ mailmanManager.deleteList(principalName, listManagementPassword);
+ } catch (Exception e) {
+ LOGGER.error("Unable to delete mailman list for group", e);
+ }
+ }
+ break;
+ case join:
+ {
+ LOGGER.info("Got group join event");
+ Group group = (Group)event.getProperty(AuthorizableEvent.GROUP);
+ User user = (User)event.getProperty(AuthorizableEvent.USER);
+ try {
+ LOGGER.info("Adding " + user.getID() + " to mailman group " + group.getID());
+ mailmanManager.addMember(group.getID(), listManagementPassword, user.getID() + "@example.com");
+ } catch (RepositoryException e) {
+ LOGGER.error("Repository exception adding user to mailman group", e);
+ } catch (MailmanException e) {
+ LOGGER.error("Mailman exception adding user to mailman group", e);
+ }
+ }
+ break;
+ case part:
+ {
+ LOGGER.info("Got group join event");
+ Group group = (Group)event.getProperty(AuthorizableEvent.GROUP);
+ User user = (User)event.getProperty(AuthorizableEvent.USER);
try {
- mailmanManager.createList(principalName, principalName + "@example.com", listManagementPassword);
- } catch (Exception e) {
- LOGGER.error("Unable to create mailman list for group", e);
+ LOGGER.info("Adding " + user.getID() + " to mailman group " + group.getID());
+ mailmanManager.removeMember(group.getID(), listManagementPassword, user.getID() + "@example.com");
+ } catch (RepositoryException e) {
+ LOGGER.error("Repository exception removing user from mailman group", e);
+ } catch (MailmanException e) {
+ LOGGER.error("Mailman exception removing user from mailman group", e);
}
}
+ break;
}
}
View
85 ...undles/mailman/src/main/java/org/sakaiproject/kernel/mailman/impl/MailmanManagerImpl.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.sakaiproject.kernel.mailman.impl;
import com.google.common.collect.ImmutableMap;
@@ -65,7 +81,7 @@ private String getMailmanUrl(String stub) {
return "http://" + configMap.get(MAILMAN_HOST) + configMap.get(MAILMAN_PATH) + stub;
}
- public void createList(String listName, String ownerEmail, String password) throws MailmanException, HttpException, IOException {
+ public void createList(String listName, String ownerEmail, String password) throws MailmanException {
HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
PostMethod post = new PostMethod(getMailmanUrl("/create"));
NameValuePair[] parametersBody = new NameValuePair[] {
@@ -81,17 +97,21 @@ public void createList(String listName, String ownerEmail, String password) thro
new NameValuePair("doit", "Create List")
};
post.setRequestBody(parametersBody);
- int result = client.executeMethod(post);
try {
+ int result = client.executeMethod(post);
if (result != HttpServletResponse.SC_OK) {
throw new MailmanException("Unable to create list");
}
+ } catch (HttpException e) {
+ throw new MailmanException("HTTP Exception communicating with mailman server", e);
+ } catch (IOException e) {
+ throw new MailmanException("IOException communicating with mailman server", e);
} finally {
post.releaseConnection();
}
}
- public void deleteList(String listName, String listPassword) throws HttpException, IOException, MailmanException {
+ public void deleteList(String listName, String listPassword) throws MailmanException {
HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
PostMethod post = new PostMethod(getMailmanUrl("/rmlist/" + listName));
NameValuePair[] parametersBody = new NameValuePair[] {
@@ -100,17 +120,21 @@ public void deleteList(String listName, String listPassword) throws HttpExceptio
new NameValuePair("doit", "Delete this list")
};
post.setRequestBody(parametersBody);
- int result = client.executeMethod(post);
try {
+ int result = client.executeMethod(post);
if (result != HttpServletResponse.SC_OK) {
throw new MailmanException("Unable to create list");
}
+ } catch (HttpException e) {
+ throw new MailmanException("HTTP Exception communicating with mailman server", e);
+ } catch (IOException e) {
+ throw new MailmanException("IOException communicating with mailman server", e);
} finally {
post.releaseConnection();
}
}
- public boolean listHasMember(String listName, String listPassword, String memberEmail) throws HttpException, IOException, MailmanException, SAXException {
+ public boolean listHasMember(String listName, String listPassword, String memberEmail) throws MailmanException {
HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "members"));
NameValuePair[] parameters = new NameValuePair[] {
@@ -119,8 +143,8 @@ public boolean listHasMember(String listName, String listPassword, String member
new NameValuePair("adminpw", listPassword)
};
get.setQueryString(parameters);
- int result = client.executeMethod(get);
try {
+ int result = client.executeMethod(get);
if (result != HttpServletResponse.SC_OK) {
throw new MailmanException("Unable to search for member");
}
@@ -136,15 +160,21 @@ public boolean listHasMember(String listName, String listPassword, String member
} catch (NullPointerException npe) {
}
}
+ } catch (SAXException e) {
+ throw new MailmanException("Error parsing mailman response", e);
+ } catch (HttpException e) {
+ throw new MailmanException("HTTP Exception communicating with mailman server", e);
+ } catch (IOException e) {
+ throw new MailmanException("IOException communicating with mailman server", e);
} finally {
get.releaseConnection();
}
return false;
}
- public boolean addMember(String listName, String listPassword, String memberEmail) throws HttpException, IOException, MailmanException, SAXException {
+ public boolean addMember(String listName, String listPassword, String memberEmail) throws MailmanException {
HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
- GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "members/add"));
+ GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "/members/add"));
NameValuePair[] parameters = new NameValuePair[] {
new NameValuePair("subscribe_or_invite", "0"),
new NameValuePair("send_welcome_msg_to_this_batch", "0"),
@@ -153,8 +183,8 @@ public boolean addMember(String listName, String listPassword, String memberEmai
new NameValuePair("adminpw", listPassword)
};
get.setQueryString(parameters);
- int result = client.executeMethod(get);
try {
+ int result = client.executeMethod(get);
if (result != HttpServletResponse.SC_OK) {
throw new MailmanException("Unable to add member");
}
@@ -164,14 +194,20 @@ public boolean addMember(String listName, String listPassword, String memberEmai
throw new MailmanException("Unable to read result status");
}
return "Successfully subscribed:".equals(inputs.item(0).getTextContent());
+ } catch (SAXException e) {
+ throw new MailmanException("Error parsing mailman response", e);
+ } catch (HttpException e) {
+ throw new MailmanException("HTTP Exception communicating with mailman server", e);
+ } catch (IOException e) {
+ throw new MailmanException("IOException communicating with mailman server", e);
} finally {
get.releaseConnection();
}
}
- public boolean removeMember(String listName, String listPassword, String memberEmail) throws HttpException, IOException, MailmanException, SAXException {
+ public boolean removeMember(String listName, String listPassword, String memberEmail) throws MailmanException {
HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
- GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "members/remove"));
+ GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "/members/remove"));
NameValuePair[] parameters = new NameValuePair[] {
new NameValuePair("send_unsub_ack_to_this_batch", "0"),
new NameValuePair("send_unsub_notifications_to_list_owner", "0"),
@@ -179,8 +215,8 @@ public boolean removeMember(String listName, String listPassword, String memberE
new NameValuePair("adminpw", listPassword)
};
get.setQueryString(parameters);
- int result = client.executeMethod(get);
try {
+ int result = client.executeMethod(get);
if (result != HttpServletResponse.SC_OK) {
throw new MailmanException("Unable to add member");
}
@@ -193,6 +229,12 @@ public boolean removeMember(String listName, String listPassword, String memberE
}
}
return "Successfully Unsubscribed:".equals(inputs.item(0).getTextContent());
+ } catch (HttpException e) {
+ throw new MailmanException("HTTP Exception communicating with mailman server", e);
+ } catch (IOException e) {
+ throw new MailmanException("IOException communicating with mailman server", e);
+ } catch (SAXException e) {
+ throw new MailmanException("Error parsing mailman response", e);
} finally {
get.releaseConnection();
}
@@ -204,12 +246,12 @@ private Document parseHtml(HttpMethodBase method) throws SAXException, IOExcepti
return parser.getDocument();
}
- public List<String> getLists() throws HttpException, IOException, MailmanException, SAXException {
+ public List<String> getLists() throws MailmanException {
HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
GetMethod get = new GetMethod(getMailmanUrl("/admin"));
List<String> lists = new ArrayList<String>();
- int result = client.executeMethod(get);
try {
+ int result = client.executeMethod(get);
if (result != HttpServletResponse.SC_OK) {
LOGGER.warn("Got " + result + " from http request");
throw new MailmanException("Unable to list mailinglists");
@@ -226,6 +268,12 @@ private Document parseHtml(HttpMethodBase method) throws SAXException, IOExcepti
for (int i=4; i<rows.getLength(); i++) {
lists.add(parseListNameFromRow((HTMLTableRowElement)rows.item(i)));
}
+ } catch (SAXException e) {
+ throw new MailmanException("Error parsing mailman response", e);
+ } catch (HttpException e) {
+ throw new MailmanException("HTTP Exception communicating with mailman server", e);
+ } catch (IOException e) {
+ throw new MailmanException("IOException communicating with mailman server", e);
} finally {
get.releaseConnection();
}
@@ -262,17 +310,20 @@ void setProxyClientService(ProxyClientService proxyClientService) {
this.proxyClientService = proxyClientService;
}
- public boolean isServerActive() throws HttpException, IOException, MailmanException,
- SAXException {
+ public boolean isServerActive() throws MailmanException {
HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
GetMethod get = new GetMethod(getMailmanUrl("/admin"));
- int result = client.executeMethod(get);
try {
+ int result = client.executeMethod(get);
if (result != HttpServletResponse.SC_OK) {
LOGGER.warn("Got " + result + " from http request");
return false;
}
return true;
+ } catch (HttpException e) {
+ throw new MailmanException("HTTP Exception communicating with mailman server", e);
+ } catch (IOException e) {
+ throw new MailmanException("IOException communicating with mailman server", e);
} finally {
get.releaseConnection();
}
View
17 ...undles/personal/src/main/java/org/sakaiproject/kernel/personal/UserPostProcessorImpl.java
@@ -39,6 +39,7 @@
import org.sakaiproject.kernel.api.personal.PersonalUtils;
import org.sakaiproject.kernel.api.user.AuthorizableEventUtil;
import org.sakaiproject.kernel.api.user.UserConstants;
+import org.sakaiproject.kernel.api.user.UserModification;
import org.sakaiproject.kernel.api.user.UserPostProcessor;
import org.sakaiproject.kernel.api.user.AuthorizableEvent.Operation;
import org.sakaiproject.kernel.util.JcrUtils;
@@ -297,7 +298,21 @@ private void fireEvent(SlingHttpServletRequest request, String principalName,
if (path == null) {
path = m.getSource();
}
- if (path.endsWith(principalName)) {
+ if (m instanceof UserModification) {
+ LOGGER.info("Got user modification: " + m);
+ UserModification um = (UserModification) m;
+ switch (um.getType()) {
+ case COPY:
+ case CREATE:
+ case DELETE:
+ case MOVE:
+ LOGGER.debug("Ignoring unknown modification type: " + um.getType());
+ break;
+ case MODIFY:
+ eventAdmin.postEvent(AuthorizableEventUtil.newGroupEvent(um));
+ break;
+ }
+ } else if (path.endsWith(principalName)) {
switch (m.getType()) {
case COPY:
eventAdmin.postEvent(AuthorizableEventUtil.newAuthorizableEvent(
View
5 ...kernel/bundles/user/src/main/java/org/sakaiproject/kernel/api/user/AuthorizableEvent.java
@@ -41,13 +41,14 @@
public static final String MODIFICATION = "change";
public static final String USER = "user";
-
+
+ public static final String GROUP = "group";
/**
* Operations
*/
public static enum Operation {
- delete(), update(), create();
+ delete(), update(), create(), join(), part();
public String getTopic() {
return TOPIC+toString();
View
9 ...el/bundles/user/src/main/java/org/sakaiproject/kernel/api/user/AuthorizableEventUtil.java
@@ -58,5 +58,14 @@ public static Event newAuthorizableEvent(
return new Event(operation.getTopic(), eventDictionary);
}
+ public static Event newGroupEvent(UserModification um) throws RepositoryException {
+ Dictionary<String, Object> eventDictionary = new Hashtable<String, Object>();
+ Operation operation = (um.isJoin() ? Operation.join : Operation.part);
+ eventDictionary.put(AuthorizableEvent.OPERATION, operation);
+ eventDictionary.put(AuthorizableEvent.PRINCIPAL_NAME, um.getGroup().getID());
+ eventDictionary.put(AuthorizableEvent.USER, um.getUser());
+ eventDictionary.put(AuthorizableEvent.GROUP, um.getGroup());
+ return new Event(operation.getTopic(), eventDictionary);
+ }
}
View
72 ...ikernel/bundles/user/src/main/java/org/sakaiproject/kernel/api/user/UserModification.java
@@ -0,0 +1,72 @@
+package org.sakaiproject.kernel.api.user;
+
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.sling.servlets.post.Modification;
+import org.apache.sling.servlets.post.ModificationType;
+
+import javax.jcr.RepositoryException;
+
+public class UserModification extends Modification {
+
+ private Group group;
+ private User user;
+ private boolean isJoin;
+
+ public UserModification(ModificationType type, String source, String destination) {
+ super(type, source, destination);
+ }
+
+ /**
+ * Records a 'modified' change
+ *
+ * @param path path of the item that was modified
+ */
+ public static Modification onGroupJoin(String path, Group group, User user) {
+ UserModification result = new UserModification(ModificationType.MODIFY, path, null);
+ result.setGroup(group);
+ result.setUser(user);
+ result.setJoin(true);
+ return result;
+ }
+
+ public static Modification onGroupLeave(String path, Group group, User user) {
+ UserModification result = new UserModification(ModificationType.MODIFY, path, null);
+ result.setGroup(group);
+ result.setUser(user);
+ result.setJoin(false);
+ return result;
+ }
+
+ private void setJoin(boolean isJoin) {
+ this.isJoin = isJoin;
+ }
+
+ private void setUser(User user) {
+ this.user = user;
+ }
+
+ private void setGroup(Group group) {
+ this.group = group;
+ }
+
+ public Group getGroup() {
+ return group;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public boolean isJoin() {
+ return isJoin;
+ }
+
+ public String toString() {
+ try {
+ return "User " + user.getID() + " " + (isJoin ? "" : "un") + "joins group " + group.getID();
+ } catch (RepositoryException e) {
+ }
+ return "User " + user + " " + (isJoin ? "" : "un") + "joins group " + group;
+ }
+}
View
29 ...ser/src/main/java/org/sakaiproject/kernel/user/servlet/AbstractSakaiGroupPostServlet.java
@@ -16,17 +16,9 @@
*/
package org.sakaiproject.kernel.user.servlet;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
@@ -37,10 +29,21 @@
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.SlingPostConstants;
import org.sakaiproject.kernel.api.user.UserConstants;
+import org.sakaiproject.kernel.api.user.UserModification;
import org.sakaiproject.kernel.util.PathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
/**
* Base class for servlets manipulating groups
*/
@@ -75,6 +78,7 @@ protected void updateGroupMembership(Session session, SlingHttpServletRequest re
int addIndex = 0;
int removeIndex = 0;
+ List<Modification> userChanges = new ArrayList<Modification>();
String[] membersToDelete = request.getParameterValues(SlingPostConstants.RP_PREFIX
+ "member" + SlingPostConstants.SUFFIX_DELETE);
@@ -85,6 +89,8 @@ protected void updateGroupMembership(Session session, SlingHttpServletRequest re
if (membersToDelete != null) {
for (removeIndex=0; removeIndex<membersToDelete.length; removeIndex++) {
if (removeMember(group, membersToDelete[removeIndex], baseResource, userManager, resolver)) {
+ String[] usernameParts = membersToDelete[removeIndex].split("\\/");
+ userChanges.add(UserModification.onGroupLeave(groupPath + "/members", group, (User)userManager.getAuthorizable(usernameParts[usernameParts.length - 1])));
changed = true;
}
}
@@ -94,10 +100,15 @@ protected void updateGroupMembership(Session session, SlingHttpServletRequest re
if (membersToAdd != null) {
for (addIndex=0; addIndex<membersToAdd.length; addIndex++) {
if (addMember(group, membersToAdd[addIndex], baseResource, userManager, resolver)) {
+ String[] usernameParts = membersToAdd[addIndex].split("\\/");
+ userChanges.add(UserModification.onGroupJoin(groupPath + "/members", group, (User)userManager.getAuthorizable(usernameParts[usernameParts.length - 1])));
changed = true;
}
}
}
+
+ changes.addAll(userChanges);
+
} catch (RepositoryException re) {
LOGGER.debug("Group membership modification failed, rolling back");
for (int unaddIndex = addIndex - 1; unaddIndex >= 0; unaddIndex--) {

0 comments on commit afe414a

Please sign in to comment.
Something went wrong with that request. Please try again.