From d3e86e83b169f78b6641986e2018f474f04cf6ec Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 6 Oct 2014 17:53:11 +0200 Subject: [PATCH] register the UserManagementService in gwt.ui bundle's web.xml, solving the cross-bundle RPC issue --- java/com.sap.sailing.gwt.ui/WEB-INF/web.xml | 10 ++++++ .../META-INF/MANIFEST.MF | 3 +- java/com.sap.sse.security.ui/WEB-INF/web.xml | 1 - .../security/ui/loginpanel/LoginPanel.java | 6 ---- .../ui/server/UserManagementServiceImpl.java | 31 +++++++++++++++++++ 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml b/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml index 74c49dbb0d6..b0f1e23c1e4 100755 --- a/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml +++ b/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml @@ -90,6 +90,16 @@ DataMiningService /service/datamining + + User Management Service + UserManagementService + com.sap.sse.security.ui.server.UserManagementServiceImpl + + + UserManagementService + /service/usermanagement + + diff --git a/java/com.sap.sailing.server.test/META-INF/MANIFEST.MF b/java/com.sap.sailing.server.test/META-INF/MANIFEST.MF index 80cad9632f7..dd2beaa78c6 100644 --- a/java/com.sap.sailing.server.test/META-INF/MANIFEST.MF +++ b/java/com.sap.sailing.server.test/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: com.sap.sailing.domain, org.junit4;bundle-version="4.8.2", com.sap.sailing.domain.test, org.mockito.mockito-core;bundle-version="1.9.5", - com.sap.sse.common + com.sap.sse.common, + org.eclipse.jetty.server;bundle-version="9.2.2" Import-Package: com.sap.sailing.server.gateway.jaxrs, com.sap.sailing.server.gateway.jaxrs.spi, org.json.simple, diff --git a/java/com.sap.sse.security.ui/WEB-INF/web.xml b/java/com.sap.sse.security.ui/WEB-INF/web.xml index 9d293cacd01..ec5e6d81a40 100644 --- a/java/com.sap.sse.security.ui/WEB-INF/web.xml +++ b/java/com.sap.sse.security.ui/WEB-INF/web.xml @@ -31,7 +31,6 @@ ERROR - User Management Service UserManagementService diff --git a/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/loginpanel/LoginPanel.java b/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/loginpanel/LoginPanel.java index 8c70750a93c..8adef0b3aef 100644 --- a/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/loginpanel/LoginPanel.java +++ b/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/loginpanel/LoginPanel.java @@ -44,7 +44,6 @@ public class LoginPanel extends FlowPanel implements UserStatusEventHandler { static { EntryPointHelper.registerASyncService((ServiceDefTarget) userManagementService, - RemoteServiceMappingConstants.WEB_CONTEXT_PATH, RemoteServiceMappingConstants.userManagementServiceRemotePath); } @@ -103,7 +102,6 @@ public class LoginPanel extends FlowPanel implements UserStatusEventHandler { infoPanel.setWidget(loginPanel); wrapperPanel.add(infoPanel); add(wrapperPanel); - addUserStatusEventHandler(this); registerStorageListener(); updateUser(); @@ -112,11 +110,9 @@ public class LoginPanel extends FlowPanel implements UserStatusEventHandler { private void initLoginContent() { loginPanel = new FormPanel(); loginPanel.addSubmitHandler(new SubmitHandler() { - @Override public void onSubmit(SubmitEvent event) { userManagementService.login(name.getText(), password.getText(), new AsyncCallback() { - @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); @@ -134,9 +130,7 @@ public class LoginPanel extends FlowPanel implements UserStatusEventHandler { }); } }); - FlowPanel formContent = new FlowPanel(); - Label nameLabel = new Label("Name: "); formContent.add(nameLabel); name = new TextBox(); diff --git a/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/server/UserManagementServiceImpl.java b/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/server/UserManagementServiceImpl.java index b12667ac192..361b72c9b03 100644 --- a/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/server/UserManagementServiceImpl.java +++ b/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/server/UserManagementServiceImpl.java @@ -1,5 +1,8 @@ package com.sap.sse.security.ui.server; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -14,6 +17,7 @@ import java.util.concurrent.FutureTask; import java.util.logging.Level; import java.util.logging.Logger; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.shiro.SecurityUtils; @@ -23,6 +27,7 @@ import org.osgi.framework.BundleContext; import org.osgi.util.tracker.ServiceTracker; import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.google.gwt.user.server.rpc.SerializationPolicy; import com.sap.sse.security.Credential; import com.sap.sse.security.SecurityService; import com.sap.sse.security.SessionUtils; @@ -86,6 +91,32 @@ public class UserManagementServiceImpl extends RemoteServiceServlet implements U return "Hello"; } + @Override + protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL, + String strongName) { + final String emulatedContextPath = "/"+(moduleBaseURL.split("/")[3]); + try { + final Method getContextPath = HttpServletRequest.class.getDeclaredMethod("getContextPath"); + HttpServletRequest proxyRequestAnsweringWithEmulatedContextPath = (HttpServletRequest) Proxy + .newProxyInstance(request.getClass().getClassLoader(), new Class[] { HttpServletRequest.class }, + new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (method.equals(getContextPath)) { + return emulatedContextPath; + } else { + return method.invoke(proxy, args); + } + } + }); + return super.doGetSerializationPolicy(proxyRequestAnsweringWithEmulatedContextPath, moduleBaseURL, strongName); + } catch (NoSuchMethodException | SecurityException e) { + logger.log(Level.SEVERE, "Error obtaining serialization policy for " + request + " with moduleBaseURL " + + moduleBaseURL, e); + throw new RuntimeException(e); + } + } + @Override public Collection getUserList() { List users = new ArrayList<>();