public static int getAuthenticatedId() {
    SecurityContext securityContext = SecurityContextHolder.getContext();

    Authentication authentication = securityContext.getAuthentication();
    Object principal = (authentication == null) ? null : authentication.getPrincipal();

    if (principal instanceof AmbariUserDetails) {
      return ((AmbariUserDetails) principal).getUserId();
    }

    return -1;
  }
Gets the ID of the logged-in user.  Thread-safe due to use of
thread-local.

@return the ID of the logged-in user
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AuthorizationHelper.java