App Engine凭据问题

时间:2013-10-09 19:03:43

标签: google-app-engine credentials google-bigquery

我有一个导入jar的app引擎应用。在我正在使用的罐子里 GoogleClientSecrets.load() 加载client_secrets.json文件以使用BigQuery进行身份验证。显然,当我在localhost上部署应用程序时,App Engine不喜欢我从磁盘上的某个位置读取文件。我假设如果我将凭据放在WEBINF文件夹中它将工作,但没有测试它,但那么任何人都可以轻松访问该文件。放置凭据的最佳位置在哪里以及如何从App Engine应用程序访问凭证?

感谢您的帮助!

这些建议有助于在阅读文件时解决问题。写文件怎么样?我正在使用存储凭据文件的FileCredentialStore。

我相信这条线造成了问题: FileCredentialStore variantStoreCredentialManager = new FileCredentialStore(expectedClientFile,jsonFactory); 而错误是 java.security.AccessControlException:访问被拒绝(“java.io.FilePermission”文件路径“写”)

    public Bigquery createAuthorizedClient() throws IOException {
    Credential authorization = new GoogleCredential();
    if ( clientID == null ) {
        authorization = createWebAuthenticatedClientCredential();
    } else {
        String expectedFileLocation = CREDENTIAL_FILE_PATH;
        File expectedClientFile = new File(expectedFileLocation);
        if ( ! expectedClientFile.exists() ) {
            // this is a known issue, the credential store will blow up if the file doesn't exist. So create it with an
            // empty json ( {  } )
            createClientFile(expectedClientFile);
        }
        FileCredentialStore variantStoreCredentialManager = new FileCredentialStore(expectedClientFile,jsonFactory);
        GoogleCredential.Builder credentialBuilder = new GoogleCredential.Builder();
        credentialBuilder.setJsonFactory(jsonFactory);
        credentialBuilder.setClientSecrets(clientSecrets);
        credentialBuilder.setTransport(transport);
        authorization = credentialBuilder.build();
        boolean loadedSuccessfully = variantStoreCredentialManager.load(clientID,authorization);
        if ( ! loadedSuccessfully  ) {
            authorization = createWebAuthenticatedClientCredential();
            variantStoreCredentialManager.store(clientID, authorization);
        }
    }

    return new Bigquery(transport, jsonFactory, authorization);
}

1 个答案:

答案 0 :(得分:1)

不,/WEB-INF文件夹的内容对应用程序代码是私有的,不能通过HTTP访问(= servlet容器不支持尝试访问WEB-INF文件夹中的数据的请求)。

使用此代码段读取/WEB-INF文件夹中文件的内容:

InputStream is = getServletContext().getResourceAsStream("/WEB-INF/"+filename);

然后使用methods for reading InputStreams之一读取流。