【问题标题】:Java Agent in Lotus Notes thrwoing "java.security.AccessControlException" ExceptionLotus Notes 中的 Java 代理引发“java.security.AccessControlException”异常
【发布时间】:2016-02-01 17:00:42
【问题描述】:

显然,我正在尝试使用 Google 自定义搜索 API 在 google 中进行搜索。我在 Lotus Notes 中制作了这个 Java 代理。

主类:

import java.util.List;
import lotus.domino.AgentBase;
import com.google.api.services.customsearch.model.Result;
public class JavaAgent extends AgentBase {
    public void NotesMain() {
        GoogleSearchClient gsc = new GoogleSearchClient();
        String searchKeyWord = "test";
        List<Result> resultList =    gsc.getSearchResult(searchKeyWord);
        if(resultList != null && resultList.size() > 0){
            for(Result result: resultList){
                System.out.println(result.getHtmlTitle());
                System.out.println(result.getFormattedUrl());
                System.out.println("----------------------------------------");
            }
        }
    }
}

这就是 GoogleSearchClient 类:

import java.util.Collections;
import java.util.List;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.customsearch.Customsearch;
import com.google.api.services.customsearch.model.Result;
import com.google.api.services.customsearch.model.Search;
public class GoogleSearchClient {
    public List<Result> getSearchResult(String keyword){
        String GOOGLE_SEARCH_URL = https://www.googleapis.com/customsearch/v1?";
        //api key
        String API_KEY = "xxxxxxxxxxxxxxxxxxxxx";
        //custom search engine ID
        String SEARCH_ENGINE_ID = "xxxxxxxxxx:xxxxxxxxxxxx";
        String FINAL_URL= GOOGLE_SEARCH_URL + "key=" + API_KEY + "&cx=" + SEARCH_ENGINE_ID;
        // Set up the HTTP transport and JSON factory
        HttpTransport httpTransport = new NetHttpTransport();
        JsonFactory jsonFactory = new com.google.api.client.json.jackson2.JacksonFactory();
        //HttpRequestInitializer initializer = (HttpRequestInitializer)new CommonGoogleClientRequestInitializer(API_KEY);
        Customsearch customsearch = new Customsearch(httpTransport, jsonFactory,null);

        List<Result> resultList = Collections.emptyList();
        try {
            Customsearch.Cse.List list = customsearch.cse().list(keyword);
            list.setKey(API_KEY);
            list.setCx(SEARCH_ENGINE_ID);
            //num results per page
            //list.setNum(2L);

            //for pagination
            list.setStart(10L);
            Search results = list.execute();
            resultList = results.getItems();

        }catch (Exception e) {
            e.printStackTrace();
        }
        return resultList;
    }
}

我有代码here

这会返回这个异常:

java.security.AccessControlException: Access denied (java.lang.reflect.ReflectPermission suppressAccessChecks)
    at java.security.AccessController.throwACE(AccessController.java:100)
    at java.security.AccessController.checkPermission(AccessController.java:174)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:544)
    at COM.ibm.JEmpower.applet.AppletSecurity.superDotCheckPermission(AppletSecurity.java:1449)
    at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1617)
    at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1464)
    at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:118)
    at com.google.api.client.util.FieldInfo.of(FieldInfo.java:97)
    at com.google.api.client.util.ClassInfo.<init>(ClassInfo.java:172)
    at com.google.api.client.util.ClassInfo.of(ClassInfo.java:90)
    at com.google.api.client.util.GenericData.<init>(GenericData.java:79)
    at com.google.api.client.util.GenericData.<init>(GenericData.java:61)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.<init>(AbstractGoogleClientRequest.java:109)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.<init>(AbstractGoogleJsonClientRequest.java:57)
    at com.google.api.services.customsearch.CustomsearchRequest.<init>(CustomsearchRequest.java:43)
    at com.google.api.services.customsearch.Customsearch$Cse$List.<init>(Customsearch.java:178)
    at com.google.api.services.customsearch.Customsearch$Cse.list(Customsearch.java:154)
    at GoogleSearchClient.getSearchResult(Unknown Source)
    at JavaAgent.NotesMain(Unknown Source)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)

我在互联网上挖掘了这个异常,我明白 JVM 不认为我有特权并尝试了一些事情。

  1. 我在本地机器和服务器的“Java.policy”存档中添加了以下权限,但它不起作用。

    grant { permission java.util.PropertyPermission "http.keepAlive", "read, write"; };
    grant { permission java.security.AllPermission; } 
    
  2. 我会尝试this,但我的软件版本是 9。

  3. 我在 Eclipse 中尝试了相同的代码,它工作得很好,所以我认为这是错误的 Notes 安全配置。我必须在 Lotus Notes 中做,因为我必须将信息保存在表单等中。

  4. 我将运行时安全级别更改为 3(允许具有完全管理权限的受限操作)

有什么想法可以解决这个问题吗?

【问题讨论】:

    标签: java lotus-notes javaagents


    【解决方案1】:

    当我在 Lotus 中为我的 Web 服务使用者开发 WS-Security 时,我遇到了同样的错误。我发现可以通过在我的.jar 文件中使用AccessController.doPrivileged 方法来避免这种情况。因此,您需要在 IDE 中创建单独的 .jar 并在 Lotus 代理中使用它。
    以下是在您的代码中使用 AccessController.doPrivileged 的示例:

    import java.util.Collections;
    import java.util.List;
    import com.google.api.client.http.HttpTransport;
    import com.google.api.client.http.javanet.NetHttpTransport;
    import com.google.api.client.json.JsonFactory;
    import com.google.api.services.customsearch.Customsearch;
    import com.google.api.services.customsearch.model.Result;
    import com.google.api.services.customsearch.model.Search;
    public class GoogleSearchClient {
        public List<Result> getSearchResult(final String keyword){
            String GOOGLE_SEARCH_URL = https://www.googleapis.com/customsearch/v1?";
            //api key
            final String API_KEY = "xxxxxxxxxxxxxxxxxxxxx";
            //custom search engine ID
            final String SEARCH_ENGINE_ID = "xxxxxxxxxx:xxxxxxxxxxxx";
            String FINAL_URL= GOOGLE_SEARCH_URL + "key=" + API_KEY + "&cx=" + SEARCH_ENGINE_ID;
            // Set up the HTTP transport and JSON factory
            HttpTransport httpTransport = new NetHttpTransport();
            JsonFactory jsonFactory = new com.google.api.client.json.jackson2.JacksonFactory();
            //HttpRequestInitializer initializer = (HttpRequestInitializer)new CommonGoogleClientRequestInitializer(API_KEY);
            final Customsearch customsearch = new Customsearch(httpTransport, jsonFactory,null);
    
            return AccessController.doPrivileged(
                    new PrivilegedAction<List<Result>>() {
                @Override
                public List<Result> run() {
                    List<Result> resultList = Collections.emptyList();
                    try {
                        Customsearch.Cse.List list = customsearch.cse().list(keyword);
                        list.setKey(API_KEY);
                        list.setCx(SEARCH_ENGINE_ID);
                        //num results per page
                        //list.setNum(2L);
    
                        //for pagination
                        list.setStart(10L);
                        Search results = list.execute();
                        resultList = results.getItems();
    
                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                    return resultList;
                }
            });
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-07
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2012-04-14
      相关资源
      最近更新 更多