【问题标题】:setDefaultAuthenticator causes a java.security.AccessControlException in GWT web applicationsetDefaultAuthenticator 在 GWT Web 应用程序中导致 java.security.AccessControlException
【发布时间】:2011-09-07 23:17:18
【问题描述】:

我正在使用 GWT 创建一个 Web 应用程序,服务器向客户端提供服务。在此服务中,它必须生成一个 HTTP 请求到另一个具有身份验证的服务器。以下代码描述了如何发出请求:

public int request()
{
    Authenticator.setDefault(new MyAuthenticator(username, password));
    try {
        URL url = new URL(url_string);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("Content-Type", "text/xml");
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(buildRequest());
        wr.flush();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        //the rest is to handle the response ...

    } catch (Exception e) {
        //handle exception
    }
}

MyAuthenticator 是按照建议的here 实现的,我测试了代码,它就像一个魅力,但是当我尝试将它合并到 GWT 项目中时,我遇到了一个异常:

//huge stack trace above ... what is important is the following
Caused by: java.security.AccessControlException: access denied (java.net.NetPermission setDefaultAuthenticator)

有什么办法解决这个问题吗?

【问题讨论】:

    标签: java exception gwt httprequest policy


    【解决方案1】:

    我可以看到两种情况:

    1. 您正在使用 AppEngine 运行它。我相信它不会起作用。
    2. 您在 GWT 的客户端使用它。将其移至服务器端。

    【讨论】:

    • 其实我正在运行这个代码服务器端。但是,我阅读了一些关于写权限授予的内容,但我不知道是否可以使用 GAE。
    【解决方案2】:

    显然GAE确实允许Authenticator,这就是我得到这个异常的原因,发现了类似的问题here,解决方案是按照建议手动添加身份验证标头here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 2017-01-03
      • 2023-02-02
      • 2011-09-12
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多