com.google.enterprise.adaptor.prebuilt
Class CommandLineAdaptor

java.lang.Object
  extended by com.google.enterprise.adaptor.AbstractAdaptor
      extended by com.google.enterprise.adaptor.prebuilt.CommandLineAdaptor
All Implemented Interfaces:
Adaptor, AuthzAuthority

public class CommandLineAdaptor
extends AbstractAdaptor
implements AuthzAuthority

Command Line Adaptor


Constructor Summary
CommandLineAdaptor()
           
 
Method Summary
protected  Command.Result executeAuthorizer(String[] commandLine, byte[] stdin)
           
protected  int executeLister(String[] commandLine, StreamingCommand.InputSource stdin, StreamingCommand.OutputSink stdout, StreamingCommand.OutputSink stderr)
           
protected  int executeRetriever(String[] commandLine, StreamingCommand.InputSource stdin, StreamingCommand.OutputSink stdout, StreamingCommand.OutputSink stderr)
           
 void getDocContent(Request req, Response resp)
          Gives the bytes of a document referenced with id.
 void getDocIds(DocIdPusher pusher)
          Pushes all the DocIds that are suppose to be indexed by the GSA.
 List<String> getListerCommand()
           
 List<String> getRetrieverCommand()
           
 void init(AdaptorContext context)
          Initialize adaptor with the current context.
 void initConfig(Config config)
          Provides the opportunity for the Adaptor to create new configuration values or override default values.
 Map<DocId,AuthzStatus> isUserAuthorized(AuthnIdentity userIdentity, Collection<DocId> ids)
          Determines whether the user identified is allowed to access the DocIds.
static void main(String[] args)
          Call default main for adaptors.
 void setListerCommand(List<String> commandWithArgs)
           
 void setRetrieverCommand(List<String> commandWithArgs)
           
 
Methods inherited from class com.google.enterprise.adaptor.AbstractAdaptor
destroy, main
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineAdaptor

public CommandLineAdaptor()
Method Detail

initConfig

public void initConfig(Config config)
Description copied from class: AbstractAdaptor
Provides the opportunity for the Adaptor to create new configuration values or override default values. Only Config.addKey(java.lang.String, java.lang.String) should likely be called. The user's configuration will override any values set in this way. This method is called by AbstractAdaptor.main(com.google.enterprise.adaptor.Adaptor, java.lang.String[]) before Adaptor.init(com.google.enterprise.adaptor.AdaptorContext) is called.

This implementation does nothing.

Specified by:
initConfig in interface Adaptor
Overrides:
initConfig in class AbstractAdaptor

init

public void init(AdaptorContext context)
          throws Exception
Description copied from class: AbstractAdaptor
Initialize adaptor with the current context. This is the ideal time to start any threads to do extra behind-the-scenes work. The context points to other useful objects that can be used at any time. For example, methods on DocIdPusher provided via AdaptorContext.getDocIdPusher() are allowed to be called whenever the Adaptor wishes. This allows doing event-based incremental pushes at any time.

The method is called at the end of GsaCommunicationHandler.start().

If you experience a fatal error during initialization, feel free to throw an Exception to cancel the startup process.

This implementation does nothing.

Specified by:
init in interface Adaptor
Overrides:
init in class AbstractAdaptor
Throws:
Exception

setListerCommand

public void setListerCommand(List<String> commandWithArgs)

getListerCommand

public List<String> getListerCommand()

setRetrieverCommand

public void setRetrieverCommand(List<String> commandWithArgs)

getRetrieverCommand

public List<String> getRetrieverCommand()

getDocIds

public void getDocIds(DocIdPusher pusher)
               throws IOException,
                      InterruptedException
Description copied from interface: Adaptor
Pushes all the DocIds that are suppose to be indexed by the GSA. This will frequently involve re-sending DocIds to the GSA, but this allows healing previous errors and cache inconsistencies. Re-sending DocIds is very fast and should be considered free on the GSA. This method should determine a list of DocIds to push and call DocIdPusher.pushDocIds(java.lang.Iterable) one or more times and DocIdPusher.pushNamedResources(java.util.Map) if using named resources.

pusher is provided as convenience and is the same object provided to Adaptor.init(com.google.enterprise.adaptor.AdaptorContext) previously. This method may take a while and implementations are free to call Thread.sleep(long) occasionally to reduce load.

If you experience a fatal error, feel free to throw an IOException or RuntimeException. In the case of an error, the ExceptionHandler in use in AdaptorContext will determine if and when to retry.

Specified by:
getDocIds in interface Adaptor
Throws:
IOException
InterruptedException

getDocContent

public void getDocContent(Request req,
                          Response resp)
                   throws IOException
Gives the bytes of a document referenced with id.

Specified by:
getDocContent in interface Adaptor
Throws:
IOException

isUserAuthorized

public Map<DocId,AuthzStatus> isUserAuthorized(AuthnIdentity userIdentity,
                                               Collection<DocId> ids)
                                        throws IOException
Determines whether the user identified is allowed to access the DocIds. The user is either anonymous or assumed to be previously authenticated. If an anonymous user is denied access to a document, then the caller may prompt the user to go through an authentication process and then try again.

Returns AuthzStatus.PERMIT for DocIds the user is allowed to access. Retutrns AuthzStatus.DENY for DocIds the user is not allowed to access. If the document exists, AuthzStatus.INDETERMINATE will not be returned for that DocId.

If the document doesn't exist, then there are several possibilities. If the repository is fully-public then it will return PERMIT. This will allow the caller to provide a cached version of the file to the user or call Adaptor.getDocContent(com.google.enterprise.adaptor.Request, com.google.enterprise.adaptor.Response) which should call Response.respondNotFound(). If the adaptor is not sensitive to users knowing that certain documents do not exist, then it will return INDETERMINATE. This will be interpreted as the document does not exist; no cached copy will be provided to the user but the user may be informed the document doesn't exist. Highly sensitive repositories may return DENY.

If you experience a fatal error, feel free to throw an IOException or RuntimeException. In the case of an error, the users will be denied access to the resources.

This implementation provides access permissions for the DocIds in an \ unmodifiable map based upon data returned by a command line authorizer. Permissions can have one of three values: AuthzStatus.PERMIT, AuthzStatus.DENY, AuthzStatus.INDETERMINATE If an authorizerCommand is not set then AbstractAdaptor.isUserAuthorized is used.

Specified by:
isUserAuthorized in interface AuthzAuthority
Parameters:
userIdentity - user to authorize, or null for anonymous users
ids - Collection of DocIds that need to be checked
Returns:
an AuthzStatus for each DocId provided in ids
Throws:
IOException

executeLister

protected int executeLister(String[] commandLine,
                            StreamingCommand.InputSource stdin,
                            StreamingCommand.OutputSink stdout,
                            StreamingCommand.OutputSink stderr)
                     throws IOException,
                            InterruptedException
Throws:
IOException
InterruptedException

executeRetriever

protected int executeRetriever(String[] commandLine,
                               StreamingCommand.InputSource stdin,
                               StreamingCommand.OutputSink stdout,
                               StreamingCommand.OutputSink stderr)
                        throws IOException,
                               InterruptedException
Throws:
IOException
InterruptedException

executeAuthorizer

protected Command.Result executeAuthorizer(String[] commandLine,
                                           byte[] stdin)
                                    throws IOException,
                                           InterruptedException
Throws:
IOException
InterruptedException

main

public static void main(String[] args)
Call default main for adaptors.