* remove activator class, not needed.

* remove use of non-official sun api from BrowserToken.
* change bundle version to 1.0.0.qualifier.
This commit is contained in:
Heng Sin Low 2010-07-15 03:05:48 +08:00
parent 456b168e9b
commit e0f1a979f9
5 changed files with 25 additions and 113 deletions

View File

@ -34,7 +34,7 @@
<classpathentry kind="lib" path="WEB-INF/lib/zweb.jar" sourcepath="WEB-INF/lib/zweb-sources.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/cglib.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/fckez.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="WEB-INF/classes"/>
</classpath>

View File

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.adempiere.webui
Bundle-SymbolicName: org.adempiere.webui;singleton:=true
Bundle-Version: 0.0.0.2
Bundle-Version: 1.0.0.qualifier
Web-ContextPath: webui
Bundle-ClassPath: WEB-INF/classes/,
WEB-INF/lib/zk.jar,
@ -365,15 +365,13 @@ Export-Package: junit.extensions,
web.zul.img.vd,
web.zul.img.wnd
Eclipse-RegisterBuddy: org.adempiere.tools
Require-Bundle: org.eclipse.osgi.services;bundle-version="3.1.100",
org.eclipse.core.runtime;bundle-version="3.5.0",
org.apache.xerces;bundle-version="2.9.0",
Require-Bundle: org.apache.xerces;bundle-version="2.9.0",
org.apache.xml.serializer;bundle-version="2.7.1",
com.springsource.javax.servlet;bundle-version="2.5.0",
org.adempiere.JasperReports;bundle-version="1.0.0",
org.adempiere.client;bundle-version="0.0.0",
org.adempiere.base;bundle-version="0.0.0",
org.adempiere.tools;bundle-version="0.0.0",
org.adempiere.client;bundle-version="1.0.0",
org.adempiere.base;bundle-version="1.0.0",
org.adempiere.tools;bundle-version="1.0.0",
org.adempiere.JasperReportsTools;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Eclipse-ExtensibleAPI: true

View File

@ -1,87 +0,0 @@
package org.adempiere.webui;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.adempiere.webui.session.WebUIServlet;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.util.tracker.ServiceTracker;
import org.zkoss.zk.au.http.DHtmlUpdateServlet;
public class Activator extends Plugin {
private ServiceTracker httpServiceTracker;
public void start(BundleContext context) throws Exception {
System.out.println("Starting WebUI");
httpServiceTracker = new HttpServiceTracker(context);
httpServiceTracker.open();
}
public void stop(BundleContext context) throws Exception {
System.out.println("Stopping WebUI");
httpServiceTracker.close();
httpServiceTracker = null;
}
private class HttpServiceTracker extends ServiceTracker {
private BundleContext context;
public HttpServiceTracker(BundleContext context) {
super(context, HttpService.class.getName(), null);
this.context = context;
}
public Object addingService(ServiceReference reference) {
HttpService httpService = (HttpService) context.getService(reference);
System.out.println("Adding zkLoader: "+httpService);
try {
// MappingServlet mapping = new MappingServlet();
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("update-uri", "/zkau");
HttpContext ctx = httpService.createDefaultHttpContext();
WebUIServlet webuiServlet = new WebUIServlet();
httpService.registerServlet("/*.zul", webuiServlet, params , ctx); //$NON-NLS-1$
DelegatingServlet updateServlet = new DelegatingServlet(new DHtmlUpdateServlet()) {
private ServletConfig cfg;
@Override
public void init(ServletConfig config)
throws ServletException {
super.init(config);
cfg = config;
}
@Override
public ServletConfig getServletConfig() {
return cfg;
}
};
httpService.registerServlet("/zkau", updateServlet, params , ctx); //$NON-NLS-1$
// httpService.registerServlet("/*.zhtml", webuiServlet, params , ctx); //$NON-NLS-1$
httpService.registerResources("/", "/WebContent", ctx);
httpService.registerResources("/WEB-INF/zk.xml", "/zk.xml", ctx);
System.out.println("zkLoader added: " + httpService.toString());
} catch (Exception e) {
e.printStackTrace();
}
return httpService;
}
public void removedService(ServiceReference reference, Object service) {
HttpService httpService = (HttpService) service;
httpService.unregister("/"); //$NON-NLS-1$
System.out.println("zkLoader removedss: " + httpService.toString());
super.removedService(reference, service);
}
}
}

View File

@ -19,6 +19,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import org.apache.commons.codec.binary.Base64;
import org.compiere.Adempiere;
import org.compiere.model.MSession;
import org.compiere.model.MSystem;
@ -27,8 +28,6 @@ import org.compiere.util.CLogger;
import org.zkoss.zk.au.out.AuScript;
import org.zkoss.zk.ui.util.Clients;
import sun.misc.BASE64Encoder;
/**
* class to manage browser token for auto authentication
* @author hengsin
@ -37,9 +36,9 @@ import sun.misc.BASE64Encoder;
public final class BrowserToken {
private final static CLogger log = CLogger.getCLogger(BrowserToken.class);
private BrowserToken() {}
public final static String REMEMBER_ME = "Login.RememberMe";
/**
* save session and user as client side token for future auto login
@ -47,20 +46,20 @@ public final class BrowserToken {
* @param user
*/
public static void save(MSession session, MUser user) {
try
try
{
String home = getHomeToken();
String hash = getPasswordHash(session, user);
String script = "adempiere.saveUserToken('" + home + "', '" + hash + "', '" + session.getAD_Session_ID() + "');";
AuScript aus = new AuScript(null, script);
Clients.response("saveUserToken", aus);
}
}
catch (Exception e)
{
log.log(Level.WARNING, e.getLocalizedMessage(), e);
}
}
/**
* remove client side token for auto login
*/
@ -93,7 +92,7 @@ public final class BrowserToken {
log.log(Level.WARNING, e.getLocalizedMessage(), e);
}
}
/**
* validate a stored client side token is valid
* @param session
@ -102,7 +101,7 @@ public final class BrowserToken {
* @return true if token is valid
*/
public static boolean validateToken(MSession session, MUser user, String token) {
try
try
{
String hash = getPasswordHash(session, user);
return hash.equals(token);
@ -110,21 +109,21 @@ public final class BrowserToken {
catch (Exception e)
{
log.log(Level.WARNING, e.getLocalizedMessage(), e);
}
}
return false;
}
private static String getHomeToken() throws UnsupportedEncodingException {
String home = Adempiere.getAdempiereHome();
BASE64Encoder encoder = new BASE64Encoder();
home = encoder.encode(home.getBytes("UTF-8"));
String home = Adempiere.getAdempiereHome();
Base64 encoder = new Base64();
home = new String(encoder.encode(home.getBytes("UTF-8")), "UTF-8");
home = URLEncoder.encode(home, "UTF-8");
return home;
}
private static String getPasswordHash(MSession session, MUser user) throws UnsupportedEncodingException, NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-512");
BASE64Encoder encoder = new BASE64Encoder();
Base64 encoder = new Base64();
digest.reset();
digest.update(session.getWebSession().getBytes("UTF-8"));
String password = null;
@ -133,9 +132,9 @@ public final class BrowserToken {
else
password = new String("");
byte[] input = digest.digest(password.getBytes("UTF-8"));
String hash = encoder.encode(input);
String hash = new String(encoder.encode(input), "UTF-8");
hash = URLEncoder.encode(hash, "UTF-8");
return hash;
}
}

View File

@ -1,3 +1,5 @@
source.. = WEB-INF/src/
output.. = WEB-INF/classes/
bin.includes = META-INF/,\
WEB-INF/,\
css/,\