@Override
  public String getUsername() {
    String shortName = getLoggedinUser();
    try {
      String authToLocalRules = getAuthToLocalRules();
      //Getting ambari server realm. Ideally this should come from user
      String defaultRealm = KerberosUtil.getDefaultRealm();
      if(Strings.isNotEmpty(authToLocalRules) && Strings.isNotEmpty(defaultRealm)){
        synchronized (KerberosName.class){
          KerberosName.setRules(authToLocalRules);
          shortName = new KerberosName(shortName+"@"+defaultRealm).getShortName();
        }
      }
    } catch (InvocationTargetException e) {
      LOG.debug("Failed to get default realm",e);
    }catch (Exception e){
      LOG.warn("Failed to apply auth_to_local rules. "+e.getMessage());
      LOG.debug("Failed to apply auth_to_local rules",e);
    }
    return shortName;
  }
Construct a view context from the given view entity.

@param viewEntity    the view entity
@param viewRegistry  the view registry
ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java