Wikitty-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 1653 discussions
Author: bpoussin
Date: 2010-10-14 17:45:33 +0200 (Thu, 14 Oct 2010)
New Revision: 406
Url: http://nuiton.org/repositories/revision/wikitty/406
Log:
ajout de la dependance xstream pour la serialisation xml des events
Modified:
trunk/pom.xml
trunk/wikitty-api/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-14 15:21:42 UTC (rev 405)
+++ trunk/pom.xml 2010-10-14 15:45:33 UTC (rev 406)
@@ -178,6 +178,13 @@
<scope>compile</scope>
</dependency>
+ <!-- for event serialization -->
+ <dependency>
+ <groupId>xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.2.2</version>
+ </dependency>
+
<!-- Cache -->
<dependency>
<groupId>org.jgroups</groupId>
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2010-10-14 15:21:42 UTC (rev 405)
+++ trunk/wikitty-api/pom.xml 2010-10-14 15:45:33 UTC (rev 406)
@@ -92,6 +92,12 @@
<artifactId>jta</artifactId>
</dependency>
+ <!-- for event serialization -->
+ <dependency>
+ <groupId>xstream</groupId>
+ <artifactId>xstream</artifactId>
+ </dependency>
+
<!-- Cache -->
<dependency>
<groupId>org.jgroups</groupId>
1
0
r405 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty test/java/org/nuiton/wikitty test/java/org/nuiton/wikitty/notification
by bpoussin@users.nuiton.org 14 Oct '10
by bpoussin@users.nuiton.org 14 Oct '10
14 Oct '10
Author: bpoussin
Date: 2010-10-14 17:21:42 +0200 (Thu, 14 Oct 2010)
New Revision: 405
Url: http://nuiton.org/repositories/revision/wikitty/405
Log:
Implantation du transporteur sur xmpp devrait fonctionner (a tester sur vradi)
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-13 14:39:33 UTC (rev 404)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-14 15:21:42 UTC (rev 405)
@@ -18,6 +18,8 @@
package org.nuiton.wikitty;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import java.util.EventObject;
import java.util.Map;
import java.util.Set;
@@ -101,6 +103,14 @@
this.source = source;
}
+ public WikittyEventType getType() {
+ return type;
+ }
+
+ public void setType(WikittyEventType type) {
+ this.type = type;
+ }
+
/**
* Is event remote.
*
@@ -176,8 +186,34 @@
@Override
public String toString() {
String toString = getClass().getName() + "[source=" + source +
+ ", type=" + type +
", remote=" + remote + ", ids=" + ids + ", idExtensions=" + idExtensions +
", idVersions=" + idVersions + "]";
return toString;
}
+
+ /**
+ * Permet de serializer en XML l'event. Pourrait etre utilise pour l'envoi
+ * sur un transporteur qui ne peremt pas la serialisation java
+ * @return
+ */
+ public String toXML() {
+ XStream xstream = new XStream();
+ xstream.setMode(XStream.NO_REFERENCES);
+ xstream.alias("event", WikittyServiceEvent.class);
+ String result = xstream.toXML(this);
+ return result;
+ }
+
+ /**
+ * Inverse de la methode toXML
+ * @param xml
+ * @return
+ */
+ static public WikittyServiceEvent fromXML(String xml) {
+ XStream xstream = new XStream();
+ xstream.alias("event", WikittyServiceEvent.class);
+ WikittyServiceEvent result = (WikittyServiceEvent)xstream.fromXML(xml);
+ return result;
+ }
}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 2010-10-14 15:21:42 UTC (rev 405)
@@ -0,0 +1,235 @@
+/* *##%
+ * Copyright (c) 2010 Code Lutin, Benjamin Poussin. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *##%*/
+
+package org.nuiton.wikitty;
+
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.UUID;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smackx.muc.DiscussionHistory;
+import org.jivesoftware.smackx.muc.MultiUserChat;
+import org.nuiton.util.ApplicationConfig;
+
+/**
+ * Transporter d'event via xmpp. Pour que ca fonctionne il faut un serveur
+ * xmpp avec une room
+ * <p>
+ * Configuration
+ * <li>wikitty.xmpp.server = adresse du serveur (ex: im.codelutin.com)
+ * <li>wikitty.xmpp.room = adresse de la room (ex: wikitty-event(a)im.codelutin.com)
+ * <li>wikitty.notification.persistent = [true|false] indique si on doit
+ * recevoir tous les messages sans en loupe un seul. Pour cela il faut que la
+ * room soit archivee. (FIXME poussin 20101014 pas encore implantee)
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class XMPPNotifierTransporter implements PacketListener,
+ WikittyServiceNotifier.RemoteNotifierTransporter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(XMPPNotifierTransporter.class);
+
+ static final public String PROPERTY_EVENT_NAME = "wikitty-event";
+ static final public String WIKITTY_XMPP_SERVER = "wikitty.xmpp.server";
+ static final public String WIKITTY_XMPP_ROOM = "wikitty.xmpp.room";
+ static final public String WIKITTY_NOTIFICATION_PERSISTENT =
+ "wikitty.notification.persistent";
+
+ /** Notifier service reference reference. */
+ protected WikittyServiceNotifier ws;
+
+ /** if persistent is true use Chat otherwize use MUC. Chat permit to
+ received event missed after deconnection */
+ protected boolean persistent = false;
+
+ protected XMPPConnection connection;
+ protected MultiUserChat muc;
+
+ /**
+ *
+ * @param ws
+ */
+ public XMPPNotifierTransporter(WikittyServiceNotifier ws, Properties props) {
+ this.ws = ws;
+ initXMPP(props);
+ }
+
+ /**
+ * Si persistent est vrai alors il faut toujours utilise le meme user id
+ *
+ * @param props
+ */
+ protected void initXMPP(Properties props) {
+ ApplicationConfig config = new ApplicationConfig(props);
+
+ persistent = config.getOptionAsBoolean(WIKITTY_NOTIFICATION_PERSISTENT);
+ String server = config.getOption(WIKITTY_XMPP_SERVER);
+ String room = config.getOption(WIKITTY_XMPP_ROOM);
+
+ String pseudo = getUniqueLoginName();
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Try to connect to xmpp serveur " + server +
+ " with pseudo " + pseudo + " in room " + room +
+ " persistent " + persistent);
+ }
+ connection = new XMPPConnection(server);
+ connection.connect();
+ connection.loginAnonymously();
+
+ DiscussionHistory history = new DiscussionHistory();
+ if (persistent) {
+ // FIXME poussin 20101113 compute amount of log history to retrieve
+ // MUC must be archived
+ Date date = new Date();
+ history.setSince(date);
+ } else {
+ history.setMaxChars(0);
+ }
+
+ // connection to the volatile room
+ muc = new MultiUserChat(connection, room);
+ muc.join(pseudo, "", history, 4000);
+ muc.addMessageListener(this);
+ } catch (Exception eee) {
+ throw new WikittyException("Can't connect to xmpp serveur", eee);
+ }
+ }
+
+ @Override
+ public void sendMessage(WikittyServiceEvent event) throws Exception {
+ Message message = muc.createMessage();
+ message.setBody(event.getType().toString());
+ message.setProperty(PROPERTY_EVENT_NAME, event);
+
+ muc.sendMessage(message);
+ }
+
+ /**
+ * used for MUC message
+ * @param packet
+ */
+ @Override
+ public void processPacket(Packet packet) {
+ Object event = packet.getProperty(PROPERTY_EVENT_NAME);
+
+ if (log.isInfoEnabled()) {
+ log.info("Receive message : " + event);
+ }
+
+ if (event instanceof WikittyServiceEvent) {
+ processEvent((WikittyServiceEvent)event);
+ }
+ }
+
+ /**
+ * Process event
+ */
+ protected void processEvent(WikittyServiceEvent event) {
+ //source is transient, add it here :
+ event.setSource(ws);
+ event.setRemote(true); // received event became remote
+
+ switch (event.getType()) {
+ case PUT_WIKITTY:
+ ws.firePutWikitty(event);
+ break;
+ case REMOVE_WIKITTY:
+ ws.fireRemoveWikitty(event);
+ break;
+ case CLEAR_WIKITTY:
+ ws.fireClearWikitty(event);
+ break;
+ case PUT_EXTENSION:
+ ws.firePutExtension(event);
+ break;
+ case REMOVE_EXTENSION:
+ ws.fireRemoveExtension(event);
+ break;
+ case CLEAR_EXTENSION:
+ ws.fireClearExtension(event);
+ break;
+ default:
+ if (log.isDebugEnabled()) {
+ log.debug("Not managed xmpp message " + event.type);
+ }
+ }
+ }
+
+ /**
+ * Recherche le meilleur nom a utiliser comme pseudo pour cette machine.
+ * Un UUID est toujours ajouter en debut, pour potentiellement lancer
+ * plusieurs application en meme temps sur la meme machine et etre sur que
+ * le pseudo soit bien unique.
+ *
+ * Le pseudo, n'est pas seulement un UUID, pour pouvoir facilement faire
+ * du debug en entrant dans le channel et voir les ip des machiens connectees
+ *
+ * @return
+ */
+ static public String getUniqueLoginName() {
+ String result = UUID.randomUUID().toString();
+ try {
+ String ipv4 = null;
+ String ipv6 = null;
+ for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
+ NetworkInterface netint = e.nextElement();
+
+ for (Enumeration<InetAddress> a = netint.getInetAddresses(); a.hasMoreElements();) {
+ InetAddress ip = a.nextElement();
+ if (ip instanceof Inet4Address) {
+ if ((ipv4 == null || "127.0.0.1".equals(ipv4))) {
+ ipv4 = ip.getHostAddress();
+ }
+ } else if (ip instanceof Inet6Address) {
+ if (ipv6 == null) {
+ ipv6 = ip.getHostAddress();
+ }
+ } else {
+ log.error("Can't get ip from no ipv4 and no ipv6: " + ip);
+ }
+ }
+ }
+
+ if (ipv4 != null) {
+ result = ipv4 + "=" + result;
+ } else if (ipv6 != null) {
+ result = ipv6 + "=" + result;
+ }
+ } catch (Exception eee) {
+ log.error("Can't compute unique name from network interface", eee);
+ }
+ return result;
+ }
+
+}
Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java 2010-10-14 15:21:42 UTC (rev 405)
@@ -0,0 +1,105 @@
+/* *##%
+ * Copyright (c) 2010 poussin. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *##%*/
+
+package org.nuiton.wikitty.notification;
+
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smackx.muc.DiscussionHistory;
+import org.jivesoftware.smackx.muc.MultiUserChat;
+import org.jivesoftware.smackx.muc.RoomInfo;
+import org.junit.Test;
+import org.nuiton.wikitty.WikittyServiceEvent;
+import org.nuiton.wikitty.XMPPNotifierTransporter;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class XMPPNotificationTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(XMPPNotificationTest.class);
+
+ @Test
+ public void testXMPP() throws Exception {
+ String server = "im.codelutin.com";
+ String room = "test(a)conference.im.codelutin.com";
+ Properties props = new Properties();
+ props.setProperty(XMPPNotifierTransporter.WIKITTY_XMPP_SERVER, server);
+ props.setProperty(XMPPNotifierTransporter.WIKITTY_XMPP_ROOM, room);
+
+ // Envoi d'un message avec le transporter normal
+
+ XMPPNotifierTransporter xmpp = new XMPPNotifierTransporter(null, props);
+ WikittyServiceEvent event = new WikittyServiceEvent("test",
+ WikittyServiceEvent.WikittyEventType.PUT_WIKITTY);
+ Set<String> ids = new HashSet<String>();
+ ids.add("id1");
+ ids.add("id2");
+ ids.add("id3");
+ event.setIds(ids);
+ xmpp.sendMessage(event);
+
+
+ // essaie de recuperation du message
+
+ XMPPConnection connection = new XMPPConnection(server);
+ connection.connect();
+ connection.loginAnonymously();
+
+ MultiUserChat muc = new MultiUserChat(connection, room);
+ String pseudo = XMPPNotifierTransporter.getUniqueLoginName();
+ System.out.println("pseudo: " + pseudo);
+
+ DiscussionHistory history = new DiscussionHistory();
+ history.setMaxStanzas(1);
+ muc.join(pseudo, "", history, 4000);
+
+ muc.addMessageListener(new PacketListener() {
+
+ @Override
+ public void processPacket(Packet packet) {
+ System.out.println("ext: " + packet.getExtensions());
+ System.out.println("prop: " + packet.getPropertyNames());
+ Object event = packet.getProperty(XMPPNotifierTransporter.PROPERTY_EVENT_NAME);
+ System.out.println("event " + event + " PACKET: " +
+ " xml: " + packet.toXML());
+ }
+ });
+
+ // Discover information about the room roomName(a)conference.myserver
+ RoomInfo info = MultiUserChat.getRoomInfo(connection, room);
+ System.out.println("Number of occupants:" + info.getOccupantsCount());
+ System.out.println("Room Subject:" + info.getSubject());
+
+// Thread t = new Thread();
+// t.sleep(1000*60);
+ }
+
+}
1
0
Author: bpoussin
Date: 2010-10-13 16:39:33 +0200 (Wed, 13 Oct 2010)
New Revision: 404
Url: http://nuiton.org/repositories/revision/wikitty/404
Log:
suppression de tous les compiler-plugin
Modified:
trunk/pom.xml
trunk/wikitty-api/pom.xml
trunk/wikitty-ui-gwt/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-13 14:08:43 UTC (rev 403)
+++ trunk/pom.xml 2010-10-13 14:39:33 UTC (rev 404)
@@ -496,17 +496,7 @@
</plugin>
</plugins>
</pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- </plugins>
+
</build>
<profiles>
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2010-10-13 14:08:43 UTC (rev 403)
+++ trunk/wikitty-api/pom.xml 2010-10-13 14:39:33 UTC (rev 404)
@@ -186,15 +186,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
</plugins>
</build>
Modified: trunk/wikitty-ui-gwt/pom.xml
===================================================================
--- trunk/wikitty-ui-gwt/pom.xml 2010-10-13 14:08:43 UTC (rev 403)
+++ trunk/wikitty-ui-gwt/pom.xml 2010-10-13 14:39:33 UTC (rev 404)
@@ -86,16 +86,6 @@
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <optimize>true</optimize>
- </configuration>
- </plugin>
-
- <plugin>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
1
0
r401 - trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory
by bpoussin@users.nuiton.org 13 Oct '10
by bpoussin@users.nuiton.org 13 Oct '10
13 Oct '10
Author: bpoussin
Date: 2010-10-13 16:04:01 +0200 (Wed, 13 Oct 2010)
New Revision: 401
Url: http://nuiton.org/repositories/revision/wikitty/401
Log:
hack pour permettre aux tests de passer avec le changement de tmp dir
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-13 14:03:30 UTC (rev 400)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-13 14:04:01 UTC (rev 401)
@@ -34,6 +34,12 @@
@Test
public void testFilePersistance() throws Exception {
+ // TODO poussin 20101113 hack to create tmp dir, this is necessary
+ // actually because new mavenpom move tmp dir to target without create it :(
+ File tmp = new File(System.getProperty("java.io.tmpdir"));
+ tmp.mkdirs();
+ // end of hack
+
File tempPersistFile = File.createTempFile(InMemoryStorageTest.class.getName(), ".tmp");
tempPersistFile.delete();
tempPersistFile.deleteOnExit();
2
1
r403 - in trunk/wikitty-api: . src/main/java/org/nuiton/wikitty
by bpoussin@users.nuiton.org 13 Oct '10
by bpoussin@users.nuiton.org 13 Oct '10
13 Oct '10
Author: bpoussin
Date: 2010-10-13 16:08:43 +0200 (Wed, 13 Oct 2010)
New Revision: 403
Url: http://nuiton.org/repositories/revision/wikitty/403
Log:
refactoring de event remote pour permettre l'implantation simple de nouveaux protocoles
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java
Removed:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java
Modified:
trunk/wikitty-api/pom.xml
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2010-10-13 14:05:31 UTC (rev 402)
+++ trunk/wikitty-api/pom.xml 2010-10-13 14:08:43 UTC (rev 403)
@@ -98,6 +98,11 @@
<artifactId>jgroups</artifactId>
</dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smackx</artifactId>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
@@ -181,7 +186,15 @@
</execution>
</executions>
</plugin>
-
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java 2010-10-13 14:05:31 UTC (rev 402)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java 2010-10-13 14:08:43 UTC (rev 403)
@@ -1,277 +0,0 @@
-/* *##%
- * Copyright (C) 2010 Code Lutin, Chatellier Eric
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *##%*/
-
-package org.nuiton.wikitty;
-
-import java.io.Serializable;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jgroups.Channel;
-import org.jgroups.ChannelClosedException;
-import org.jgroups.ChannelException;
-import org.jgroups.ChannelNotConnectedException;
-import org.jgroups.JChannel;
-import org.jgroups.Message;
-import org.jgroups.ReceiverAdapter;
-
-/**
- * JGroups notifier.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class JGroupsNotifier extends ReceiverAdapter implements WikittyServiceListener {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(JGroupsNotifier.class);
-
- /** Notifier service reference reference. */
- protected WikittyServiceNotifier ws;
-
- /** Message type (put, remove, clear...). */
- static enum WikittyJGroupType {
- PUT_WIKITTY,
- REMOVE_WIKITTY,
- CLEAR_WIKITTY,
- PUT_EXTENSION,
- REMOVE_EXTENSION,
- CLEAR_EXTENSION
- }
-
- static class WikittyJGroupMessage implements Serializable {
- /** serialVersionUID. */
- private static final long serialVersionUID = 1914969328584238081L;
-
- public WikittyJGroupType type;
- public WikittyServiceEvent event;
-
- private WikittyJGroupMessage(WikittyJGroupType type, WikittyServiceEvent event) {
- this.type = type;
- this.event = event;
- }
-
- public String toString() {
- String toString = type + " " + event;
- return toString;
- }
- }
-
- /**
- * Indique si les objects sont propages (true) vers les autres caches ou
- * simplement supprimes des autres caches (false).
- *
- * @see WikittyServiceCached#WIKITTY_PROPAGATE_CACHE_OPTION
- */
- protected boolean propagateCache = false;
-
- /** JGroup channel. */
- protected JChannel channel;
-
- public JGroupsNotifier(WikittyServiceNotifier ws, String channelName, boolean propagateCache) {
- this.ws = ws;
- this.propagateCache = propagateCache;
- initChannel(channelName);
- }
-
- /**
- * Init jgroup channel.
- *
- * @param channelName channel name
- */
- protected void initChannel(String channelName) {
- if (log.isDebugEnabled()) {
- log.debug("Init jgroup communication channel...");
- }
-
- try {
- // use default udp.xml in classpath
- channel = new JChannel();
- channel.setReceiver(this);
-
- // don't receive messages sent by myself
- channel.setOpt(Channel.LOCAL, false);
-
- channel.connect(channelName);
-
- if (log.isInfoEnabled()) {
- log.info("JGroup communication channel initialized to "
- + channel.getAddressAsString() + " ("
- + channel.getClusterName() + ")");
- log.info("Channel view: " + channel.getView());
- }
- } catch (ChannelException eee) {
- if (log.isErrorEnabled()) {
- log.error("Can't init jgroup channel", eee);
- }
- }
- }
-
- /**
- * Send a jgroup message to all other channel member.
- *
- * @param wikittyMessage message to send
- */
- protected void sendJGroupMessage(WikittyJGroupMessage wikittyMessage) {
- if (log.isInfoEnabled()) {
- log.info("Send message : " + wikittyMessage);
- }
-
- Message msg = new Message(null, null, wikittyMessage);
- try {
- channel.send(msg);
- } catch (ChannelNotConnectedException eee) {
- if (log.isErrorEnabled()) {
- log.error("Can't send jgroup message", eee);
- }
- } catch (ChannelClosedException eee) {
- if (log.isErrorEnabled()) {
- log.error("Can't send jgroup message", eee);
- }
- }
- }
-
- /*
- * @see org.jgroups.ReceiverAdapter#receive(org.jgroups.Message)
- */
- @Override
- public void receive(Message msg) {
-
- Object message = msg.getObject();
-
- if (log.isInfoEnabled()) {
- log.info("Receive message : " + msg.getObject());
- }
-
- if (message instanceof WikittyJGroupMessage) {
- WikittyJGroupMessage wikittyMessage = (WikittyJGroupMessage)message;
- WikittyJGroupType type = wikittyMessage.type;
- WikittyServiceEvent event = wikittyMessage.event;
-
- //source is transient, add it here :
- event.setSource(ws);
- event.setRemote(true); // received event became remote
-
- switch(type) {
- case PUT_WIKITTY:
- ws.firePutWikitty(event); break;
- case REMOVE_WIKITTY:
- ws.fireRemoveWikitty(event); break;
- case CLEAR_WIKITTY:
- ws.fireClearWikitty(event); break;
- case PUT_EXTENSION:
- ws.firePutExtension(event); break;
- case REMOVE_EXTENSION:
- ws.fireRemoveExtension(event); break;
- case CLEAR_EXTENSION:
- ws.fireClearExtension(event); break;
- default:
- if (log.isDebugEnabled()) {
- log.debug("Not managed jgroup message " + wikittyMessage.type);
- }
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[])
- */
- @Override
- public void putWikitty(WikittyServiceEvent event) {
- if (propagateCache) {
- sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.PUT_WIKITTY, event));
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate putWikitty event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[])
- */
- @Override
- public void removeWikitty(WikittyServiceEvent event) {
- if (propagateCache) {
- sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.REMOVE_WIKITTY, event));
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate removeWikitty event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty()
- */
- @Override
- public void clearWikitty(WikittyServiceEvent event) {
- if (propagateCache) {
- sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.CLEAR_WIKITTY, event));
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate clearWikitty event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[])
- */
- @Override
- public void putExtension(WikittyServiceEvent event) {
- if (propagateCache) {
- sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.PUT_EXTENSION, event));
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate putExtension event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#removeExtension(java.lang.String[])
- */
- @Override
- public void removeExtension(WikittyServiceEvent event) {
- if (propagateCache) {
- sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.REMOVE_EXTENSION, event));
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate removeExtension event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
- */
- @Override
- public void clearExtension(WikittyServiceEvent event) {
- if (propagateCache) {
- sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.CLEAR_EXTENSION, event));
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate clearExtension event");
- }
- }
- }
-}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java (from rev 398, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java 2010-10-13 14:08:43 UTC (rev 403)
@@ -0,0 +1,161 @@
+/* *##%
+ * Copyright (C) 2010 Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.nuiton.wikitty;
+
+import java.util.Properties;
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jgroups.Channel;
+import org.jgroups.ChannelException;
+import org.jgroups.JChannel;
+import org.jgroups.Message;
+import org.jgroups.ReceiverAdapter;
+
+/**
+ * JGroups notifier.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class JGroupsNotifierTransporter extends ReceiverAdapter
+ implements WikittyServiceNotifier.RemoteNotifierTransporter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(JGroupsNotifierTransporter.class);
+
+ /**
+ * Utilisation du canal de communication basé sur jgroups avec
+ * comme identifiant d'application le nom de canal en option.
+ *
+ * Si ce nom est vide, jgroups n'est pas utilisé.
+ * Si {@link #WIKITTY_EVENT_PROPAGATE_OPTION} est a true et que cette
+ * options est vide, une exception est levée.
+ */
+ static public final String WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION = "wikitty.service.event.jgroupschannelname";
+
+ /** Notifier service reference reference. */
+ protected WikittyServiceNotifier ws;
+
+
+ /** JGroup channel. */
+ protected JChannel channel;
+
+ public JGroupsNotifierTransporter(WikittyServiceNotifier ws, Properties props) {
+ this.ws = ws;
+
+ // can be null according to default constructor
+ if (props != null) {
+ // add notifier as listener
+ String jgroupChannel = props.getProperty(WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION);
+ if (!StringUtils.isBlank(jgroupChannel)) {
+ initChannel(jgroupChannel);
+ } else {
+ throw new IllegalArgumentException("Can't use propagate cache without a valid jgroups channel name !!!");
+ }
+ }
+ }
+
+ /**
+ * Init jgroup channel.
+ *
+ * @param channelName channel name
+ */
+ protected void initChannel(String channelName) {
+ if (log.isDebugEnabled()) {
+ log.debug("Init jgroup communication channel...");
+ }
+
+ try {
+ // use default udp.xml in classpath
+ channel = new JChannel();
+ channel.setReceiver(this);
+
+ // don't receive messages sent by myself
+ channel.setOpt(Channel.LOCAL, false);
+
+ channel.connect(channelName);
+
+ if (log.isInfoEnabled()) {
+ log.info("JGroup communication channel initialized to "
+ + channel.getAddressAsString() + " ("
+ + channel.getClusterName() + ")");
+ log.info("Channel view: " + channel.getView());
+ }
+ } catch (ChannelException eee) {
+ throw new WikittyException("Can't initialize jgroup channel", eee);
+ }
+ }
+
+ /**
+ * Send a jgroup message to all other channel member.
+ *
+ * @param event message to send
+ */
+ @Override
+ public void sendMessage(WikittyServiceEvent event) throws Exception {
+ Message msg = new Message(null, null, event);
+ channel.send(msg);
+ }
+
+ /*
+ * @see org.jgroups.ReceiverAdapter#receive(org.jgroups.Message)
+ */
+ @Override
+ public void receive(Message msg) {
+
+ Object message = msg.getObject();
+
+ if (log.isInfoEnabled()) {
+ log.info("Receive message : " + message);
+ }
+
+ if (message instanceof WikittyServiceEvent) {
+ WikittyServiceEvent event = (WikittyServiceEvent)message;
+
+ //source is transient, add it here :
+ event.setSource(ws);
+ event.setRemote(true); // received event became remote
+
+ switch(event.type) {
+ case PUT_WIKITTY:
+ ws.firePutWikitty(event); break;
+ case REMOVE_WIKITTY:
+ ws.fireRemoveWikitty(event); break;
+ case CLEAR_WIKITTY:
+ ws.fireClearWikitty(event); break;
+ case PUT_EXTENSION:
+ ws.firePutExtension(event); break;
+ case REMOVE_EXTENSION:
+ ws.fireRemoveExtension(event); break;
+ case CLEAR_EXTENSION:
+ ws.fireClearExtension(event); break;
+ default:
+ if (log.isDebugEnabled()) {
+ log.debug("Not managed jgroup message " + event.type);
+ }
+ }
+ }
+ }
+
+}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-13 14:05:31 UTC (rev 402)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-13 14:08:43 UTC (rev 403)
@@ -44,9 +44,23 @@
/** serialVersionUID. */
private static final long serialVersionUID = 9017732163643700599L;
+ /** Message type (put, remove, clear...). */
+ static public enum WikittyEventType {
+ PUT_WIKITTY,
+ REMOVE_WIKITTY,
+ CLEAR_WIKITTY,
+ PUT_EXTENSION,
+ REMOVE_EXTENSION,
+ CLEAR_EXTENSION
+ }
+
+
/** Remote event (received from jgroup). */
protected boolean remote;
+ /** event type */
+ protected WikittyEventType type;
+
/**
* Id managed by event.
*
@@ -73,8 +87,9 @@
*
* @param source wikitty service
*/
- public WikittyServiceEvent(Object source) {
+ public WikittyServiceEvent(Object source, WikittyEventType type) {
super(source);
+ this.type = type;
}
/**
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-13 14:05:31 UTC (rev 402)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-13 14:08:43 UTC (rev 403)
@@ -26,10 +26,11 @@
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
+import org.apache.commons.beanutils.ConstructorUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ListenerSet;
/**
@@ -48,31 +49,6 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyServiceNotifier.class);
- /**
- * Utilisation du canal de communication basé sur jgroups avec
- * comme identifiant d'application le nom de canal en option.
- *
- * Si ce nom est vide, jgroups n'est pas utilisé.
- * Si {@link #WIKITTY_EVENT_PROPAGATE_OPTION} est a true et que cette
- * options est vide, une exception est levée.
- */
- static public final String WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION = "wikitty.service.event.jgroupschannelname";
-
- /**
- * Indique si les objects sont propages (true) vers les autres caches ou
- * simplement supprimes des autres caches (false). Default to {@code false}.
- */
- static public final String WIKITTY_EVENT_PROPAGATE_OPTION = "wikitty.service.event.propagateEvent";
-
- /**
- * Indique si les evenement sont propagés aux autres listener. Sinon on est
- * juste listener des evenements recus. C'est pourquoi le listener
- * {@link #notifier} doit toujours être ajouté.
- *
- * @see WikittyServiceNotifier#WIKITTY_EVENT_PROPAGATE_OPTION
- */
- protected boolean propagateCache = false;
-
/** Service to delegate. */
protected WikittyService ws;
@@ -111,41 +87,11 @@
allWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
localWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
remoteWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
-
- addJGroupNotifier(props);
- }
- /**
- * Add jgroup listener if enabled by configuration.
- *
- * @param props properties (can be null)
- */
- protected void addJGroupNotifier(Properties props) {
-
// can be null according to default constructor
if (props != null) {
-
- // get propagate cache property
- String propagateCacheOption = props.getProperty(WIKITTY_EVENT_PROPAGATE_OPTION, "false");
- propagateCache = "true".equalsIgnoreCase(propagateCacheOption);
- if (log.isDebugEnabled()) {
- log.debug("Set propagateCache option to " + propagateCache);
- }
-
- // add notifier as listener
- String jgroupChannel = props.getProperty(WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION);
- if (!StringUtils.isBlank(jgroupChannel)) {
- notifier = new JGroupsNotifier(this, jgroupChannel, propagateCache);
- addWikittyServiceListener(notifier, ServiceListenerType.ALL); // weak reference
- }
- else if (propagateCache) {
- throw new IllegalArgumentException("Can't use propagate cache without a valid jgroups channel name !!!");
- }
- else if (log.isDebugEnabled()) {
- log.debug("JGroup synchronisation channel not used ");
- }
+ notifier = new RemoteNotifier(this, props);
}
-
}
@Override
@@ -443,7 +389,8 @@
* @param ws data
*/
protected void firePutWikitty(Wikitty... ws) {
- WikittyServiceEvent event = new WikittyServiceEvent(ws);
+ WikittyServiceEvent event = new WikittyServiceEvent(ws,
+ WikittyServiceEvent.WikittyEventType.PUT_WIKITTY);
Set<String> ids = new HashSet<String>();
Map<String, Set<String>> idsExtension = new HashMap<String, Set<String>>();
Map<String, String> idsVersion = new HashMap<String, String>();
@@ -471,7 +418,8 @@
* @param wikittyIds wikitty ids
*/
protected void fireRemoveWikitty(String... wikittyIds) {
- WikittyServiceEvent event = new WikittyServiceEvent(ws);
+ WikittyServiceEvent event = new WikittyServiceEvent(ws,
+ WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY);
Set<String> ids = new HashSet<String>();
for (String wikittyId : wikittyIds) {
@@ -487,7 +435,8 @@
* Build event to fire and call {@link #fireClearWikitty(WikittyServiceEvent)}.
*/
protected void fireClearWikitty() {
- WikittyServiceEvent event = new WikittyServiceEvent(ws);
+ WikittyServiceEvent event = new WikittyServiceEvent(ws,
+ WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY);
fireClearWikitty(event);
}
@@ -497,7 +446,8 @@
* @param ws data
*/
protected void firePutExtension(WikittyExtension... exts) {
- WikittyServiceEvent event = new WikittyServiceEvent(ws);
+ WikittyServiceEvent event = new WikittyServiceEvent(ws,
+ WikittyServiceEvent.WikittyEventType.PUT_EXTENSION);
Set<String> ids = new HashSet<String>();
Map<String, Set<String>> idsExtension = new HashMap<String, Set<String>>();
@@ -525,7 +475,8 @@
* @param ws data
*/
protected void fireRemoveExtension(WikittyExtension... exts) {
- WikittyServiceEvent event = new WikittyServiceEvent(ws);
+ WikittyServiceEvent event = new WikittyServiceEvent(ws,
+ WikittyServiceEvent.WikittyEventType.REMOVE_EXTENSION);
Set<String> ids = new HashSet<String>();
for (WikittyExtension ext : exts) {
@@ -543,7 +494,8 @@
* @param ws data
*/
protected void fireClearExtension() {
- WikittyServiceEvent event = new WikittyServiceEvent(ws);
+ WikittyServiceEvent event = new WikittyServiceEvent(ws,
+ WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION);
fireClearExtension(event);
}
@@ -744,4 +696,189 @@
};
eventThread.start();
}
+
+ /**
+ * This interface must be implemented to send and received remote message.
+ * Only sendMessage method is in interface but you must write receive
+ * method too, but this method is protocol specific and can't appear in
+ * interface
+ */
+ static public interface RemoteNotifierTransporter {
+
+ /**
+ * Send a jgroup message to all other channel member.
+ *
+ * @param event message to send
+ */
+ public void sendMessage(WikittyServiceEvent event) throws Exception;
+ }
+
+ /**
+ * Class used to notify remote listener. This class is realy activate
+ * only if wikitty.notifier.transporter.class configuration is found and
+ * wikitty.service.event.propagateEvent is true
+ */
+ static public class RemoteNotifier implements WikittyServiceListener {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(JGroupsNotifierTransporter.class);
+ /**
+ * Indique si les objects sont propages (true) vers les autres caches ou
+ * simplement supprimes des autres caches (false). Default to {@code false}.
+ */
+ static public final String WIKITTY_EVENT_PROPAGATE_OPTION = "wikitty.service.event.propagateEvent";
+ /** notifier class name in configuration that this service must used */
+ static final public String WIKITTY_NOTIFIER_TRANSPORTER_CLASS = "wikitty.notifier.transporter.class";
+
+ /** Notifier service reference reference. */
+ protected WikittyServiceNotifier ws;
+ /**
+ * Indique si les objects sont propages (true) vers les autres caches ou
+ * simplement supprimes des autres caches (false).
+ *
+ * @see WikittyServiceCached#WIKITTY_PROPAGATE_CACHE_OPTION
+ */
+ protected boolean propagateEvent = false;
+ protected RemoteNotifierTransporter transporter;
+
+ public RemoteNotifier(WikittyServiceNotifier ws, Properties props) {
+ // can be null according to default constructor
+ if (props != null) {
+ this.ws = ws;
+
+ if (!props.containsKey(WIKITTY_NOTIFIER_TRANSPORTER_CLASS)) {
+ props.setProperty(WIKITTY_NOTIFIER_TRANSPORTER_CLASS, JGroupsNotifierTransporter.class.getName());
+ }
+ ApplicationConfig config = new ApplicationConfig(props);
+ propagateEvent = config.getOptionAsBoolean(WIKITTY_EVENT_PROPAGATE_OPTION);
+ if (log.isDebugEnabled()) {
+ log.debug("Set propagateEvent option to " + propagateEvent);
+ }
+
+ if (propagateEvent) {
+ try {
+ Class transporterClass = config.getOptionAsClass(
+ WIKITTY_NOTIFIER_TRANSPORTER_CLASS);
+ transporter = (RemoteNotifierTransporter) ConstructorUtils.invokeConstructor(transporterClass, new Object[]{this, props});
+ } catch (Exception eee) {
+ throw new WikittyException("Can't create notifier: "
+ + config.getOption(WIKITTY_NOTIFIER_TRANSPORTER_CLASS), eee);
+ }
+
+ // add this as listener when transporter is created without error
+ ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference
+ }
+ }
+ if (transporter == null && log.isDebugEnabled()) {
+ log.debug("RemoteNotifier synchronisation not used ");
+ }
+ }
+
+ /**
+ * Send a jgroup message to all other channel member.
+ *
+ * @param event message to send
+ */
+ protected void sendMessage(WikittyServiceEvent event) {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Try to send message : " + event);
+ }
+
+ transporter.sendMessage(event);
+
+ if (log.isInfoEnabled()) {
+ log.info("message send" + event);
+ }
+ } catch (Exception eee) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't send message", eee);
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[])
+ */
+ @Override
+ public void putWikitty(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate putWikitty event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[])
+ */
+ @Override
+ public void removeWikitty(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate removeWikitty event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty()
+ */
+ @Override
+ public void clearWikitty(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate clearWikitty event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[])
+ */
+ @Override
+ public void putExtension(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate putExtension event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#removeExtension(java.lang.String[])
+ */
+ @Override
+ public void removeExtension(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate removeExtension event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
+ */
+ @Override
+ public void clearExtension(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate clearExtension event");
+ }
+ }
+ }
+ }
}
1
0
Author: bpoussin
Date: 2010-10-13 16:05:31 +0200 (Wed, 13 Oct 2010)
New Revision: 402
Url: http://nuiton.org/repositories/revision/wikitty/402
Log:
preparation du pom pour l'implantation xmpp (ajout de dependance)
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-13 14:04:01 UTC (rev 401)
+++ trunk/pom.xml 2010-10-13 14:05:31 UTC (rev 402)
@@ -140,7 +140,7 @@
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
- <version>1.4.1</version>
+ <version>1.5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
@@ -187,6 +187,13 @@
</dependency>
<dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smackx</artifactId>
+ <version>3.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zk</artifactId>
<version>${zk.version}</version>
@@ -489,7 +496,17 @@
</plugin>
</plugins>
</pluginManagement>
-
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
</build>
<profiles>
1
0
r400 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty test/java/org/nuiton/wikitty/layers
by bpoussin@users.nuiton.org 13 Oct '10
by bpoussin@users.nuiton.org 13 Oct '10
13 Oct '10
Author: bpoussin
Date: 2010-10-13 16:03:30 +0200 (Wed, 13 Oct 2010)
New Revision: 400
Url: http://nuiton.org/repositories/revision/wikitty/400
Log:
debut de refactoring de la securite
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java 2010-10-13 14:03:30 UTC (rev 400)
@@ -0,0 +1,74 @@
+/* *##%
+ * Copyright (c) 2010 poussin. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *##%*/
+
+package org.nuiton.wikitty;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyMetaExtensionUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyMetaExtensionUtil.class);
+
+ private static String SEPARATOR = ":";
+
+ /**
+ * generate id for meta extension and extension
+ * @return a wikitty id
+ */
+ static public String generateId(
+ String metaExtensionName, String extensionName) {
+ return String.format("%s%s%s", metaExtensionName, SEPARATOR, extensionName);
+ }
+
+ /**
+ * Extract meta extension name from wikittyId. If Id is not meta extension
+ * id, return null
+ */
+ static public String extractMetaName(String id) {
+ String[] ids = id.split(SEPARATOR);
+ if (ids.length == 2) {
+ return ids[0];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Extract extension name from wikittyId. If Id is not meta extension
+ * id, return null
+ */
+ static public String extractExtName(String id) {
+ String[] ids = id.split(SEPARATOR);
+ if (ids.length == 2) {
+ return ids[1];
+ } else {
+ return null;
+ }
+ }
+
+}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java 2010-10-13 14:03:30 UTC (rev 400)
@@ -0,0 +1,134 @@
+/* *##%
+ * Copyright (c) 2010 poussin. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *##%*/
+
+package org.nuiton.wikitty;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittySecurityHelper {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittySecurityHelper.class);
+
+ /** nom du groupe des administrateurs de l'application */
+ static final public String WIKITTY_APPADMIN_GROUP_NAME = "WikittyAppAdmin";
+
+ /**
+ * get the id of a user given his login.
+ *
+ * @param securityToken a token
+ * @param login the login of the user to search for
+ * @return a wikitty id
+ */
+ static public String getUserWikittyId(WikittyProxy proxy, String login) {
+ String userWikittyId = null;
+ Wikitty user = proxy.findByCriteria(Search.query().eq(
+ WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
+ if (user != null) {
+ userWikittyId = user.getId();
+ }
+ return userWikittyId;
+ }
+
+ /**
+ * create appAdminGroup and add current user as first member
+ */
+ static public WikittyGroup createAppAdminGroup(WikittyUser user) {
+ WikittyGroup result = new WikittyGroupImpl();
+ result.setName(WIKITTY_APPADMIN_GROUP_NAME);
+
+ String firstUserId = user.getWikittyId();
+ result.addMembers(firstUserId);
+
+ return result;
+ }
+
+ /**
+ * create wikitty that represent a <strong>level 2</strong> security policy
+ * on the given extension.
+ *
+ * Store must check if this security policy doesn't already exist
+ *
+ */
+ static public Wikitty createExtensionAuthorisation(WikittyUser owner,
+ WikittyExtension extension) {
+
+ String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extension.getName());
+ Wikitty result = new WikittyImpl(wikittyAuthorisationId);
+ WikittyAuthorisationHelper.addExtension(result);
+ WikittyAuthorisationHelper.setOwner(result, owner.getWikittyId());
+ return result;
+ }
+
+ static public Wikitty restoreExtensionAuthorisation(
+ WikittyProxy proxy, WikittyExtension extension) {
+ String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extension.getName());
+ Wikitty result = proxy.restore(wikittyAuthorisationId);
+ return result;
+ }
+
+// /**
+// * @param securityToken token with rights to modify extension
+// * @param extensionRights a wikitty that has extension WikittyAuthorisation
+// */
+// static public void storeExtensionAuthorisation(String securityToken,
+// Wikitty extensionRights) {
+//
+// String userId = getUserId(securityToken);
+//
+// Wikitty oldVersion = ws.restore(securityToken, extensionRights.getId());
+//
+// // check that the extensionRights does not have
+// if (WikittyAuthorisationHelper.hasExtension(extensionRights)) {
+//
+// if (oldVersion == null) {
+// // if this exception is raised, you should use addExtensionAuthorisation()
+// throw new IllegalArgumentException("you can't store an authorisation for the fist time");
+//
+// } else {
+//
+// if ( userIsAnonymousOrAppAdmin(securityToken, userId) ||
+// canAdmin(securityToken, userId, null, oldVersion) ) {
+//
+// ws.store(securityToken, extensionRights);
+//
+// } else {
+// throw new SecurityException(String.format(
+// "user %s can't admin rights for this extension", userId));
+// }
+// }
+// } else {
+// throw new IllegalArgumentException(String.format(
+// "extensionRights %s is not a wikittyAuthorisation. It misses the extension",
+// extensionRights));
+// }
+// }
+//
+}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-13 12:38:37 UTC (rev 399)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-13 14:03:30 UTC (rev 400)
@@ -29,9 +29,6 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyServiceSecurity.class);
- /** nom du groupe des administrateurs de l'application */
- static final public String WIKITTY_APPADMIN_GROUP_NAME = "WikittyAppAdmin";
-
protected WikittyService ws;
/** cache de l'id du groupe AppAdmin */
@@ -97,61 +94,7 @@
}
/**
- * @return a wikitty id
- */
- protected String extensionToWikittySecurityId(String extensionName) {
- return String.format("WikittySecurity:%s", extensionName);
- }
-
- /** create an new account.
- * create a new account, require to be appAdmin or anonymous if security
- * is not yet enabled
- * @param securityToken token (null for anonymous, or a token of an appAdmin)
- * @param login the login of the account to be created
- * @param password the password of the account to be created
- */
- public void createAccount(String securityToken, String login, String password) {
- String userId = getUserId(securityToken);
- boolean creationAllowed = userIsAnonymousOrAppAdmin(securityToken, userId);
-
- if (creationAllowed) {
- Wikitty user = ws.findByCriteria(securityToken, Search.query().eq(
- WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
- if (user == null) {
- user = new WikittyImpl();
- WikittyUserHelper.addExtension(user);
- WikittyUserHelper.setLogin(user, login);
- WikittyUserHelper.setPassword(user, password);
- ws.store(null, user);
- log.debug(String.format("login '%s' has userId '%s'", login, user.getId()));
- } else {
- throw new IllegalArgumentException(
- String.format("account already exists '%s'",
- login));
- }
- } else {
- throw new SecurityException("only admin can create accounts");
- }
- }
-
- /** get the id of a user given his login.
- *
- * @param securityToken a token
- * @param login the login of the user to search for
- * @return a wikitty id
- */
- public String getUserWikittyId(String securityToken, String login) {
- getUserId(securityToken);
- String userWikittyId = null;
- Wikitty user = ws.findByCriteria(null, Search.query().eq(
- WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
- if (user != null) {
- userWikittyId = user.getId();
- }
- return userWikittyId;
- }
-
- /** if app-admin group exists, return true if given userId is app-admin
+ * if app-admin group exists, return true if given userId is app-admin
* if app-admin group doesn't exists, return true if user is anonymous
*/
protected boolean userIsAnonymousOrAppAdmin(String securityToken, String userId) {
@@ -172,107 +115,6 @@
return userIsAnonymousOrAppAdmin;
}
- /** add a <strong>level 2</strong> security policy on the given extension. */
- public Wikitty addExtensionAuthorisation(String securityToken,
- WikittyExtension extension) {
-
- // TODO 20101005 bleny merge into storeExtensionAuthorisation by adding an extension paramater ?
-
- String userId = getUserId(securityToken);
- boolean creationAllowed = userIsAnonymousOrAppAdmin(securityToken, userId);
-
- if (creationAllowed) {
- if (restoreExtensionAuthorisation(securityToken, extension.getName()) == null) {
- String wikittyAuthorisationId = extensionToWikittySecurityId(extension.getName());
- Wikitty wikittyAuthorisation = new WikittyImpl(wikittyAuthorisationId);
- WikittyAuthorisationHelper.addExtension(wikittyAuthorisation);
- WikittyAuthorisationHelper.setOwner(wikittyAuthorisation, userId);
- ws.store(securityToken, wikittyAuthorisation);
- return wikittyAuthorisation;
- } else {
- throw new SecurityException(String.format(
- "extension %s already has an security extension attached",
- extension.getName()));
- }
- } else {
- throw new SecurityException(String.format(
- "Only members of %s group can add authorisation",
- WIKITTY_APPADMIN_GROUP_NAME));
- }
- }
-
- /** restore the wikitty authorisation attached to given extension.
- *
- * @return a wikitty with WikittyAuthorisation extension, or null if given
- * extension has no security policy attached
- */
- public Wikitty restoreExtensionAuthorisation(String securityToken,
- WikittyExtension extension) {
- return restoreExtensionAuthorisation(securityToken, extension.getName());
- }
-
- /** restore the wikitty authorisation attached to given extension.
- *
- * @return a wikitty with WikittyAuthorisation extension, or null if given
- * extension has no security policy attached
- */
- public Wikitty restoreExtensionAuthorisation(String securityToken,
- String extensionName) {
- String userId = getUserId(securityToken);
- String wikittyAuthorisationId = extensionToWikittySecurityId(extensionName);
- Wikitty wikittyAuthorisation = ws.restore(securityToken, wikittyAuthorisationId);
- if (wikittyAuthorisation == null) {
- log.debug(extensionName + " has no authorization attached");
- } else {
- /*
- if ( ! canAdmin(securityToken, userId, wikittyAuthorisation)) {
- throw new SecurityException(String.format(
- "user %s doesn't have admin rights on extension %s",
- userId, extension.getName()));
- }
- */
- }
- return wikittyAuthorisation;
- }
-
- /**
- *
- * @param securityToken token with rights to modify extension
- * @param extensionRights a wikitty that has extension WikittyAuthorisation
- */
- public void storeExtensionAuthorisation(String securityToken,
- Wikitty extensionRights) {
-
- String userId = getUserId(securityToken);
-
- Wikitty oldVersion = ws.restore(securityToken, extensionRights.getId());
-
- // check that the extensionRights does not have
- if (WikittyAuthorisationHelper.hasExtension(extensionRights)) {
-
- if (oldVersion == null) {
- // if this exception is raised, you should use addExtensionAuthorisation()
- throw new IllegalArgumentException("you can't store an authorisation for the fist time");
-
- } else {
-
- if ( userIsAnonymousOrAppAdmin(securityToken, userId) ||
- canAdmin(securityToken, userId, null, oldVersion) ) {
-
- ws.store(securityToken, extensionRights);
-
- } else {
- throw new SecurityException(String.format(
- "user %s can't admin rights for this extension", userId));
- }
- }
- } else {
- throw new IllegalArgumentException(String.format(
- "extensionRights %s is not a wikittyAuthorisation. It misses the extension",
- extensionRights));
- }
- }
-
@Override
public UpdateResponse store(String securityToken, Wikitty wikitty) {
Collection<Wikitty> wikitties = Arrays.asList(wikitty);
@@ -320,7 +162,8 @@
// check that **reader** right on Security for all extension
for (String extensionName: newExtensions) {
- Wikitty extensionRights = restoreExtensionAuthorisation(securityToken, extensionName);
+ Wikitty extensionRights = restoreExtensionAuthorisation(
+ securityToken, extensionName);
boolean canCreate = extensionRights == null ||
canRead(securityToken, userId, null, extensionRights);
if ( ! canCreate ) {
@@ -896,39 +739,14 @@
return result;
}
- /** create appAdminGroup and add current user as first member */
- public void createAppAdminGroup(String securityToken) {
- if (securityToken == null) {
- throw new IllegalArgumentException("login required, token is null");
- }
-
- Wikitty group = getAppAdminGroup(securityToken);
- if (group == null) {
- // il n'existe pas on le cree.
- WikittyGroupAbstract appAdminGroup = new WikittyGroupImpl();
- appAdminGroup.setName(WIKITTY_APPADMIN_GROUP_NAME);
-
- String fisrtUserId = getUserId(securityToken);
- appAdminGroup.addMembers(fisrtUserId);
-
- ws.store(securityToken, appAdminGroup.getWikitty());
-
- // on garde l'id pour ne plus faire la recherche,
- // vu que le groupe doit etre unique cela ne pose pas de probleme
- appAdminGroupId = appAdminGroup.getWikitty().getId();
- group = appAdminGroup.getWikitty();
- } else {
- throw new SecurityException("AppAdmin group already exists");
- }
- }
-
/** get the wikitty with extension WikittyGroup that contains all app-admin. */
protected Wikitty getAppAdminGroup(String securityToken) {
Wikitty group;
if (appAdminGroupId == null) {
// 1er fois, on le recherche
group = ws.findByCriteria(securityToken, Search.query().eq(
- WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME, WIKITTY_APPADMIN_GROUP_NAME).criteria());
+ WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME,
+ WikittySecurityHelper.WIKITTY_APPADMIN_GROUP_NAME).criteria());
// group peut-etre null s'il n'existe pas
} else {
// on a deja fait la recherche precedement, on essaie de reutilise
@@ -966,4 +784,33 @@
return false; // not found in groupOrUser
}
+ /**
+ * restore the wikitty authorisation attached to given extension.
+ *
+ * @return a wikitty with WikittyAuthorisation extension, or null if given
+ * extension has no security policy attached
+ */
+ protected Wikitty restoreExtensionAuthorisation(String securityToken,
+ WikittyExtension extension) {
+ return restoreExtensionAuthorisation(securityToken, extension.getName());
+ }
+
+ /**
+ * restore the wikitty authorisation attached to given extension.
+ *
+ * @return a wikitty with WikittyAuthorisation extension, or null if given
+ * extension has no security policy attached
+ */
+ protected Wikitty restoreExtensionAuthorisation(String securityToken,
+ String extensionName) {
+ String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName);
+ Wikitty wikittyAuthorisation = ws.restore(securityToken, wikittyAuthorisationId);
+ if (wikittyAuthorisation == null) {
+ log.debug(extensionName + " has no authorization attached");
+ }
+ return wikittyAuthorisation;
+ }
+
+
}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-13 12:38:37 UTC (rev 399)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-13 14:03:30 UTC (rev 400)
@@ -1,9 +1,7 @@
package org.nuiton.wikitty.layers;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -17,14 +15,21 @@
import org.nuiton.wikitty.WikittyAuthorisationAbstract;
import org.nuiton.wikitty.WikittyAuthorisationHelper;
import org.nuiton.wikitty.WikittyAuthorisationImpl;
+import org.nuiton.wikitty.WikittyGroup;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittySecurityHelper;
import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.WikittyServiceInMemory;
import org.nuiton.wikitty.WikittyServiceSecurity;
+import org.nuiton.wikitty.WikittyUser;
+import org.nuiton.wikitty.WikittyUserImpl;
import org.nuiton.wikitty.WikittyUtil;
/** test {@link org.nuiton.wikitty.WikittyServiceSecurity}. */
public class WikittyServiceSecurityTest extends AbstractWikittyServiceTest {
-
+
+ // FIXME 20101112 poussin classe a revoir suite au refactoring de la secu
+
private static final Log log = LogFactory.getLog(WikittyServiceSecurityTest.class);
protected WikittyServiceSecurity securityService;
@@ -34,7 +39,7 @@
protected String writerToken;
protected String adminToken;
protected String ownerToken;
-
+
@Before
public void setUpWikittyServiceSecurityTest() {
WikittyService inMemoryService = new WikittyServiceInMemory();
@@ -52,26 +57,52 @@
// token = service.login(APPADMIN_LOGIN, APPADMIN_PASSWORD);
token = null;
- securityService.createAccount(token, "i have no rights", "");
- securityService.createAccount(token, "reader", "");
- securityService.createAccount(token, "writer", "");
- securityService.createAccount(token, "admin", "");
- securityService.createAccount(token, "owner", "");
+ WikittyProxy proxy = new WikittyProxy(securityService);
+ proxy.setSecurityToken(token);
+
+ WikittyUser anonymous = new WikittyUserImpl();
+ anonymous.setLogin("i have no rights");
+ anonymous.setPassword("");
+ proxy.store(anonymous);
- Wikitty authorizations = securityService.addExtensionAuthorisation(token, extension);
- WikittyAuthorisationHelper.addReader(authorizations, securityService.getUserWikittyId(token, "reader"));
- WikittyAuthorisationHelper.addWriter(authorizations, securityService.getUserWikittyId(token, "writer"));
- WikittyAuthorisationHelper.addAdmin(authorizations, securityService.getUserWikittyId(token, "admin"));
- WikittyAuthorisationHelper.setOwner(authorizations, securityService.getUserWikittyId(token, "owner"));
+ WikittyUser reader = new WikittyUserImpl();
+ reader.setLogin("reader");
+ reader.setPassword("");
+ proxy.store(reader);
+ WikittyUser writer = new WikittyUserImpl();
+ writer.setLogin("writer");
+ writer.setPassword("");
+ proxy.store(writer);
+
+ WikittyUser admin = new WikittyUserImpl();
+ admin.setLogin("admin");
+ admin.setPassword("");
+ proxy.store(admin);
+
+ WikittyUser owner = new WikittyUserImpl();
+ owner.setLogin("owner");
+ owner.setPassword("");
+ proxy.store(owner);
+
+
+ Wikitty authorizations = WikittySecurityHelper.createExtensionAuthorisation(owner, extension);
+ WikittyAuthorisationHelper.addReader(authorizations, reader.getWikittyId());
+ WikittyAuthorisationHelper.addWriter(authorizations, writer.getWikittyId());
+ WikittyAuthorisationHelper.addAdmin(authorizations, admin.getWikittyId());
+ WikittyAuthorisationHelper.setOwner(authorizations, owner.getWikittyId());
+
log.debug("initial wikitty rights" + authorizations);
- securityService.storeExtensionAuthorisation(token, authorizations);
securityService.storeExtension(token, extension);
+ securityService.store(token, authorizations);
- Wikitty extensionAuthorisation = securityService.restoreExtensionAuthorisation(token, extension);
- log.debug("restored initial rights " + extensionAuthorisation);
+// Wikitty extensionAuthorisation =
+// WikittySecurityHelper.restoreExtensionAuthorisation(proxy, extension);
+//
+// log.debug("restored initial rights " + extensionAuthorisation);
+
token = null;
ownerToken = service.login("owner", "");
@@ -81,9 +112,14 @@
noRightsToken = service.login("i have no rights", "");
/**/
- securityService.createAccount(null, "root", "");
+ WikittyUser root = new WikittyUserImpl();
+ root.setLogin("root");
+ root.setPassword("");
+ proxy.store(root);
+
String rootToken = service.login("root", "");
- securityService.createAppAdminGroup(rootToken);
+ WikittyGroup appAdmin = WikittySecurityHelper.createAppAdminGroup(root);
+ proxy.store(appAdmin);
/**/
}
@@ -98,7 +134,7 @@
// now storing the wikitty for next tests
service.store(readerToken, aWikitty);
-
+
// try to make operations on the stored wikitty with a bad token
try {
service.restore(invalidToken, aWikitty.getId());
@@ -109,7 +145,7 @@
service.logout(invalidToken);
fail();
} catch (SecurityException e) {}
-
+
// now try to make a valid token invalid
service.logout(readerToken);
try {
@@ -117,7 +153,7 @@
fail();
} catch (SecurityException e) {}
}
-
+
/* *** level 1 security tests ***/
@Test
@@ -125,7 +161,8 @@
aWikitty.addExtension(WikittyAuthorisationAbstract.extensionWikittyAuthorisation);
WikittyAuthorisation auth = new WikittyAuthorisationImpl(aWikitty);
- String readerId = securityService.getUserWikittyId(null, "reader");
+ WikittyProxy proxy = new WikittyProxy(securityService);
+ String readerId = WikittySecurityHelper.getUserWikittyId(proxy, "reader");
auth.clearReader();
auth.addReader(readerId);
@@ -148,7 +185,8 @@
WikittyAuthorisation auth = new WikittyAuthorisationImpl(aWikitty);
service.store(ownerToken, aWikitty);
- String adminId = securityService.getUserWikittyId(null, "admin");
+ WikittyProxy proxy = new WikittyProxy(securityService);
+ String adminId = WikittySecurityHelper.getUserWikittyId(proxy, "admin");
auth.clearReader();
auth.clearWriter();
@@ -168,9 +206,9 @@
log.debug("restored wikitty is " + restoredWikitty);
assertNotNull(restoredWikitty);
}
-
+
/* *** level 2 security tests ***/
-
+
/** test level 2 reader right */
@Test
public void checkReaderRightOnExtension() {
@@ -193,7 +231,7 @@
} catch (SecurityException e) {
fail("no exception should have been raised");
}
-
+
try {
service.store(readerToken, aWikitty);
service.restoreExtension(readerToken, extension.getId());
@@ -206,7 +244,7 @@
@Test
public void checkWriterRightOnExtension() {
-
+
FieldType fieldType = new FieldType(FieldType.TYPE.STRING, 0, 1);
service.restoreExtensionLastVersion(writerToken, extension.getName());
@@ -227,11 +265,14 @@
@Test
public void checkAdminRightOnExtension() {
// TODO 20100923 bleny check that store with no sufficient rights fail
-
- Wikitty extensionAuthorisation = securityService.restoreExtensionAuthorisation(adminToken, extension);
+ WikittyProxy adminProxy = new WikittyProxy(securityService);
+ adminProxy.setSecurityToken(adminToken);
+ Wikitty extensionAuthorisation =
+ WikittySecurityHelper.restoreExtensionAuthorisation(adminProxy, extension);
+
log.debug("initial rights " + extensionAuthorisation);
-
+
// set no reader, ID1 as single writer and ID2 as owner
WikittyAuthorisationHelper.clearReader(extensionAuthorisation);
WikittyAuthorisationHelper.clearWriter(extensionAuthorisation);
@@ -244,16 +285,17 @@
// WikittyAuthorisationHelper.clearAdmin(extensionAuthorisation);
log.debug("will store rights " + extensionAuthorisation);
-
+
try {
- securityService.storeExtensionAuthorisation(writerToken, extensionAuthorisation);
+ securityService.store(writerToken, extensionAuthorisation);
fail("an exception should habe raised");
} catch (SecurityException e) {}
-
- securityService.storeExtensionAuthorisation(adminToken, extensionAuthorisation);
+ securityService.store(adminToken, extensionAuthorisation);
+
// now, restore and check that rights are preserved
- extensionAuthorisation = securityService.restoreExtensionAuthorisation(adminToken, extension);
+ extensionAuthorisation =
+ WikittySecurityHelper.restoreExtensionAuthorisation(adminProxy, extension);
log.debug("restored rights " + extensionAuthorisation);
@@ -264,9 +306,9 @@
assertTrue(WikittyAuthorisationHelper.getWriter(extensionAuthorisation).contains("ID1"));
// ... and no one else
assertEquals(1, WikittyAuthorisationHelper.getWriter(extensionAuthorisation).size());
-
+
// check that ID2 is owner
assertTrue(WikittyAuthorisationHelper.getOwner(extensionAuthorisation).contains("ID2"));
-
+
}
}
1
0
Author: bpoussin
Date: 2010-10-13 14:38:37 +0200 (Wed, 13 Oct 2010)
New Revision: 399
Url: http://nuiton.org/repositories/revision/wikitty/399
Log:
modification de la dependance i18n, je ne comprend pas comment ca
pouvait marcher (mauvais groupId et mauvais artefactId :()
Modified:
trunk/pom.xml
trunk/wikitty-api/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-08 23:51:58 UTC (rev 398)
+++ trunk/pom.xml 2010-10-13 12:38:37 UTC (rev 399)
@@ -145,6 +145,13 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ <version>1.2.2</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
<version>1.1.4c</version>
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2010-10-08 23:51:58 UTC (rev 398)
+++ trunk/wikitty-api/pom.xml 2010-10-13 12:38:37 UTC (rev 399)
@@ -68,6 +68,11 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
</dependency>
2
1
Author: tchemit
Date: 2010-10-09 01:51:58 +0200 (Sat, 09 Oct 2010)
New Revision: 398
Url: http://nuiton.org/repositories/revision/wikitty/398
Log:
Update mavenpom4redmine to 2.3.1.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-08 15:48:52 UTC (rev 397)
+++ trunk/pom.xml 2010-10-08 23:51:58 UTC (rev 398)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.3</version>
+ <version>2.3.1</version>
</parent>
<!-- ************************************************************* -->
1
0
Author: bpoussin
Date: 2010-10-08 17:48:52 +0200 (Fri, 08 Oct 2010)
New Revision: 397
Url: http://nuiton.org/repositories/revision/wikitty/397
Log:
commit du changelog (mais il ne sert peut-etre plus avec redmine)
Modified:
trunk/changelog.txt
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2010-10-08 15:48:28 UTC (rev 396)
+++ trunk/changelog.txt 2010-10-08 15:48:52 UTC (rev 397)
@@ -0,0 +1,131 @@
+Release 0.9
+-----------
+d- test unitaire implantation hbase
+d- config solr
+d- support recherche by example
+d- ajout creation index solr sur store
+d- implantation label (gesion des listes)
+d- ajout creation index solr sur label
+d- support recherche by example avec facet
+d- implantation PageResult pour supporter toute l'info des resultats (facet)
+d- probleme de changement de version des extensions: Si on change une extension
+ (et donc sa version) alors qu'elle avait ete defini dans un Bean, comment
+ continuer a utiliser ce Bean qui va utiliser une mauvaise version de
+ l'extension (impossible d'appeler un store)
+d- probleme les List et lucene a moins de mettre tous les champs comme pouvant
+ etre multi-value ?
+d- probleme de stockage des listes dans hbase, les attributs sont conserve entre
+ deux sauvegardes du meme objets, donc il faut pouvoir supprimer les anciens
+ champs (pour les listes, un remove diminue la liste, mais en fait il reste
+ toujours les elements car le nom du champs contient le nombre d'element)
+ Il faut donc soit connaitre le nombre d'element soit, supprimer les anciens
+ avant d'ajouter les nouveaux
+d- gestion des versions des extensions (supporte-t-on plusieurs version d'une
+ meme extension au meme moment pour different objet ?)
+d- l'index solr est supprimé dans le setUp()
+d- vider la base hbase
+d- implantation categorisation
+d- implantation import/export XML des wikitties (a tester)
+d- support du delete de wikitty (marque comme supprime ?)
+d- implantation d'un service metier (developpement du proxy) (ex: product)
+d- pouvoir mettre des tag/value sur les fieldType
+d- possibilite de nomer un Criteria
+d- support des required dans les extensions
+d- import/export a finir (implantation des methodes)
+d- Handle lowerBound and upperBound constraint on Fields.
+d- migration que faire lors d'un changement d'une extension
+ (ajout/suppression/modif de champs)
+d- typage dans solr
+d- finir implantation criteria
+d- synchronisation de version des extension
+ ex: un champ change de nom.
+ ex: on recharge un wikitty dont une extension a évolué (ajout/suppression de champ)
+d- support des enumerations comme type de champs wikitty (gere comme une chaine)
+
+Release 1 Sprint 1
+------------------
+d- [bug] gestion des ensembles, cast des ensembles en liste
+d- [bug] non récupération du résultat de l'export
+d- [bug] transformation des champs dans le format Solr pour la récupération des facettes
+d- [bug] passage du format de date en UTC
+d- creation d'une factory pour la création des extensions
+d- migration des api hbase en 0.20.0
+d- mise en place du Log4J
+d- suppression des exceptions sur le recherche dans le cas où il y a pas de résultat
+d- implantation facet sur categorisation (facet hierarchique)
+d- transformation en xml du criteria
+d- récupérer les dépendances entre extension dans un wikitty
+d- centralisation de la configuration htable
+
+d- gestion des critiria sur les extensions
+d- simplification de l'interface sur les find criteria et export, plus qu'un
+ find criteria et un export sur le service, déplacement des find example et export example
+ sur le proxy
+
+Release 1 Sprint 2
+------------------
+d- trie sur le criteria
+d- création d'un nom d'élément static pour les recherches sur les ids et les extensions
+d- recherche full texte
+d- recherche d'un champ sur plusieurs extensions
+d- ajout de requires sur une extension dans l'import en export XML
+
+d- améloration de la recherche avec des arbres arithmétiques
+d- création d'un module Solr
+d- reindexation des nouveaux contenus quand ils sont aujouté dans un noeud
+d- ajout d'un find all dans le DAO
+d- reprise des tests unitaires
+
+Release 1 Sprint 3
+------------------
+d- modification du DAO pour renvoyer par défaut les beans selon l'extension de la class paramètrés
+d- restoreNode avec checkExtension
+d- facetisation sur les extensions
+d- restore d'une extension à partir de son nom
+
+d- restauration en set ordonnées
+d- ajout d'un service pour synchroniser solr avec hbase
+
+Release 1 Sprint 4
+------------------
+
+d- migration des wikitties lors d'une modification de l'extension
+d- normalisation des versions sur les extensions
+d- clone pour modification d'une extension
+d- sous recherche avec un sous arbre en not
+d- acceptation de n'importe quels caractères dans les tagvalues
+
+Release 1 RC
+------------
+d- refonte des tests
+d- déplacer les tests solr de hbase
+d- gestion des string en text dans solr
+d- recherche sur un champ string sans tenir compte de la case
+d- création d'un module de storage en jpa
+
+Release 2 Sprint 1 (Version 1.2)
+--------------------------------
+d- fixer les SQL injections dans la partie JDBC
+d- mise en place des transactions JTA dans l'API
+d- mise en place des transactions JTA dans JPA
+d- mise en place des transactions JTA dans JDBC
+d- modification des interfaces de storage pour supprimer les commandes
+d- suppression du module test-hbase-plateform, directement intégrer dans les
+tests du module hbase
+d- mise en place des transactions JTA dans Solr
+d- ajout d'un filtre sur les restores children et node
+
+Version 1.3
+-----------
+d- ajout des tagvalues sur les extensions
+d- recupération des requires dans le module JDBC
+d- utilisation de JPA 2 dans le module JPA
+d- création d'un storage permettant d'enregister dans plusieurs autres storages
+d- création d'un storage JMS pour faire de la réplication de données
+d- utiliser directement les objets de l'API pour les mapper en XML dans la partie JPA
+
+Version 2.1.5
+-------------
+d- ajouter un generateur BusinessEntityHelper qui contient les memes
+ methodes que le BusinessEntityAbstract mais en static et en 1er
+ arguement un wikitty
1
0