Permalink
Browse files

Added mailman group membership tracking

  • Loading branch information...
codders committed Sep 17, 2009
1 parent 8eca421 commit afe414a8ce0a47e136ad5a3346f728adaeec7aec
@@ -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>
@@ -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;
}
@@ -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;
+ }
+
}
@@ -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;
}
}
Oops, something went wrong.

0 comments on commit afe414a

Please sign in to comment.