⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agentlauncherexploreritemsecurity.java

📁 一个agent 工具包,可以开发移动设备应用,考虑了安全措施
💻 JAVA
字号:
package SOMA.security;

import java.util.*;
import java.io.*;

import SOMA.explorer.*;
import SOMA.Environment;
import SOMA.agent.*;
import SOMA.agent.mobility.*;
import SOMA.security.infrastructure.*;

/** Voce di menu per gestire il lancio di agenti...
* @author Livio Profiri
*/

public class AgentLauncherExplorerItemSecurity extends ExplorerItem
{
  Environment env;

  public static final String SYSTEM_CLASSLOADER = "-s";
  public static final String NOT_TRACEABLE = "-nt";
  public static final String NO_START = "-ns";
//  public static final String CA_ONLINE = "-online";
  public static final String PASSWORD_PROFILEPATH = "-p";


  public AgentLauncherExplorerItemSecurity( Environment env )
  {

    super( "[" + SYSTEM_CLASSLOADER + "] [" + NOT_TRACEABLE + "] [" + NO_START +
           "] [" + PASSWORD_PROFILEPATH + " ProfilePath ProfilePassword ] " +
           " \"Agent ID\" { \"Arg1\" \"Arg2\" ... }"  );
    this.env = env;
    //env.out.println("AgentLauncherSecurity begin");
  }

  public Object Execute( Collection Parameters, PrintStream out )
  {
    ProfileManager profile = null;

    String profilePath;
    String profilePassword;

    HashSet options = new HashSet();

    Iterator i = Parameters.iterator();

    while( i.hasNext() )
    {
      String option = (String)i.next();

      out.println( option );

      if ( option.equals( PASSWORD_PROFILEPATH ) )
      {
        i.remove();
        if (! i.hasNext() ) profile = null;
        else
        {
            profilePath = (String)i.next();
            i.remove();
            if (! i.hasNext() ) profile = null;
            else
            {
              try
              {
                env.out.println( "Logon user profile, begin." );
                options.add( PASSWORD_PROFILEPATH );
                profilePassword = (String)i.next();
                //i.remove();
                // inizializzare il profilo.

                if ( ((SecurityEnvironment)env).profile == null)
                  env.out.println( "Env.Profile is null" );
                else env.out.println( "Env.Profile ok" );
                Infrastructure pki = null;

                boolean onLine = ( ( ((SecurityEnvironment)env).profile != null) &&
                                   ( (pki = ((SecurityEnvironment)env).profile.getEntrustInfrastructure()) != null) &&
                                   ( pki.getOnLine() ));
                profile = new ProfileManager ( pki );
                // profile.setEntrustInfrastructure( pki );

                profile.logonProfile( profilePath, profilePassword, onLine );
                env.out.println( "Logon user profile, end." );
              } catch ( Exception e ) { env.out.println( "Error cannot logon profile: " + e ); }

            }
        }
      }
      if( option.startsWith( "-" ) )
      {
        i.remove(); // Rimuove il parametro dalla lista dei parametri.
        options.add( option );
      }
      else
        break;
    }

    i = Parameters.iterator();
    if( i.hasNext() )
    {
      String agentName = (String)i.next();
      i.remove();
      out.println( "Agent class: " + agentName );

      int NumParameters = Parameters.size();
      String[] ParametersArray = new String[NumParameters];

      out.println( "Creating agent: " + agentName + " Parameters: " );
      for( int j = 0; j < NumParameters; j++ )
      {
        ParametersArray[j] = (String)i.next();
        out.println( "  " + j + ")  " + ParametersArray[j] );
      }

      if( options.contains( SYSTEM_CLASSLOADER ) )
        out.println( SYSTEM_CLASSLOADER + " ==> Using System ClassLoader." );

      if( options.contains( NOT_TRACEABLE ) )
        out.println( NOT_TRACEABLE + " ==> Not Traceable agent." );

      if( options.contains( NO_START ) )
        out.println( NO_START + " ==> No Start: the agent will not be started." );

      if( options.contains( PASSWORD_PROFILEPATH ) )
        out.println( PASSWORD_PROFILEPATH + " ==> start agent signature" );

      // true --> System agent!
      AgentWorker worker =
           ((AgentManagerSecurity)env.agentManager).createAgent( agentName, ParametersArray,
                                                                 options.contains( SYSTEM_CLASSLOADER ),
                                                                 !options.contains( NOT_TRACEABLE ),
                                                                 profile );

      /** Questa operazione chiude il profilo che firma l'agente;
       *  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -