我想根据https://wiki.eclipse.org/Scout/Concepts/Security中找到的童子军默认安全概念进行身份验证。
我做了什么:
我添加BasicSecurityFilter
到服务器plugin.xml
:
<extension name="" point="org.eclipse.scout.rt.server.commons.filters">
<filter aliases="/ /process /remotefiles /updatesite" class="org.eclipse.scout.http.servletfilter.security.BasicSecurityFilter" ranking="30"></filter>
</extension>
并在以下位置激活它config.ini
:
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
在客户端,我添加InternalNetAuthenticator
了plugin.xml
:
<extension point="org.eclipse.core.net.authenticator">
<authenticator class="org.eclipse.scout.rt.ui.rap.login.internal.InternalNetAuthenticator"</authenticator>
</extension>
并将其设置为客户端中的默认身份验证器Activator
:
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
InternalNetAuthenticator authenticator = new InternalNetAuthenticator();
InternalNetAuthenticator.setDefault(authenticator);
}
怎么了:
BasicSecurityFilter.negotiate()
访问应用程序时调用(第一次加载,例如http://localhost:8015/web
)InternalNetAuthenticator.getPasswordAuthentication()
在协商BasicSecurityFilter
失败时调用(即在 HTTP 标头中找不到用户和密码,或者用户和密码无效)。InternalNetAuthenticator.showModalDialog(status, display)
不可能在 RAP 级别打开对话框(请参阅参考资料),因为 Display.getDefault() 或 Display.getCurrent() 总是返回null
。- 这是因为所有 UI 操作(例如打开对话框)都必须出现在 UIThread 中(参见参考资料中的 java-doc
Display.getDefault()
)。 InternalNetAuthenticator
是在 UIThread中实例化的(请参阅 参考资料Activator.start()
),但它不在UIThread 中调用!为什么???
- 这是因为所有 UI 操作(例如打开对话框)都必须出现在 UIThread 中(参见参考资料中的 java-doc
- 返回一个
PasswordAuthentication
对象将 HTTP 标头中的凭据提供给下一次BasicSecurityFilter.negotiate()
调用。
BasicSecurityFilter.negotiate()
使用给定的凭据再次调用。
什么失败:
因此,由于InternalNetAuthenticator.showModalDialog(status, display)
没有在 UI 线程中调用,它会导致NullPointerException
:
java.lang.NullPointerException
at org.eclipse.scout.rt.ui.rap.login.internal.InternalNetAuthenticator.showModalDialog(InternalNetAuthenticator.java:102)
...
我已经考虑过的:
- 一般信息
https://wiki.eclipse.org/Scout/HowTo/3.9/Extending_the_login_dialog
https://wiki.eclipse.org/Scout/Concepts/Securit
- UI线程问题
https://www.eclipse.org/forums/index.php/t/440290/
https://www.eclipse.org/rap/developers-guide/devguide.php?topic=threads.html
Activator.start()
在方法中实例化 Authenticator 时,我已经尝试通过创建自己的 Authenticator 并向构造函数添加参数来 存储 UI 线程,例如:MyAuthenticator my_authenticator = new MyAuthenticator(Thread.currentThread());
- 但这会导致
IllegelStateException
类似的事情。因此,无法通过这种方式访问 UI 线程。
- 使用
BasicSecurityFilter
RAP 级别(在plugin.xml
RAP 捆绑包中)可以使用系统默认登录对话框。- 但我想有一个自定义的 SecurityFilter 可以访问其他服务器端系统,所以它必须出现在服务器端,RAP/客户端 SecurityFilter 不是选项!
概括
我所能看到的是,用 UI 线程解决问题将是推动这个问题的首选方法。
我还将接受在我的 eclipse-scout-RAP 环境中使用自定义登录对话框的替代解决方案。