title: Authentication via login dialog in Scout (RAP)
body: <p>I'd like to have an authentication based on scouts default security concept found in <a href="https://wiki.eclipse.org/Scout/Concepts/Security" rel="nofollow">https://wiki.eclipse.org/Scout/Concepts/Security</a>.</p>
  
  <p><strong>What I've done:</strong></p>
  
  <p>I added the <code>BasicSecurityFilter</code> to the servers <code>plugin.xml</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;extension name="" point="org.eclipse.scout.rt.server.commons.filters"&gt;
        &lt;filter aliases="/ /process /remotefiles /updatesite" class="org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter" ranking="30"&gt;&lt;/filter&gt;
  &lt;/extension&gt;
  </code></pre>
  
  <p>And activated it in the <code>config.ini</code>:</p>
  
  <pre><code>org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter#active=true
  org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter#realm=Development
  org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter#users=TEST\=admin
  </code></pre>
  
  <p>On client side I added the <code>InternalNetAuthenticator</code> in the <code>plugin.xml</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;extension point="org.eclipse.core.net.authenticator"&gt;
      &lt;authenticator class="org.eclipse.scout.rt.ui.rap.login.internal.InternalNetAuthenticator"&lt;/authenticator&gt;
  &lt;/extension&gt;
  </code></pre>
  
  <p>And set it as default authenticator in the client <code>Activator</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    InternalNetAuthenticator authenticator = new InternalNetAuthenticator();
    InternalNetAuthenticator.setDefault(authenticator);
  }
  </code></pre>
  
  <p><strong>What happens:</strong></p>
  
  <ul>
  <li><code>BasicSecurityFilter.negotiate()</code> is called when accessing the application (first load, e.g. <code>http://localhost:8015/web</code>)</li>
  <li><code>InternalNetAuthenticator.getPasswordAuthentication()</code> is called when the negotiation in the <code>BasicSecurityFilter</code> fails (this is when user and password are not found in the HTTP header, or user and password are invalid).
  
  <ul>
  <li>Opening a Dialog on RAP level (see <code>InternalNetAuthenticator.showModalDialog(status, display)</code>) is impossible, because Display.getDefault() or Display.getCurrent() always returns <code>null</code>.
  
  <ul>
  <li>This is because all UI operations (e.g. opening a dialog) MUST appear in the UIThread (see java-doc in <code>Display.getDefault()</code>).</li>
  <li>The <code>InternalNetAuthenticator</code> is <em>instantiated</em> in the UIThread (see <code>Activator.start()</code>), but it isn't <em>called</em> in the UIThread! <strong>Why???</strong></li>
  </ul></li>
  <li>Returning a <code>PasswordAuthentication</code> object provides the credentials within the HTTP header to the next <code>BasicSecurityFilter.negotiate()</code> call.</li>
  </ul></li>
  <li><code>BasicSecurityFilter.negotiate()</code>is called again with the given credentials.</li>
  </ul>
  
  <p><strong>What fails:</strong></p>
  
  <p>So because of the fact, that the <code>InternalNetAuthenticator.showModalDialog(status, display)</code> isn't called in the UI-thread, it causes a <code>NullPointerException</code>:</p>
  
  <pre><code>java.lang.NullPointerException
      at org.eclipse.scout.rt.ui.rap.login.internal.InternalNetAuthenticator.showModalDialog(InternalNetAuthenticator.java:102)
  ...
  </code></pre>
  
  <p><strong>What I've already considered:</strong></p>
  
  <ul>
  <li>General information
  
  <ul>
  <li><code>https://wiki.eclipse.org/Scout/HowTo/3.9/Extending_the_login_dialog</code></li>
  <li><code>https://wiki.eclipse.org/Scout/Concepts/Securit</code></li>
  </ul></li>
  <li>UI-thread problem
  
  <ul>
  <li><code>https://www.eclipse.org/forums/index.php/t/440290/</code></li>
  <li><code>https://www.eclipse.org/rap/developers-guide/devguide.php?topic=threads.html</code></li>
  <li>I already tried to store the UI-thread when instantiating the Authenticator in the <code>Activator.start()</code> method by creating an own Authenticator and adding a parameter to the constructor like:
  
  <ul>
  <li><code>MyAuthenticator my_authenticator = new MyAuthenticator(Thread.currentThread());</code></li>
  <li>But this causes an <code>IllegelStateException</code> or something like that. So the UI-thread is not accessible on this way.</li>
  </ul></li>
  <li>Using the <code>BasicSecurityFilter</code> on RAP-level (in <code>plugin.xml</code> of the RAP bundle) makes it possible to use the systems default login dialog.
  
  <ul>
  <li>But I would like to have a custom SecurityFilter which have acces to other server side systems, so it must appear on server side and a RAP/client side SecurityFilter is no option!</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p><strong>Summary</strong></p>
  
  <p>All I can see is, that solving the Problem with the UI-thread will be the preferred way to move this issue forward. </p>
  
  <p>I'll also accept alternative solutions to have a custom login dialog in my eclipse-scout-RAP environment.</p>