HiromuHota / pentaho-kettle

webSpoon is a web-based graphical designer for Pentaho Data Integration with the same look & feel as Spoon
https://hub.docker.com/r/hiromuhota/webspoon/
Apache License 2.0
502 stars 192 forks source link

Login page for Google Drive does not pop up #107

Closed HiromuHota closed 5 years ago

HiromuHota commented 6 years ago

Expected Behavior

A window pops up like this:

screen shot 2018-06-11 at 9 27 54 am

Actual Behavior

The window does not pop up, but the following error occurs.

<!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Image is disposed</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p
<pre>java.lang.IllegalArgumentException: Image is disposed
    org.eclipse.rap.rwt.remote.JsonMapping.toJson(JsonMapping.java:185)
    org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil.renderProperty(WidgetLCAUtil.java:424)
    org.eclipse.swt.internal.widgets.shellkit.ShellLCA.renderImage(ShellLCA.java:198)
    org.eclipse.swt.internal.widgets.shellkit.ShellLCA.renderChanges(ShellLCA.java:121)
    org.eclipse.swt.internal.widgets.shellkit.ShellLCA.renderChanges(ShellLCA.java:1)
    org.eclipse.rap.rwt.internal.lifecycle.WidgetLCA.render(WidgetLCA.java:40)
    org.eclipse.swt.internal.widgets.displaykit.DisplayLCA$RenderVisitor.render(DisplayLCA.java:318)
    org.eclipse.swt.internal.widgets.displaykit.DisplayLCA$RenderVisitor.visit(DisplayLCA.java:302)
    org.eclipse.swt.internal.widgets.WidgetTreeUtil.accept(WidgetTreeUtil.java:32)
    org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.renderShells(DisplayLCA.java:175)
    org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.render(DisplayLCA.java:101)
    org.eclipse.rap.rwt.internal.lifecycle.Render.execute(Render.java:32)
    org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.continueLifeCycle(RWTLifeCycle.java:155)
    org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.sleep(RWTLifeCycle.java:229)
    org.eclipse.swt.widgets.Display.sleep(Display.java:1258)
    org.eclipse.rap.rwt.application.AbstractEntryPoint.createUI(AbstractEntryPoint.java:70)
    org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:177)
    org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:290)
    java.lang.Thread.run(Thread.java:748)
    org.eclipse.rap.rwt.internal.lifecycle.UIThread.run(UIThread.java:107)
</pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p><hr class="line" /><h3>Apache Tomcat/8.5.31</h3></body></html>

Steps to Reproduce the Problem

As described in https://t.co/XylJLOoKjD

  1. Copy client_secret.json to plugins/pentaho-googledrive-vfs/credentials
    1. File -> Open URL

Specifications

Server

HiromuHota commented 6 years ago

Workaround

  1. Use Spoon to get authenticated. StoredCredential will be created at plugins/pentaho-googledrive-vfs/credentials
  2. Copy client_secret.json and StoredCredential from Spoon to webSpoon.
HiromuHota commented 5 years ago

GoogleAuthorizationDialog.java violates one of the anti-pattern in webSpoon (ie https://github.com/HiromuHota/pentaho-kettle/wiki/Dev%3A-Antipatterns-in-webSpoon#example-use-of-the-static-modifier-for-session-unique-instances). The following code fixes it.

$ git diff
diff --git a/plugins/pentaho-googledrive-vfs/core/src/main/java/org/pentaho/googledrive/vfs/ui/GoogleAuthorizationDialog.java b/plugins/pentaho-googledrive-vfs/core/src/main/java/org/pentaho/googledrive/vfs/ui/GoogleAuthorizationDialog.java
index e9f69bef0c..5f84983f5c 100644
--- a/plugins/pentaho-googledrive-vfs/core/src/main/java/org/pentaho/googledrive/vfs/ui/GoogleAuthorizationDialog.java
+++ b/plugins/pentaho-googledrive-vfs/core/src/main/java/org/pentaho/googledrive/vfs/ui/GoogleAuthorizationDialog.java
@@ -43,7 +43,7 @@ public class GoogleAuthorizationDialog extends Dialog {
   protected Display display;

   private static final int OPTIONS = SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM;
-  private static final Image LOGO = GUIResource.getInstance().getImageLogoSmall();
+  private final Image LOGO = GUIResource.getInstance().getImageLogoSmall();
   private VerificationCodeReceiver receiver;

   public GoogleAuthorizationDialog( Shell shell, VerificationCodeReceiver receiver ) {
HiromuHota commented 5 years ago

But now we can another problem.

The following error is shown at the browser's console,

Refused to display 'https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=500042598218-oj0mf6hb1nk2k3eq5qcrpmai7js3ovc5.apps.googleusercontent.com&redirect_uri=http://localhost:53544/Callback/success.html&response_type=code&scope=https://www.googleapis.com/auth/drive' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

This means that the Google page restricts itself from being embedded in an external page to prevent a clickjacking and most modern browsers respect 'X-Frame-Options'. This is not the case for Spoon because the Browser widget in SWT is not a modern browser, while the Browser widget in RWT is an iframe (see here for details) hence is restricted by the option.

HiromuHota commented 5 years ago

b1ada947e90200e14157590f1d542f0c8ae90fab in branch fix/107 can solve the 'X-Frame-Options' issue. But the current implementation (b1ada947e90200e14157590f1d542f0c8ae90fab) has a limitation that the host of the callback url is always 'localhost'. I would not merge this branch because

  1. The workaround is good enough.
  2. The authentication is just one time.
  3. It is not worth even more effort to make b1ada947e90200e14157590f1d542f0c8ae90fab host-agnostic.

Though I'm not merging it for now, I will put the branch in a public space in case someone may find it useful as-is or can submit a pull-request in a better shape.