private void assignPermissions ( final String user , final File tokenFile , final Logger logger ) throws IOException { final List < String > changePermissionsCommand = Arrays . asList ( CHMOD , TOKEN_FILE_PERMISSIONS , tokenFile . getAbsolutePath ( ) ) ; int result = this . executeAsUser . execute ( System . getProperty ( "user.name" ) , changePermissionsCommand ) ; if ( result != 0 ) { throw new IOException ( "Unable to modify permissions. User: " + user ) ; } final List < String > changeOwnershipCommand = Arrays . asList ( CHOWN , user + ":" + GROUP_NAME , tokenFile . getAbsolutePath ( ) ) ; result = this . executeAsUser . execute ( "root" , changeOwnershipCommand ) ; if ( result != 0 ) { throw new IOException ( "Unable to set ownership. User: " + user ) ; } }
Uses execute - as - user binary to reassign file permissions to be readable only by that user .