You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2011/01/12 00:00:21 UTC
svn commit: r1057909 - in /mina/vysper/trunk/server: ./ admin-console/
admin-console/src/ admin-console/src/main/ admin-console/src/main/java/
admin-console/src/main/java/org/ admin-console/src/main/java/org/apache/
admin-console/src/main/java/org/apac...
Author: ngn
Date: Tue Jan 11 23:00:20 2011
New Revision: 1057909
URL: http://svn.apache.org/viewvc?rev=1057909&view=rev
Log:
Adding a first prototype of the admin console
Added:
mina/vysper/trunk/server/admin-console/
mina/vysper/trunk/server/admin-console/pom.xml
mina/vysper/trunk/server/admin-console/src/
mina/vysper/trunk/server/admin-console/src/main/
mina/vysper/trunk/server/admin-console/src/main/java/
mina/vysper/trunk/server/admin-console/src/main/java/org/
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java
mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ResourceNotFoundException.java
mina/vysper/trunk/server/admin-console/src/main/resources/
mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/
mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/
mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/command.vm
mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/index.vm
mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/layout.vm
mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/login.vm
mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/nav.vm
mina/vysper/trunk/server/admin-console/src/main/resources/bogus_mina_tls.cert (with props)
mina/vysper/trunk/server/admin-console/src/main/webapp/
mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/
mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/console-servlet.xml
mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/web.xml
mina/vysper/trunk/server/admin-console/src/test/
mina/vysper/trunk/server/admin-console/src/test/java/
mina/vysper/trunk/server/admin-console/src/test/java/org/
mina/vysper/trunk/server/admin-console/src/test/java/org/apache/
mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/
mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/
mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java
mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/MockHttpSession.java
mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/ServerMain.java
mina/vysper/trunk/server/admin-console/src/test/resources/
mina/vysper/trunk/server/admin-console/src/test/resources/log4j.properties
Modified:
mina/vysper/trunk/server/pom.xml
Added: mina/vysper/trunk/server/admin-console/pom.xml
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/pom.xml?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/pom.xml (added)
+++ mina/vysper/trunk/server/admin-console/pom.xml Tue Jan 11 23:00:20 2011
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>vysper-server</artifactId>
+ <groupId>org.apache.vysper</groupId>
+ <version>0.7-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.vysper</groupId>
+ <artifactId>vysper-admin-console</artifactId>
+ <name>Apache Vysper Core Admin Console</name>
+ <version>0.7-SNAPSHOT</version>
+ <packaging>war</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.vysper</groupId>
+ <artifactId>vysper-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smack</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smackx</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity-tools</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>vysper-admin-console</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <configuration>
+ <scanIntervalSeconds>10</scanIntervalSeconds>
+ <contextPath>/</contextPath>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java (added)
+++ mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.apache.vysper.console;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.jivesoftware.smackx.FormField;
+import org.jivesoftware.smackx.packet.AdHocCommandData;
+import org.jivesoftware.smackx.packet.DataForm;
+
+public class AdHocCommandDataBuilder {
+
+ public AdHocCommandData build(Map<String, String[]> parameters) {
+ AdHocCommandData commandData = new AdHocCommandData();
+ commandData.setSessionID(getSingleValue(parameters, AdminConsoleController.SESSION_FIELD));
+
+ DataForm form = new DataForm("submit");
+
+ for(Entry<String, String[]> entry : parameters.entrySet()) {
+ if(!AdminConsoleController.SESSION_FIELD.equals(entry.getKey())) {
+ FormField field = new FormField(entry.getKey());
+ for(String value : entry.getValue()) {
+ field.addValue(value);
+ }
+ form.addField(field);
+ }
+ }
+
+ commandData.setForm(form);
+
+ return commandData;
+ }
+
+ private String getSingleValue(Map<String, String[]> parameters, String name) {
+ String[] values = parameters.get(name);
+ if(values != null && values.length == 1) {
+ return values[0];
+ } else {
+ throw new IllegalArgumentException(name + " must contain exactly one value");
+ }
+ }
+
+}
Added: mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java (added)
+++ mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,205 @@
+/*
+ * 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.apache.vysper.console;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.packet.IQ.Type;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smackx.commands.AdHocCommand.Action;
+import org.jivesoftware.smackx.commands.AdHocCommand.Status;
+import org.jivesoftware.smackx.commands.AdHocCommandNote;
+import org.jivesoftware.smackx.packet.AdHocCommandData;
+import org.jivesoftware.smackx.packet.DataForm;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+@Controller
+public class AdminConsoleController {
+
+ private static final String MODEL_AUTHENTICATED = "authenticated";
+
+ public static final String SESSION_ATTRIBUTE = "smack.client";
+
+ public static final String SESSION_FIELD = "vysper-admingui-sessionid";
+
+ public static final List<String> COMMANDS = Arrays.asList(
+ "get-online-users-num",
+ "add-user",
+ "change-user-password"
+ );
+
+ private ConnectionConfiguration connectionConfiguration;
+
+ private AdHocCommandDataBuilder adHocCommandDataBuilder = new AdHocCommandDataBuilder();
+ private HtmlFormBuilder htmlFormBuilder = new HtmlFormBuilder();
+
+ @Autowired
+ public AdminConsoleController(ConnectionConfiguration connectionConfiguration) {
+ this.connectionConfiguration = connectionConfiguration;
+ }
+
+ @RequestMapping("/")
+ public ModelAndView index(HttpSession session) throws XMPPException {
+ ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE);
+ if(client == null) {
+ // login
+ return login();
+ } else {
+ ModelAndView mav = new ModelAndView("index");
+ mav.addObject(MODEL_AUTHENTICATED, getUserName(client));
+ return mav;
+ }
+ }
+
+ private String getUserName(XMPPConnection client) {
+ Entity entity = EntityImpl.parseUnchecked(client.getUser());
+ return entity.getBareJID().getFullQualifiedName();
+ }
+
+
+ @RequestMapping(value="/{command}", method=RequestMethod.GET)
+ public ModelAndView command(@PathVariable("command") String command, HttpSession session) throws XMPPException {
+ ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE);
+ if(client == null) {
+ // login
+ return login();
+ } else {
+ if(!COMMANDS.contains(command)) {
+ throw new ResourceNotFoundException();
+ }
+
+ AdHocCommandData requestCommand = new AdHocCommandData();
+ requestCommand.setType(Type.SET);
+ requestCommand.setFrom(client.getUser());
+ requestCommand.setTo(client.getServiceName());
+ requestCommand.setAction(Action.execute);
+ requestCommand.setNode("http://jabber.org/protocol/admin#" + command);
+
+ return sendRequestAndGenerateForm(command, client, requestCommand);
+ }
+ }
+
+ @RequestMapping(value="/{command}", method=RequestMethod.POST)
+ public ModelAndView submitCommand(@PathVariable("command") String command, HttpServletRequest request, HttpSession session) throws XMPPException {
+ ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE);
+ if(client == null) {
+ // login
+ return login();
+ } else {
+ System.out.println(request.getParameterMap());
+
+ @SuppressWarnings("unchecked")
+ AdHocCommandData requestCommand = adHocCommandDataBuilder.build(request.getParameterMap());
+ requestCommand.setType(Type.SET);
+ requestCommand.setFrom(client.getUser());
+ requestCommand.setTo(client.getServiceName());
+ requestCommand.setNode("http://jabber.org/protocol/admin#" + command);
+
+ return sendRequestAndGenerateForm(command, client, requestCommand);
+ }
+ }
+
+ private ModelAndView sendRequestAndGenerateForm(String command, ExtendedXMPPConnection client,
+ AdHocCommandData requestCommand) {
+ try {
+ Packet response = client.sendSync(requestCommand);
+
+ AdHocCommandData responseData = (AdHocCommandData) response;
+ DataForm form = responseData.getForm();
+
+ StringBuffer htmlForm = new StringBuffer();
+
+ for(AdHocCommandNote note : responseData.getNotes()) {
+ htmlForm.append("<p class='note " + note.getType() + "'>" + note.getValue() + "</p>");
+ }
+
+ htmlForm.append("<form action='' method='post'>");
+ htmlForm.append("<input type='hidden' name='" + SESSION_FIELD + "' value='" + responseData.getSessionID() + "' />");
+
+ htmlForm.append(htmlFormBuilder.build(form));
+ if(Status.executing.equals(responseData.getStatus())) {
+ htmlForm.append("<input type='submit' value='" + command + "' />");
+ } else if(Status.completed.equals(responseData.getStatus())) {
+ if(form == null || form.getFields() == null || !form.getFields().hasNext()) {
+ // no field, print success
+ htmlForm.append("<p>Command successful</p>");
+ }
+ }
+ htmlForm.append("</form>");
+ System.out.println(htmlForm);
+
+ ModelAndView mav = new ModelAndView("command");
+ mav.addObject(MODEL_AUTHENTICATED, getUserName(client));
+ mav.addObject("form", htmlForm.toString());
+ return mav;
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private ModelAndView login() {
+ return new ModelAndView("login");
+ }
+
+ protected ExtendedXMPPConnection createXMPPConnection() {
+ return new ExtendedXMPPConnection(connectionConfiguration);
+ }
+
+ @RequestMapping(value="/login", method=RequestMethod.POST)
+ public ModelAndView login(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session) {
+ ExtendedXMPPConnection client = createXMPPConnection();
+ try {
+ client.connect();
+ client.login(username, password);
+ session.setAttribute(SESSION_ATTRIBUTE, client);
+ return new ModelAndView("redirect:");
+ } catch (XMPPException e) {
+ ModelAndView mav = new ModelAndView("login");
+ mav.addObject("error", "Failed to login to server: " + e.getMessage());
+ return mav;
+ }
+ }
+
+ @RequestMapping(value="/logout")
+ public ModelAndView logout(HttpSession session) {
+ ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE);
+ if(client != null) {
+ client.disconnect();
+ session.removeAttribute(SESSION_ATTRIBUTE);
+ }
+ return new ModelAndView("redirect:");
+ }
+
+}
Added: mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java (added)
+++ mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,88 @@
+/*
+ * 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.apache.vysper.console;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import javax.security.auth.callback.CallbackHandler;
+
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.filter.PacketFilter;
+import org.jivesoftware.smack.packet.Packet;
+
+public class ExtendedXMPPConnection extends XMPPConnection {
+
+ public ExtendedXMPPConnection(ConnectionConfiguration config, CallbackHandler callbackHandler) {
+ super(config, callbackHandler);
+ }
+
+ public ExtendedXMPPConnection(ConnectionConfiguration config) {
+ super(config);
+ }
+
+ public ExtendedXMPPConnection(String serviceName, CallbackHandler callbackHandler) {
+ super(serviceName, callbackHandler);
+ }
+
+ public ExtendedXMPPConnection(String serviceName) {
+ super(serviceName);
+ }
+
+ public static class IdPacketFilter implements PacketFilter {
+ private String id;
+
+ public IdPacketFilter(String id) {
+ this.id = id;
+ }
+
+ public boolean accept(Packet packet) {
+ return id.equals(packet.getPacketID());
+ }
+ }
+
+ public static class SyncPacketListener implements PacketListener {
+ private LinkedBlockingQueue<Packet> queue;
+
+ public SyncPacketListener(LinkedBlockingQueue<Packet> queue) {
+ this.queue = queue;
+ }
+
+ public void processPacket(Packet packet) {
+ queue.offer(packet);
+ }
+ }
+
+ public Packet sendSync(Packet request) throws InterruptedException {
+ LinkedBlockingQueue<Packet> queue = new LinkedBlockingQueue<Packet>();
+ PacketListener listener = new SyncPacketListener(queue);
+ PacketFilter filter = new IdPacketFilter(request.getPacketID());
+
+ addPacketListener(listener, filter);
+ sendPacket(request);
+
+ Packet response = queue.poll(10000, TimeUnit.MILLISECONDS);
+ removePacketListener(listener);
+
+ return response;
+ }
+}
Added: mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java (added)
+++ mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,102 @@
+/*
+ * 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.apache.vysper.console;
+
+import java.util.Iterator;
+
+import org.jivesoftware.smackx.FormField;
+import org.jivesoftware.smackx.packet.DataForm;
+
+public class HtmlFormBuilder {
+
+ public String build(DataForm form) {
+ if(form == null) return "";
+
+ StringBuffer sb = new StringBuffer();
+ Iterator<String> instructions = form.getInstructions();
+ while(instructions.hasNext()) {
+ sb.append("<p class='instruction'>" + instructions.next() + "</p>");
+ }
+
+ Iterator<FormField> fields = form.getFields();
+ while(fields.hasNext()) {
+ FormField field = fields.next();
+ String type = field.getType();
+ System.out.println(type);
+ sb.append("<p>");
+ if("hidden".equals(type)) {
+ sb.append(hiddenFieldToHtml(field));
+ } else if("fixed".equals(type)) {
+ sb.append(fixedFieldToHtml(field));
+ } else if("jid-single".equals(type)) {
+ sb.append(jidSingleFieldToHtml(field));
+ } else if("text-single".equals(type)) {
+ sb.append(textSingleFieldToHtml(field));
+ } else if("text-private".equals(type)) {
+ sb.append(textPrivateFieldToHtml(field));
+ } else {
+ System.out.println("Unknown field type: " + type);
+ }
+ sb.append("</p>");
+ }
+
+ return sb.toString();
+ }
+
+ private String labelToHtml(FormField field) {
+ StringBuffer sb = new StringBuffer();
+ if(field.getLabel() != null) {
+ sb.append("<label>");
+ // TODO for
+ sb.append(field.getLabel());
+ sb.append("</label>");
+ }
+ return sb.toString();
+ }
+
+ private String hiddenFieldToHtml(FormField field) {
+ return labelToHtml(field) + "<input type='hidden' name='" + field.getVariable() + "' value='" + getSingleValue(field) + "' />";
+ }
+
+ private String fixedFieldToHtml(FormField field) {
+ return labelToHtml(field) + " <span>" + field.getValues().next() + "</span>";
+ }
+
+ private String jidSingleFieldToHtml(FormField field) {
+ return labelToHtml(field) + "<input name='" + field.getVariable() + "' value='" + getSingleValue(field) + "' />";
+ }
+
+ private String textSingleFieldToHtml(FormField field) {
+ return labelToHtml(field) + "<input name='" + field.getVariable() + "' value='" + getSingleValue(field) + "' />";
+ }
+
+ private String textPrivateFieldToHtml(FormField field) {
+ return labelToHtml(field) + "<input name='" + field.getVariable() + "' type='password' value='" + getSingleValue(field) + "' />";
+ }
+
+ private String getSingleValue(FormField field) {
+ if(field.getValues().hasNext()) {
+ return field.getValues().next();
+ } else {
+ return "";
+ }
+ }
+
+}
Added: mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ResourceNotFoundException.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ResourceNotFoundException.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ResourceNotFoundException.java (added)
+++ mina/vysper/trunk/server/admin-console/src/main/java/org/apache/vysper/console/ResourceNotFoundException.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,28 @@
+/*
+ * 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.apache.vysper.console;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+@ResponseStatus(value=HttpStatus.NOT_FOUND)
+public class ResourceNotFoundException extends RuntimeException {
+
+}
Added: mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/command.vm
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/command.vm?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/command.vm (added)
+++ mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/command.vm Tue Jan 11 23:00:20 2011
@@ -0,0 +1,19 @@
+#*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*#
+${form}
\ No newline at end of file
Added: mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/index.vm
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/index.vm?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/index.vm (added)
+++ mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/index.vm Tue Jan 11 23:00:20 2011
@@ -0,0 +1,20 @@
+#*
+ * 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.
+*#
+<h1>Welcome to the Vysper Admin console</h1>
+
Added: mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/layout.vm
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/layout.vm?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/layout.vm (added)
+++ mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/layout.vm Tue Jan 11 23:00:20 2011
@@ -0,0 +1,64 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+#*
+ * 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.
+*#
+<html>
+ <head>
+ <title>Apache Vysper Admin console</title>
+ <link rel="stylesheet" type="text/css" href="#springUrl("/resources/css/reset.css")" />
+ <link rel="stylesheet" type="text/css" href="#springUrl("/resources/css/typography.css")" />
+ <link rel="stylesheet" type="text/css" href="#springUrl("/resources/css/console.css")" />
+ </head>
+ <body>
+ <div id="main">
+ <div id="top">
+ <div id="top-left">
+ </div>
+ <div id="top-right">
+ #if($authenticated)
+ <span>Logged in as $authenticated.</span>
+ <span>
+ <a href="logout">
+ Log out
+ </a>
+ </span>
+ #end
+ </div>
+ </div>
+ <div class="clear"></div>
+ <div id="content">
+ <div id="center">
+ <div class="errorMessages">
+ #if ($error)
+ $error
+ #end
+ </div>
+ <div id="centerContent">
+ $screen_content
+ </div>
+ </div>
+ #if($authenticated)
+ <div id="left">
+ #parse("nav.vm")
+ </div>
+ #end
+ </div>
+ <div class="clear"> </div>
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/login.vm
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/login.vm?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/login.vm (added)
+++ mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/login.vm Tue Jan 11 23:00:20 2011
@@ -0,0 +1,23 @@
+#*
+ * 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.
+*#
+<form action="login" method="post">
+ <p><input name="username" value="admin@vysper.org" /></p>
+ <p><input name="password" type="password" value="password" /></p>
+ <p><input type="submit" value="Log in" /></p>
+</form>
\ No newline at end of file
Added: mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/nav.vm
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/nav.vm?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/nav.vm (added)
+++ mina/vysper/trunk/server/admin-console/src/main/resources/META-INF/velocity/nav.vm Tue Jan 11 23:00:20 2011
@@ -0,0 +1,21 @@
+#*
+ * 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.
+*#
+<a href="get-online-users-num">Get number of online users</a>
+<a href="add-user">Add user</a>
+<a href="change-user-password">Change user password</a>
\ No newline at end of file
Added: mina/vysper/trunk/server/admin-console/src/main/resources/bogus_mina_tls.cert
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/resources/bogus_mina_tls.cert?rev=1057909&view=auto
==============================================================================
Binary file - no diff available.
Propchange: mina/vysper/trunk/server/admin-console/src/main/resources/bogus_mina_tls.cert
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/console-servlet.xml
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/console-servlet.xml?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/console-servlet.xml (added)
+++ mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/console-servlet.xml Tue Jan 11 23:00:20 2011
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ /**
+ * Copyright 2010 Västra Götalandsregionen
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of version 2.1 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This library 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA
+ *
+ */
+
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:mvc="http://www.springframework.org/schema/mvc"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/mvc
+ http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
+
+ <mvc:resources location="classpath:/META-INF/" mapping="/resources/**" />
+
+ <mvc:annotation-driven/>
+
+ <context:component-scan base-package="org.apache.vysper.console"/>
+
+ <bean id="serverDomain" class="java.lang.String">
+ <constructor-arg value="vysper.org" />
+ </bean>
+
+ <bean class="org.jivesoftware.smack.ConnectionConfiguration">
+ <constructor-arg ref="serverDomain" />
+ <constructor-arg value="5222" />
+ <constructor-arg value="localhost" />
+ <property name="keystorePath" value="src/main/resources/bogus_mina_tls.cert" />
+ <property name="truststorePath" value="src/main/resources/bogus_mina_tls.cert" />
+ <property name="truststorePassword" value="boguspw" />
+ </bean>
+
+
+ <bean id="velocityConfig"
+ class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
+ <property name="resourceLoaderPath" value="classpath:/META-INF/velocity/" />
+ <property name="velocityProperties">
+ <props>
+ <prop key="input.encoding">utf-8</prop>
+ <prop key="output.encoding">utf-8 </prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean id="viewResolver"
+ class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
+ <property name="layoutUrl" value="layout.vm" />
+ <property name="screenContentKey" value="screen_content"/>
+ <property name="layoutKey" value="layout"/>
+ <!-- <property name="cache" value="true"/>-->
+ <property name="prefix" value="" />
+ <property name="suffix" value=".vm" />
+ <property name="contentType" value="text/html; charset=UTF-8" />
+ <property name="exposeRequestAttributes" value="true"/>
+ <property name="exposeSessionAttributes" value="true"/>
+ <property name="exposeSpringMacroHelpers" value="true"/>
+ </bean>
+
+
+</beans>
\ No newline at end of file
Added: mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/web.xml?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/web.xml (added)
+++ mina/vysper/trunk/server/admin-console/src/main/webapp/WEB-INF/web.xml Tue Jan 11 23:00:20 2011
@@ -0,0 +1,19 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+
+ <description>Apache Vysper Admin console</description>
+
+ <servlet>
+ <servlet-name>console</servlet-name>
+ <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>console</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Added: mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java (added)
+++ mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,107 @@
+/*
+ * 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.apache.vysper.console;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.jivesoftware.smack.XMPPException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.springframework.web.servlet.ModelAndView;
+
+
+public class AdminConsoleControllerTest {
+
+ private static final String ENTITY = "test@vysper.org";
+ private static final String PASSWORD = "password";
+
+ private ExtendedXMPPConnection connection = Mockito.mock(ExtendedXMPPConnection.class);
+
+ private AdminConsoleController controller = new AdminConsoleController(null) {
+ @Override
+ protected ExtendedXMPPConnection createXMPPConnection() {
+ return connection;
+ }
+ };
+
+ private HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ private MockHttpSession session = new MockHttpSession();
+
+ @Test
+ public void login() throws XMPPException {
+ ModelAndView mav = controller.login(ENTITY, PASSWORD, session);
+
+ Mockito.verify(connection).connect();
+ Mockito.verify(connection).login(ENTITY, PASSWORD);
+
+ Assert.assertNotNull(session.getAttribute(AdminConsoleController.SESSION_ATTRIBUTE));
+ Assert.assertEquals("redirect:", mav.getViewName());
+ }
+
+ @Test
+ public void failedLogin() throws XMPPException {
+ Mockito.doThrow(new XMPPException()).when(connection).login(ENTITY, PASSWORD);
+
+ ModelAndView mav = controller.login(ENTITY, PASSWORD, session);
+
+ Mockito.verify(connection).connect();
+ Mockito.verify(connection).login(ENTITY, PASSWORD);
+
+ Assert.assertNull(session.getAttribute(AdminConsoleController.SESSION_ATTRIBUTE));
+ Assert.assertEquals("login", mav.getViewName());
+ Assert.assertNotNull(mav.getModel().get("error"));
+ }
+
+ @Test
+ public void failedConnect() throws XMPPException {
+ Mockito.doThrow(new XMPPException()).when(connection).connect();
+
+ ModelAndView mav = controller.login(ENTITY, PASSWORD, session);
+
+ Mockito.verify(connection).connect();
+
+ Assert.assertNull(session.getAttribute(AdminConsoleController.SESSION_ATTRIBUTE));
+ Assert.assertEquals("login", mav.getViewName());
+ Assert.assertNotNull(mav.getModel().get("error"));
+ }
+
+ @Test
+ public void indexNotAuthenticated() throws XMPPException {
+ ModelAndView mav = controller.index(session);
+
+ Assert.assertEquals("login", mav.getViewName());
+ }
+
+ @Test
+ public void commandNotAuthenticated() throws XMPPException {
+ ModelAndView mav = controller.command("foo", session);
+
+ Assert.assertEquals("login", mav.getViewName());
+ }
+
+ @Test
+ public void submitCommandNotAuthenticated() throws XMPPException {
+ ModelAndView mav = controller.submitCommand("foo", request, session);
+
+ Assert.assertEquals("login", mav.getViewName());
+ }
+
+}
Added: mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/MockHttpSession.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/MockHttpSession.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/MockHttpSession.java (added)
+++ mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/MockHttpSession.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,99 @@
+/*
+ * 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.apache.vysper.console;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+
+public class MockHttpSession implements HttpSession {
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ public void setMaxInactiveInterval(int interval) {
+ }
+
+ public void setAttribute(String name, Object value) {
+ attributes.put(name, value);
+ }
+
+ public void removeValue(String name) {
+ removeAttribute(name);
+ }
+
+ public void removeAttribute(String name) {
+ attributes.remove(name);
+ }
+
+ public void putValue(String name, Object value) {
+ setAttribute(name, value);
+ }
+
+ public boolean isNew() {
+ return false;
+ }
+
+ public void invalidate() {
+
+ }
+
+ public String[] getValueNames() {
+ return null;
+ }
+
+ public Object getValue(String name) {
+ return getAttribute(name);
+ }
+
+ public HttpSessionContext getSessionContext() {
+ return null;
+ }
+
+ public ServletContext getServletContext() {
+ return null;
+ }
+
+ public int getMaxInactiveInterval() {
+ return 0;
+ }
+
+ public long getLastAccessedTime() {
+ return 0;
+ }
+
+ public String getId() {
+ return null;
+ }
+
+ public long getCreationTime() {
+ return 0;
+ }
+
+ public Enumeration getAttributeNames() {
+ return null;
+ }
+
+ public Object getAttribute(String name) {
+ return attributes.get(name);
+ }
+}
\ No newline at end of file
Added: mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/ServerMain.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/ServerMain.java?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/ServerMain.java (added)
+++ mina/vysper/trunk/server/admin-console/src/test/java/org/apache/vysper/console/ServerMain.java Tue Jan 11 23:00:20 2011
@@ -0,0 +1,98 @@
+/*
+ * 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.apache.vysper.console;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Arrays;
+
+import org.apache.vysper.mina.TCPEndpoint;
+import org.apache.vysper.storage.StorageProviderRegistry;
+import org.apache.vysper.storage.inmemory.MemoryStorageProviderRegistry;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.authorization.AccountCreationException;
+import org.apache.vysper.xmpp.authorization.AccountManagement;
+import org.apache.vysper.xmpp.modules.extension.xep0049_privatedata.PrivateDataModule;
+import org.apache.vysper.xmpp.modules.extension.xep0050_adhoc_commands.AdhocCommandsModule;
+import org.apache.vysper.xmpp.modules.extension.xep0054_vcardtemp.VcardTempModule;
+import org.apache.vysper.xmpp.modules.extension.xep0092_software_version.SoftwareVersionModule;
+import org.apache.vysper.xmpp.modules.extension.xep0119_xmppping.XmppPingModule;
+import org.apache.vysper.xmpp.modules.extension.xep0133_service_administration.ServiceAdministrationModule;
+import org.apache.vysper.xmpp.modules.extension.xep0202_entity_time.EntityTimeModule;
+import org.apache.vysper.xmpp.server.XMPPServer;
+
+/**
+ * starts the server as a standalone application
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
+public class ServerMain {
+
+ /**
+ * boots the server as a standalone application
+ *
+ * adding a module from the command line:
+ * using a runtime property, one or more modules can be specified, like this:
+ * -Dvysper.add.module=org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.PublishSubscribeModule,... more ...
+ *
+ * @param args
+ */
+ public static void main(String[] args) throws AccountCreationException, FileNotFoundException {
+
+ String domain = "vysper.org";
+
+ // choose the storage you want to use
+ StorageProviderRegistry providerRegistry = new MemoryStorageProviderRegistry();
+
+ final Entity adminJID = EntityImpl.parseUnchecked("admin@" + domain);
+ final AccountManagement accountManagement = (AccountManagement) providerRegistry
+ .retrieve(AccountManagement.class);
+
+ if (!accountManagement.verifyAccountExists(adminJID)) {
+ accountManagement.addUser(adminJID, "password");
+ }
+
+ XMPPServer server = new XMPPServer(domain);
+ server.addEndpoint(new TCPEndpoint());
+ //server.addEndpoint(new StanzaSessionFactory());
+ server.setStorageProviderRegistry(providerRegistry);
+
+ server.setTLSCertificateInfo(new File("src/main/resources/bogus_mina_tls.cert"), "boguspw");
+
+ try {
+ server.start();
+ System.out.println("vysper server is running...");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ server.addModule(new SoftwareVersionModule());
+ server.addModule(new EntityTimeModule());
+ server.addModule(new VcardTempModule());
+ server.addModule(new XmppPingModule());
+ server.addModule(new PrivateDataModule());
+ server.addModule(new AdhocCommandsModule());
+ final ServiceAdministrationModule serviceAdministrationModule = new ServiceAdministrationModule();
+ // unless admin user account with a secure password is added, this will be not become effective
+ serviceAdministrationModule.setAddAdminJIDs(Arrays.asList(adminJID));
+ server.addModule(serviceAdministrationModule);
+ }
+}
Added: mina/vysper/trunk/server/admin-console/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/admin-console/src/test/resources/log4j.properties?rev=1057909&view=auto
==============================================================================
--- mina/vysper/trunk/server/admin-console/src/test/resources/log4j.properties (added)
+++ mina/vysper/trunk/server/admin-console/src/test/resources/log4j.properties Tue Jan 11 23:00:20 2011
@@ -0,0 +1,28 @@
+# 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.
+
+log4j.rootLogger=INFO, C
+
+log4j.logger.stanza.client=DEBUG,C
+log4j.logger.stanza.server=DEBUG,C
+log4j.logger.org.apache.vysper.mina.XmppIoHandlerAdapter=WARN,C
+log4j.logger.org.apache.mina.filter.executor.ExecutorFilter=WARN,C
+
+log4j.appender.C=org.apache.log4j.ConsoleAppender
+log4j.appender.C.layout=org.apache.log4j.PatternLayout
+log4j.appender.C.layout.ConversionPattern=%c %p %m%n
+
Modified: mina/vysper/trunk/server/pom.xml
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/pom.xml?rev=1057909&r1=1057908&r2=1057909&view=diff
==============================================================================
--- mina/vysper/trunk/server/pom.xml (original)
+++ mina/vysper/trunk/server/pom.xml Tue Jan 11 23:00:20 2011
@@ -41,6 +41,7 @@
<modules>
<module>core</module>
<module>core-inttest</module>
+ <module>admin-console</module>
<module>extensions</module>
</modules>
</profile>