Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileDataStoreFactory method setPermissionsToOwnerOnly only supports Unix #315

Closed
rbeede opened this issue Jan 16, 2016 · 3 comments · Fixed by #557
Closed

FileDataStoreFactory method setPermissionsToOwnerOnly only supports Unix #315

rbeede opened this issue Jan 16, 2016 · 3 comments · Fixed by #557
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@rbeede
Copy link

rbeede commented Jan 16, 2016

com.google.api.client.util.store.FileDataStoreFactory

setPermissionsToOwnerOnly does not use newer Java 7 or 8 APIs for setting file/dir ownership and thus generates spurious warnings like "com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody: "

The code only takes into account file systems as seen on Unix-like OSes that use a simple mode for the permissions. Windows file systems have ACLs and require different API calls to modify ownership and permissions. The latest Java APIs should be used instead which can handle both file system types.

This warning occurs for anyone using the Drive API SDK samples and causes confusion for new developers using the API.

https://github.com/google/google-http-java-client/blob/dev/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java

@rbeede
Copy link
Author

rbeede commented Jan 17, 2016

Temporary workaround:

        final java.util.logging.Logger buggyLogger = java.util.logging.Logger.getLogger(FileDataStoreFactory.class.getName());
        buggyLogger.setLevel(java.util.logging.Level.SEVERE);

@mattwhisenhunt mattwhisenhunt added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 22, 2017
@JustinBeckwith JustinBeckwith added priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. and removed priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Jun 6, 2018
@grant
Copy link

grant commented Aug 23, 2018

I believe this issue is causing downstream issues with Windows users.
https://stackoverflow.com/questions/30634827/warning-unable-to-change-permissions-for-everybody

Example:
googleworkspace/java-samples#24

I'm not sure though.

@isaacbauman-2021
Copy link

Temporary workaround:

        final java.util.logging.Logger buggyLogger = java.util.logging.Logger.getLogger(FileDataStoreFactory.class.getName());
        buggyLogger.setLevel(java.util.logging.Level.SEVERE);

where should I put this code?
`public class Auth {

/**
 * Define a global instance of the HTTP transport.使用new关键字来创建一个全局实例。
 */
public static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

/**
 * Define a global instance of the JSON factory.
 */
public static final JsonFactory JSON_FACTORY = new JacksonFactory();

/**
 * This is the directory that will be used under the user's home directory where OAuth tokens will be stored.
 */
private static final String CREDENTIALS_DIRECTORY = ".oauth-credentials";

/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param scopes              list of scopes needed to run youtube upload.
 * @param credentialDatastore name of the credential datastore to cache OAuth tokens
 */
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException{

    // Load client secrets.
    Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

    // Checks that the defaults have been replaced (Default = "Enter X here").
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(
                "Enter Client ID and Secret from https://console.developers.google.com/project/_/apiui/credential "
                        + "into src/main/resources/client_secrets.json");
        System.exit(1);
    }

    // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
            .build();

    // Build the local server and bind it to port 8080
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}

}`

clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants