class AuthorizationHelper {

  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;
  }

}