public class AgentDumpModelImpl extends AMModelBase implements AgentDumpModel {

  private static SSOToken adminSSOToken = AMAdminUtils.getSuperAdminSSOToken();

  public AgentDumpModelImpl(HttpServletRequest req, Map map) {
    super(req, map);
  }

  public Map getAttributeValues(String universalId) throws AMConsoleException {
    try {
      AMIdentity amid = IdUtils.getIdentity(adminSSOToken, universalId);
      Map values = AgentConfiguration.getAgentAttributes(amid, true);
      return values;
    } catch (IdRepoException re) {
      throw new AMConsoleException(re.getMessage());
    } catch (SMSException se) {
      throw new AMConsoleException(se.getMessage());
    } catch (SSOException ssoe) {
      throw new AMConsoleException(ssoe.getMessage());
    }
  }

  public String getDisplayName(String universalId) throws AMConsoleException {
    try {
      AMIdentity amid = IdUtils.getIdentity(getUserSSOToken(), universalId);
      return amid.getName();
    } catch (IdRepoException e) {
      throw new AMConsoleException(getErrorString(e));
    }
  }
}
  protected void createPropertyModel() {
    String xmlFileName = "com/sun/identity/console/propertyRestSecurityTokenService.xml";
    String xml =
        AMAdminUtils.getStringFromInputStream(
            getClass().getClassLoader().getResourceAsStream(xmlFileName));

    propertySheetModel = new AMPropertySheetModel(xml);
    propertySheetModel.clear();
  }
  protected AMModel getModelInternal() {
    AMModel model = null;
    HttpServletRequest req = RequestManager.getRequestContext().getRequest();
    String serviceName = (String) getPageSessionAttribute(AMServiceProfile.SERVICE_NAME);
    List parentIds = (List) getPageSessionAttribute(AMServiceProfile.PG_SESSION_SUB_CONFIG_IDS);
    String parentId = AMAdminUtils.getString(parentIds, "/", true);

    try {
      model = new SubConfigModelImpl(req, serviceName, parentId, getPageSessionAttributes());
    } catch (AMConsoleException e) {
      debug.error("SubConfigAddViewBean.getModelInternal", e);
    }

    return model;
  }
  private static void getDealtWithProperties(Set uiXML) {
    dealtWithProperties = new HashSet();
    for (Iterator i = uiXML.iterator(); i.hasNext(); ) {
      String xml = (String) i.next();
      String is =
          AMAdminUtils.getStringFromInputStream(
              ServerEditAdvancedViewBean.class
                  .getClassLoader()
                  .getResourceAsStream("com/sun/identity/console/" + xml));
      Set set = ServerEditViewBeanBase.getAllConfigUINames(is);

      for (Iterator j = set.iterator(); j.hasNext(); ) {
        dealtWithProperties.add(ServerEditViewBeanBase.getActualPropertyName((String) j.next()));
      }
    }
  }
  /**
   * Returns a map of assigned service name to its localized name under a realm.
   *
   * @param realmName Name of Realm.
   * @return a map of assigned service name to its localized name under a realm.
   * @throws AMConsoleException if service names cannot be obtained.
   */
  public Map getAssignedServiceNames(String realmName) throws AMConsoleException {
    String[] param = {realmName};
    logEvent("ATTEMPT_GET_ASSIGNED_SERVICE_OF_REALM", param);

    try {
      OrganizationConfigManager orgCfgMgr =
          new OrganizationConfigManager(getUserSSOToken(), realmName);
      Set names = orgCfgMgr.getAssignedServices();
      if ((names == null) || names.isEmpty()) {
        names = new HashSet();
      }
      getIdentityServices(realmName, names);

      /*
       * Need to use adminSSOToken because policy admin does not
       * have the correct privileges.
       */
      AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realmName);
      AMAdminUtils.removeAllCaseIgnore(names, mgr.getAuthenticationServiceNames());
      removeNonDisplayableServices(names, SUPPORTED_SCHEMA_TYPE);
      // remove auth configuration service too
      names.remove(AMAdminConstants.AUTH_CONFIG_SERVICE);
      names.remove(AMAdminConstants.CORE_AUTH_SERVICE);
      /*
      Creation and edit of instances of the Rest/Soap STS services handled by the STS tab.
       */
      names.remove(AMAdminConstants.REST_STS_SERVICE);
      names.remove(AMAdminConstants.SOAP_STS_SERVICE);

      logEvent("SUCCEED_GET_ASSIGNED_SERVICE_OF_REALM", param);
      return mapNameToDisplayName(names);
    } catch (AMConfigurationException e) {
      String strError = getErrorString(e);
      String[] paramsEx = {realmName, strError};
      logEvent("CONFIGURATION_EXCEPTION_GET_ASSIGNED_SERVICE_OF_REALM", paramsEx);
      throw new AMConsoleException(strError);
    } catch (SMSException e) {
      String strError = getErrorString(e);
      String[] paramsEx = {realmName, strError};
      logEvent("SMS_EXCEPTION_GET_ASSIGNED_SERVICE_OF_REALM", paramsEx);
      throw new AMConsoleException(strError);
    }
  }
  private void removeNonDisplayableServices(Set serviceNames, Set schemaTypes) {
    for (Iterator i = serviceNames.iterator(); i.hasNext(); ) {
      String svcName = (String) i.next();

      if (getServicePropertiesViewBeanURL(svcName) == null) {
        boolean hasAttr = false;

        for (Iterator j = schemaTypes.iterator(); j.hasNext() && !hasAttr; ) {
          SchemaType type = (SchemaType) j.next();
          Set displayable = AMAdminUtils.getDisplayableAttributeNames(svcName, type);
          hasAttr = !displayable.isEmpty();
        }

        if (!hasAttr) {
          i.remove();
        }
      }
    }
  }
  /**
   * Returns a map of service name to its display name that can be assigned to a realm.
   *
   * @param realmName Name of Realm.
   * @return a map of service name to its display name that can be assigned to a realm.
   * @throws AMConsoleException if service names cannot be obtained.
   */
  public Map getAssignableServiceNames(String realmName) throws AMConsoleException {
    String[] param = {realmName};
    logEvent("ATTEMPT_GET_ASSIGNABLE_SERVICE_OF_REALM", param);

    try {
      OrganizationConfigManager orgCfgMgr =
          new OrganizationConfigManager(getUserSSOToken(), realmName);
      Set names = orgCfgMgr.getAssignableServices();
      addIdentityUnassignedServices(realmName, names);
      names.removeAll(orgCfgMgr.getAssignedServices());

      AMAuthenticationManager mgr = new AMAuthenticationManager(getUserSSOToken(), realmName);
      AMAdminUtils.removeAllCaseIgnore(names, mgr.getAuthenticationServiceNames());
      removeNonDisplayableServices(names, SUPPORTED_SCHEMA_TYPE);
      names.remove(AMAdminConstants.CORE_AUTH_SERVICE);
      /*
      Creation and edit of instances of the Rest/Soap STS services handled by the STS tab.
       */
      names.remove(AMAdminConstants.REST_STS_SERVICE);
      names.remove(AMAdminConstants.SOAP_STS_SERVICE);
      logEvent("SUCCEED_GET_ASSIGNABLE_SERVICE_OF_REALM", param);
      return mapNameToDisplayName(names);
    } catch (AMConfigurationException e) {
      String strError = getErrorString(e);
      String[] paramsEx = {realmName, strError};
      logEvent("CONFIGURATION_EXCEPTION_GET_ASSIGNABLE_SERVICE_OF_REALM", paramsEx);
      if (debug.warningEnabled()) {
        debug.warning("ServicesModel.getAssignableServiceNames " + strError);
      }
      throw new AMConsoleException("no.properties");
    } catch (SMSException e) {
      String strError = getErrorString(e);
      String[] paramsEx = {realmName, strError};
      logEvent("SMS_EXCEPTION_GET_ASSIGNABLE_SERVICE_OF_REALM", paramsEx);
      throw new AMConsoleException(strError);
    }
  }
 protected void setValues(Map values) {
   Map upcase = AMAdminUtils.upCaseKeys(values);
   propertySheetModel.setValue(ATTR_INSTANCE_ID, upcase.get(SAMLConstants.INSTANCEID));
   propertySheetModel.setValue(ATTR_SITE_ID, upcase.get(SAMLConstants.SITEID));
   propertySheetModel.setValue(ATTR_ISSUER_NAME, upcase.get(SAMLConstants.ISSUERNAME));
 }