Example #1
0
  public static String getGlobalStateDefinitionsXML(JmxAgentUser jmxAgentUser) {

    String globalStateDefinitionsXML = null;
    // SWAgent agent = convertToSwAgent(jmxUser.getSwAgentXML());
    // SWAgent swAgent =
    // TlosSpaceWide.getSpaceWideRegistry().getHeartBeatListenerRef().getSwAgentsCache().get(agent.getIpAddress()+"."+agent.getJmxPort());
    SWAgent swAgent =
        TlosSpaceWide.getSpaceWideRegistry()
            .getAgentManagerReference()
            .getSwAgentsCache()
            .get(jmxAgentUser.getAgentId() + "");
    GlobalStateDefinition globalStateDefinition = GlobalStateDefinition.Factory.newInstance();
    globalStateDefinition =
        copyGlobalStateDefinitionsXML(
            TlosSpaceWide.getSpaceWideRegistry().getGlobalStateDefinition());

    for (State state : globalStateDefinition.getGlobalStateArray()) {
      for (Substate substate : state.getSubstateArray()) {
        for (Status status : substate.getSubStateStatusesArray()) {
          for (ReturnCodeList returnCodeList : status.getReturnCodeListArray()) {

            if (!returnCodeList.getOsType().equals(swAgent.getOsType())) {
              XmlCursor xmlCursor = returnCodeList.newCursor();
              xmlCursor.removeXml();
            }
          }
        }
      }
    }

    globalStateDefinitionsXML = getGlobalStateDefinitionsXML(globalStateDefinition);

    return globalStateDefinitionsXML;
  }
  public static boolean authorizeWeb(JmxUser jmxUser) {

    if (jmxUser == null) {
      logger.error("jmxUser is null !");
      return false;
    }

    String clientAuthanticationId =
        TlosSpaceWide.getSpaceWideRegistry().getJmxUser().getJmxClientAuthanticationId();
    String jmxClientAuthanticationKey =
        TlosSpaceWide.getSpaceWideRegistry().getJmxUser().getJmxClientAuthanticationKey();

    if (!clientAuthanticationId.equals(jmxUser.getJmxClientAuthanticationId())
        || !jmxClientAuthanticationKey.equals(jmxUser.getJmxClientAuthanticationKey())) {
      // return false;
    }
    return true;
  }
  public static boolean authorizeAgent(JmxAgentUser jmxAgentUser) {

    SWAgent clientSideSwAgent = XmlUtils.convertToSwAgent(jmxAgentUser.getSwAgentXML());

    SWAgent serverSideSwAgent =
        TlosSpaceWide.getSpaceWideRegistry()
            .getAgentManagerReference()
            .getSwAgentsCache()
            .get(jmxAgentUser.getAgentId() + "");

    if (serverSideSwAgent == null
        || !clientSideSwAgent.getJmxUser().equals(serverSideSwAgent.getJmxUser())
        || !clientSideSwAgent.getJmxPassword().equals(serverSideSwAgent.getJmxPassword())) {
      return false;
    }
    return true;
  }
  public static void initialize(String MBeanArray[], String MBeanTypeArray[]) {

    try {
      setupTls();

      logger.info("");
      logger.info("############# MBean Server ##################");

      logger.info("Create the MBean server...");
      mbeanServer = MBeanServerFactory.createMBeanServer();

      logger.info("Created !");

      for (int i = 0; i < MBeanArray.length; i++) {
        ObjectName mbeanName = new ObjectName("MBeans:type=" + MBeanTypeArray[i]);
        logger.info(MBeanArray[i] + " MBean is created ...");
        mbeanServer.createMBean(
            JMXServer.class.getPackage().getName() + ".beans." + MBeanArray[i],
            mbeanName,
            null,
            null);
      }

      logger.info(ResourceMapper.SECTION_DIVISON_KARE);
      logger.info("");
      logger.info("######### JMXMP-TLS Connector Server ############");
      logger.info("");

      // Create a JMXMP-TLS connector server
      //
      logger.info("Create a JMXMP-TLS connector server... > ");

      // hardcoded ip : localhost port : 5555
      int port =
          TlosSpaceWide.getSpaceWideRegistry()
              .getTlosSWConfigInfo()
              .getJmxParams()
              .getJmxTlsPort()
              .getPortNumber();
      if (port <= 0) {
        port = 5555;
      }

      logger.info("Using port number : " + port);

      String ipAddress =
          TlosSpaceWide.getSpaceWideRegistry().getServerConfig().getServerParams().getIpAddress();
      if (ipAddress == null || ipAddress.equals("")) {
        ipAddress = null;
      }

      logger.info("Using ip address : " + ipAddress);

      JMXServiceURL url = new JMXServiceURL("jmxmp", ipAddress, port);
      jConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbeanServer);

      logger.info("Created !");

      // Start the JMXMP-TLS connector server
      //
      logger.info("Start the JMXMP-TLS connector server... > ");
      jConnectorServer.start();

      logger.info("Started !");
      logger.info("Waiting for incoming connections...");
      logger.info("#############################################");
      logger.info("");

      String jmxUserName =
          "" + new Random(new Long(Calendar.getInstance().getTimeInMillis())).nextLong();
      Thread.sleep(10);
      String jmxPassWord =
          "" + new Random(new Long(Calendar.getInstance().getTimeInMillis())).nextLong();

      JmxUser jmxUser = new JmxUser();
      jmxUser.setJmxClientAuthanticationId(jmxUserName);
      jmxUser.setJmxClientAuthanticationKey(jmxPassWord);

      TlosSpaceWide.getSpaceWideRegistry().setJmxUser(jmxUser);

    } catch (MalformedURLException mue) {
      logger.error("### MalformedURLException ###");
      mue.printStackTrace();
      try {
        jConnectorServer.stop();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } catch (SecurityException e) {
      // System.out.println(" ### SecurityException ### ");
      logger.error("### SecurityException ###");
      e.printStackTrace();
      System.exit(-1);
    } catch (BindException e) {
      // System.out.println(" ### BindException ### ");
      logger.error("### BindException ###");
      e.printStackTrace();
      System.exit(-1);
    } catch (Exception e) {
      // System.out.println(" ### Unclassified Error ### ");
      logger.error("### Unclassified Error ###");
      e.printStackTrace();
      System.exit(-1);
    }
  }