client/src/main/java/io/hoplin/util/OsUtil.java
/**
   * Check if application is running under 'root account'
   */
Check if application is running under 'root account'
Check if application is running under ' root account '
public static boolean checkRootAccess() {
    if (OsUtil.isLinux()) {
      int uid = 0;
      final ProcessResponse pr = ProcessHelper
          .execute(false, Arrays.asList("/usr/bin/id", "-u"), null);
      if (pr.success()) {
        String output = pr.getOutput();
        if (output != null) {
          try {
            output = output.replace(System.lineSeparator(), "");
            uid = Integer.parseInt(output);
          } catch (final NumberFormatException e) {
            throw new RuntimeException("Unable to get UID : " + output);
          }
        }
      }
      LOGGER.info("Access UID : {}", uid);
      return (uid == 0);
    }
    return false;
  }
public static boolean checkRootAccess ( ) { if ( OsUtil . isLinux ( ) ) { int uid = 0 ; final ProcessResponse pr = ProcessHelper . execute ( false , Arrays . asList ( "/usr/bin/id" , "-u" ) , null ) ; if ( pr . success ( ) ) { String output = pr . getOutput ( ) ; if ( output != null ) { try { output = output . replace ( System . lineSeparator ( ) , "" ) ; uid = Integer . parseInt ( output ) ; } catch ( final NumberFormatException e ) { throw new RuntimeException ( "Unable to get UID : " + output ) ; } } } LOGGER . info ( "Access UID : {}" , uid ) ; return ( uid == 0 ) ; } return false ; }
Check if application is running under 'root account'
Check if application is running under ' root account '
// if the user is 'root' like the result will be 0