org.licas

## Class AutoSecure

- java.lang.Object
- - java.lang.Thread
  - - org.licas.module.LicasModule
    - - org.licas.module.FrameworkModule
      - - org.licas.module.ServiceModule
        - - org.licas.Service
          - - org.licas.service.DataService
            - - org.licas.Auto
              - - org.licas.AutoSecure

- All Implemented Interfaces:
    java.lang.AutoCloseable, java.lang.Runnable, DataServiceDef, ServiceDef
  Direct Known Subclasses:
    ESB, ScriptService

      public abstract class AutoSecure
      extends Auto

  This is a more secure version of the `Auto` class in which the only methods that can be executed are ones that add and remove messages from the autonomic manager queue. Allowing access to all methods might break some logic as part of a queueing system and this class even overrides any admin script security settings. The `canAccess` method has new settings so that any remote call that tries to invoke a method must use one of the `run`, `invokeBehaviour`, or `messageReply` methods. There are also the following conditions:
  1. If the Thread's `run` method has started, then `invokeBehaviour` is disabled, so the behaviours can only execute in the loop, using the internal `evaluateBehaviour` method, so as not to break some logic here.
  2. If the Thread's `run` method has not started, then `invokeBehaviour` is allowed, for single instance executions.
  3. The `messageReply` method is always open and will queue any messages it receives.
  Author:
    Kieran Greer

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler`

  - ### Field Summary

    - ### Fields inherited from class org.licas.Auto

      `autoEngine, autoManager, bm, iterations, sleepTime`

    - ### Fields inherited from class org.licas.service.DataService

      `dataCompare, dataMethod, resultObj`

    - ### Fields inherited from class org.licas.Service

      `canAccessMeta, canAccessNested, dm, finalised, isRemoteCall, messageStore, serviceAdmin, serviceGrade, serviceInitialise, serviceLinks, serviceState, sm, toLoadScript`

    - ### Fields inherited from class org.licas.module.ServiceModule

      `shutDown`

    - ### Fields inherited from class org.licas.module.FrameworkModule

      `passwordHandler, service, serviceType`

    - ### Fields inherited from class org.licas.module.LicasModule

      `jarFile, syncOn, uuid`

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AutoSecure()` Creates a new instance of AutoSecure.
    `AutoSecure(java.lang.String thisPassword, java.lang.String thisAdminKey)` Creates a new instance of AutoSecure.
    `AutoSecure(java.lang.String thisPassword, java.lang.String thisAdminKey, org.licas_xml.abs.Element adminXml)` Creates a new instance of AutoSecure.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `canAccess(java.lang.String thePassword, java.lang.String methodName, java.lang.reflect.Method theMethod)` Return true if the password allows the calling component to access this component.
    `protected boolean` | `classNameOK(java.lang.String className)` Check that the classname path is not illegal.
    `protected java.lang.Object` | `getInstanceValue(java.lang.String varName)` Get the value of the specified variable if it exists.
    `java.util.ArrayList<java.lang.String>` | `getPublicMethods()` Get the list of methods that that can be freely called, without a password even.
    `protected java.util.ArrayList<java.lang.String>` | `getSecureMethods()` Get the list of methods that can be safely called on a secure Auto class.
    `boolean` | `isSecureMethod(java.lang.String methodName)` Return true if the method is one that can be safely called on a secure Auto class.
    `protected void` | `setInstanceValues(org.licas_xml.abs.Element instanceValues)` Set actual values for variable instances if they are defined.
    `protected void` | `setSerializeValues(org.licas_xml.abs.Element serializeXml)` Set actual values for serialized variable instances if they are defined.

    - ### Methods inherited from class org.licas.Auto

      `autoAction, autoQueueMessage, behaviourAction, getAutoEngine, getMessageState, interrupt, invokeBehaviour, messageReply, removeCommunicationID, run, setAutoEngine, setAutonomicManager, setBehaviourModule, setProcessScript`

    - ### Methods inherited from class org.licas.service.DataService

      `createEvaluateData, createEvaluateData, dataTypeOK, dataXmlBM, dataXmlBM, dataXmlDH, dataXmlDH, evaluate, getData, getData, getDataType, getResultObj, resetValues, setData, setData, setFixedDataValue, setGenData, setResultObj`

    - ### Methods inherited from class org.licas.Service

      `addCommunicationID, addDefaultService, addDefaultService, addDefaultService, addDefaultService, addLinkFromService, addLinkToService, addMessageMetrics, addService, addService, addService, addService, addServiceAssociation, addServicePassword, addTempPassword, allowAddService, canAccess, canAccess, canAccess, canAccessMeta, canAccessNested, canAccessTemp, canRun, clearServiceLinks, clearServices, clearServices, close, createMetaForRepos, createMetaFull, createPermanentLinkTo, createServiceWrapper, defaultAdminToRemove, dynamicLinkQuery, dynamicLinksToPermanent, dynamicLinksToXml, dynamicLinksToXml, execute, finaliseInitialisation, finaliseInitialisation, finaliseModule, finaliseThisConfig, GET, getAllLinkToService, getAllowAddService, getAutonomicManagerConfig, getCommunicationClientURI, getDescription, getFullPath, getIsRemoteCall, getLinkFromService, getLinkToService, getLocalRemoteID, getParent, getParent, getPassword, getPassword, getPassword, getPasswordHandler, getPrivateMethods, getPublicServiceClassname, getServerPassword, getService, getService, getServiceAdmin, getServiceClasses, getServiceGrade, getServiceLinks, getServiceNames, getServiceNames, getServiceNames, getServiceNumber, getServiceOrWrapper, getServiceState, getServiceType, getServiceTypes, handshake, hasCommunicationID, hasLinkTo, hasServerPassword, hasService, hasServiceType, isCorrectPassword, isPrivateMethod, isPublicMethod, isStarted, linksToXml, passwordsStateToXml, permanentLinksToXml, reflectionMethods, reflectionObject, removeAllLinksTo, removeAllServices, removeAllServices, removeLinkFromService, removeLinkToService, removePermanentLinkTo, removeServiceAssociation, removeServiceID, removeServicePath, removeServicePath, removeTempPassword, serviceNegotiate, serviceToXml, serviceToXml, setAdminInfo, setCanAccessMeta, setCanAccessNested, setData, setDataModule, setDataModule, setDescription, setIsRemoteCall, setOtherMeta, setParent, setParent, setServerPassword, setServiceGrade, setServiceModule, setServiceState, startAllThreads, startThread, stopAllThreads, syncToAsync, syncToAsyncReply, syncToAsyncTransit, xmlToDynamicLinks, xmlToService`

    - ### Methods inherited from class org.licas.module.ServiceModule

      `getShutDown, setShutDown, setShutDown`

    - ### Methods inherited from class org.licas.module.FrameworkModule

      `canAccess, getPasswordHandler, getServicePassword, getServiceType, isAdminKey, setServiceDetails, setServiceType`

    - ### Methods inherited from class org.licas.module.LicasModule

      `getJarFile, getUUID, loadObject, setJarFile, setUUID, threadAliveState`

    - ### Methods inherited from class java.lang.Thread

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.licas.def.DataServiceDef

      `setData`

    - ### Methods inherited from interface org.licas.def.ServiceDef

      `getUUID, setJarFile, setUUID`

- - ### Constructor Detail

    - #### AutoSecure

          public AutoSecure()
                     throws java.lang.Exception

      Creates a new instance of AutoSecure. Password and service key set to `anon` by default.
      Throws:
        `java.lang.Exception` - any error.

    - #### AutoSecure

          public AutoSecure(java.lang.String thisPassword,
                            java.lang.String thisAdminKey)
                     throws java.lang.Exception

      Creates a new instance of AutoSecure.
      Parameters:
        `thisPassword` - password to invoke this service.
        `thisAdminKey` - admin key for this service.
      Throws:
        `java.lang.Exception` - any error.

    - #### AutoSecure

          public AutoSecure(java.lang.String thisPassword,
                            java.lang.String thisAdminKey,
                            org.licas_xml.abs.Element adminXml)
                     throws java.lang.Exception

      Creates a new instance of AutoSecure.
      Parameters:
        `thisPassword` - password to invoke this service.
        `thisAdminKey` - admin key for this service.
        `adminXml` - the admin info or description of this service.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### setInstanceValues

          protected void setInstanceValues(org.licas_xml.abs.Element instanceValues)
                                    throws java.lang.Exception

      Set actual values for variable instances if they are defined.

      `NOTE:` you must add this method to your own derived class if you use it, so that the private variables in that class can be accessed. It is ignored unless it gets called through the script initialisation process.

      Overrides:
        `setInstanceValues` in class `Auto`
      Parameters:
        `instanceValues` - the admin script part that defines instance values.
      Throws:
        `java.lang.Exception` - any error.

    - #### getInstanceValue

          protected java.lang.Object getInstanceValue(java.lang.String varName)
                                               throws java.lang.Exception

      Get the value of the specified variable if it exists.

      `NOTE:` you must add this method to your own derived class if you use it, so that the private variables in that class can be accessed. It is ignored unless it gets called through the script initialisation process.

      Overrides:
        `getInstanceValue` in class `Auto`
      Parameters:
        `varName` - the name of the variable to check for.
      Returns:
        the variable value, or null if it does not exist.
      Throws:
        `java.lang.Exception` - any error.

    - #### setSerializeValues

          protected void setSerializeValues(org.licas_xml.abs.Element serializeXml)
                                     throws java.lang.Exception

      Set actual values for serialized variable instances if they are defined.

      `NOTE:` you must add this method to your own derived class if you use it, so that the private variables in that class can be accessed.

      Overrides:
        `setSerializeValues` in class `Auto`
      Parameters:
        `serializeXml` - the admin script part that defines serialize instance values.
      Throws:
        `java.lang.Exception` - any error.

    - #### isSecureMethod

          public boolean isSecureMethod(java.lang.String methodName)

      Return true if the method is one that can be safely called on a secure Auto class. This version only allows the autonomous loop methods as default.
      Parameters:
        `methodName` - the name of the method.
      Returns:
        true if the method can be freely called.

    - #### canAccess

          protected boolean canAccess(java.lang.String thePassword,
                                      java.lang.String methodName,
                                      java.lang.reflect.Method theMethod)
                               throws java.lang.Exception

      Return true if the password allows the calling component to access this component.
      Overrides:
        `canAccess` in class `Service`
      Parameters:
        `thePassword` - the password to use.
        `methodName` - the method name that needs to be called.
        `theMethod` - the method that needs to be called.
      Returns:
        true if the entered password is the correct password or there is no password.
      Throws:
        `java.lang.Exception` - any error.

    - #### classNameOK

          protected boolean classNameOK(java.lang.String className)

      Check that the classname path is not illegal.
      Overrides:
        `classNameOK` in class `Service`
      Parameters:
        `className` - full classname of service to load.
      Returns:
        ture if safe path that is not one of the licas key packages.

    - #### getSecureMethods

          protected java.util.ArrayList<java.lang.String> getSecureMethods()

      Get the list of methods that can be safely called on a secure Auto class.
      Returns:
        the list of safe method names, but might still require passwords.

    - #### getPublicMethods

          public java.util.ArrayList<java.lang.String> getPublicMethods()

      Get the list of methods that that can be freely called, without a password even.
      Overrides:
        `getPublicMethods` in class `Service`
      Returns:
        the list of safe method names, but might still require passwords.