2013-10-09 3 views
0

항아리를 가져 오는 앱 엔진 앱이 있습니다. 그 항아리에서 나는 GoogleClientSecrets.load() 을 사용하여 BigQuery로 인증하기 위해 client_secrets.json 파일을로드합니다. 분명히 App Engine은 로컬 호스트에 앱을 배포 할 때 내 디스크의 일부 위치에서 파일을 읽는 것을 좋아하지 않습니다. WEBINF 폴더에 자격 증명을 입력하면 작동하지만 테스트하지 않았지만 누구든지 파일에 액세스하기 쉽습니다. 자격증 명을 넣을 수있는 가장 좋은 곳은 어디이고 App Engine 앱에서 자격증 명에 액세스하는 방법은 무엇입니까?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

'/ WEB-INF'는 이러한 데이터를 넣기에 적합한 장소입니다. 파일이 아닌 리소스로 액세스하십시오. http://stackoverflow.com/questions/4340653/file-path-to-resource-in-our-war-web-inf-folder –

+0

답장을 보내 주셔서 감사합니다. – Tad

답변

1

아니, /WEB-INF 폴더의 내용은 응용 프로그램 코드에 개인과 액세스 할 수 없습니다 HTTP (= 서블릿 컨테이너는 WEB-INF 폴더의 데이터에 액세스하려는 요청을 인식하지 않음).

사용이 조각은 /WEB-INF 폴더 안에있는 파일의 내용을 읽을 수 있습니다 :

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

그런 다음 methods for reading InputStreams 중 하나를 사용하여 스트림을 읽습니다.

+0

본 적이 있습니다. . 해당 파일을 내 응용 프로그램 엔진 프로젝트의 리소스로 사용하지 않고이를 수행 할 수있는 방법이 있습니까? 앱 엔진 앱이 아닌 인증을 수행하는 것이기 때문에 앱 엔진 앱이이 파일에 대해 알지 않아야한다고 생각합니다. 그게 가능하니? – Tad

+0

어, https://developers.google.com/appengine/kb/java#writefile하면 파일에 쓸 수 없다는 뜻입니까? – Tad

+0

네, 파일 시스템은 읽기 전용입니다. –