You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ch...@apache.org on 2001/05/11 11:39:41 UTC

cvs commit: jakarta-james/src/org/apache/james/services DNSServer.java MailRepository.java MailServer.java MailStore.java SpoolRepository.java UsersRepository.java UsersStore.java

charlesb    01/05/11 02:39:40

  Added:       src/java/org/apache/james/remotemanager RemoteManager.java
                        RemoteManager.xinfo RemoteManagerHandler.java
               src/java/org/apache/james/services DNSServer.java
                        MailRepository.java MailServer.java MailStore.java
                        SpoolRepository.java UsersRepository.java
                        UsersStore.java
  Removed:     src/org/apache/james/remotemanager RemoteManager.java
                        RemoteManager.xinfo RemoteManagerHandler.java
               src/org/apache/james/services DNSServer.java
                        MailRepository.java MailServer.java MailStore.java
                        SpoolRepository.java UsersRepository.java
                        UsersStore.java
  Log:
  Moving from src/org to src/java/org
  
  Revision  Changes    Path
  1.1                  jakarta-james/src/java/org/apache/james/remotemanager/RemoteManager.java
  
  Index: RemoteManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.remotemanager;
  
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.cornerstone.services.connection.AbstractService;
  import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
  import org.apache.avalon.cornerstone.services.connection.DefaultHandlerFactory;
  
  /**
   * Provides a really rude network interface to administer James.
   * Allow to add accounts.
   * TODO: -improve protocol
   *       -add remove user
   *       -much more...
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class RemoteManager 
      extends AbstractService {
  
      protected ConnectionHandlerFactory createFactory()
      {
          return new DefaultHandlerFactory( RemoteManagerHandler.class );
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException {
  
          m_port = configuration.getChild( "port" ).getValueAsInteger( 4554 );
  
          try 
          { 
              final String bindAddress = configuration.getChild( "bind" ).getValue( null );
              if( null != bindAddress )
              {
                  m_bindTo = InetAddress.getByName( bindAddress ); 
              }
          }
          catch( final UnknownHostException unhe ) 
          {
              throw new ConfigurationException( "Malformed bind parameter", unhe );
          }
  
          final String useTLS = configuration.getChild( "useTLS" ).getValue( "" );
          if( useTLS.equals( "TRUE" ) ) m_serverSocketType = "ssl";
  
          super.configure( configuration.getChild( "handler" ) );
      }
  
      public void initialize() throws Exception {
  
          getLogger().info( "RemoteManager init..." );
          getLogger().info( "RemoteManager using " + m_serverSocketType + " on port " + m_port );
          super.initialize();
          getLogger().info("RemoteManager ...init end");
      }
  }
  
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/remotemanager/RemoteManager.xinfo
  
  Index: RemoteManager.xinfo
  ===================================================================
  <?xml version="1.0"?>
  
  <blockinfo>
    <services>
      <service name="org.apache.avalon.framework.component.Component" version="1.0"/>
    </services>
  
    <dependencies>
      <dependency>
        <role>org.apache.james.services.MailStore</role>
        <service name="org.apache.james.services.MailStore" version="1.0"/>
      </dependency>
      <dependency>
        <role>org.apache.james.services.UsersStore</role>
        <service name="org.apache.james.services.UsersStore" version="1.0"/>
      </dependency>
      <dependency>
        <role>org.apache.avalon.cornerstone.services.connection.ConnectionManager</role>
        <service name="org.apache.avalon.cornerstone.services.connection.ConnectionManager" 
                 version="1.0"/>
      </dependency>
      <dependency>
        <role>org.apache.avalon.cornerstone.services.sockets.SocketManager</role>
        <service name="org.apache.avalon.cornerstone.services.sockets.SocketManager" version="1.0"/>
      </dependency>
      <dependency>
        <role>org.apache.avalon.cornerstone.services.scheduler.TimeScheduler</role>
        <service name="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler" version="1.0"/>
      </dependency> 
      <dependency>
        <role>org.apache.james.services.MailServer</role>
        <service name="org.apache.james.services.MailServer" version="1.0"/>
      </dependency> 
    </dependencies>  
  </blockinfo>
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
  
  Index: RemoteManagerHandler.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.remotemanager;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
  import org.apache.avalon.cornerstone.services.scheduler.PeriodicTimeTrigger;
  import org.apache.avalon.cornerstone.services.scheduler.Target;
  import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
  import org.apache.james.Constants;
  import org.apache.james.BaseConnectionHandler;
  import org.apache.james.services.MailServer;
  import org.apache.james.services.UsersRepository;
  import org.apache.james.services.UsersStore;
  
  /**
   * Provides a really rude network interface to administer James.
   * Allow to add accounts.
   * TODO: -improve protocol
   *       -add remove user
   *       -much more...
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   *
   */
  public class RemoteManagerHandler
      extends BaseConnectionHandler
      implements ConnectionHandler, Composable, Configurable, Target {
  
      private UsersStore usersStore;
      private UsersRepository users;
      private TimeScheduler scheduler;
      private MailServer mailServer;
  
      private BufferedReader in;
      private PrintWriter out;
      private HashMap admaccount = new HashMap();
      private Socket socket;
  
      public void configure( final Configuration configuration )
          throws ConfigurationException {
  
          timeout = configuration.getChild( "connectiontimeout" ).getValueAsInteger( 120000 );
  
          final Configuration admin = configuration.getChild( "administrator_accounts" );
          final Configuration[] accounts = admin.getChildren( "account" );
          for ( int i = 0; i < accounts.length; i++ )
          {
              admaccount.put( accounts[ i ].getAttribute( "login" ),
                              accounts[ i ].getAttribute( "password" ) );
          }
      }
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException {
  
          scheduler = (TimeScheduler)componentManager.
              lookup( "org.apache.avalon.cornerstone.services.scheduler.TimeScheduler" );
          mailServer = (MailServer)componentManager.
              lookup( "org.apache.james.services.MailServer" );
          usersStore = (UsersStore)componentManager.
              lookup( "org.apache.james.services.UsersStore" );
          users = usersStore.getRepository("LocalUsers");;
      }
  
      /**
       * Handle a connection.
       * This handler is responsible for processing connections as they occur.
       *
       * @param connection the connection
       * @exception IOException if an error reading from socket occurs
       * @exception ProtocolException if an error handling connection occurs
       */
      public void handleConnection( final Socket connection )
          throws IOException {
  
          /*
            if( admaccount.isEmpty() ) {
            getLogger().warn("No Administrative account defined");
            getLogger().warn("RemoteManager failed to be handled");
            return;
            }
          */
  
          final PeriodicTimeTrigger trigger = new PeriodicTimeTrigger( timeout, -1 );
          scheduler.addTrigger( this.toString(), trigger, this );
          socket = connection;
          String remoteHost = socket.getInetAddress().getHostName();
          String remoteIP = socket.getInetAddress().getHostAddress();
  
          try {
              in = new BufferedReader(new InputStreamReader( socket.getInputStream() ));
              out = new PrintWriter( socket.getOutputStream(), true);
              getLogger().info( "Access from " + remoteHost + "(" + remoteIP + ")" );
              out.println( "JAMES RemoteAdministration Tool " + Constants.SOFTWARE_VERSION );
              out.println("Please enter your login and password");
  	    out.println("Login id:");
              String login = in.readLine();
  	    out.println("Password:");
              String password = in.readLine();
  
              while (!password.equals(admaccount.get(login)) || password.length() == 0) {
                  scheduler.resetTrigger(this.toString());
                  final String message = "Login failed for " + login;
                  out.println( message );
                  getLogger().info( message );
                  login = in.readLine();
                  password = in.readLine();
              }
  
              scheduler.resetTrigger(this.toString());
  
              out.println( "Welcome " + login + ". HELP for a list of commands" );
              getLogger().info("Login for " + login + " succesful");
  
              while (parseCommand(in.readLine())) {
                  scheduler.resetTrigger(this.toString());
              }
              getLogger().info("Logout for " + login + ".");
              socket.close();
  
          } catch ( final IOException e ) {
              out.println("Error. Closing connection");
              out.flush();
              getLogger().error( "Exception during connection from " + remoteHost +
                                 " (" + remoteIP + ")");
          }
  
          scheduler.removeTrigger(this.toString());
      }
  
      public void targetTriggered( final String triggerName ) {
          getLogger().error("Connection timeout on socket");
          try {
              out.println("Connection timeout. Closing connection");
              socket.close();
          } catch ( final IOException ioe ) {
          }
      }
  
      private boolean parseCommand( String command ) {
          if (command == null) return false;
          StringTokenizer commandLine = new StringTokenizer(command.trim(), " ");
          int arguments = commandLine.countTokens();
          if (arguments == 0) {
              return true;
          } else if(arguments > 0) {
              command = commandLine.nextToken();
          }
          String argument = (String) null;
          if(arguments > 1) {
              argument = commandLine.nextToken();
          }
          String argument1 = (String) null;
          if(arguments > 2) {
              argument1 = commandLine.nextToken();
          }
          if (command.equalsIgnoreCase("ADDUSER")) {
              String user = argument;
              String passwd = argument1;
              try {
                  if (user.equals("") || passwd.equals("")) {
                      out.println("usage: adduser [username] [password]");
                      return true;
                  }
              } catch (NullPointerException e) {
                  out.println("usage: adduser [username] [password]");
                  return true;
              }
              if (users.contains(user)) {
                  out.println("user " + user + " already exist");
              } else {
                  if(mailServer.addUser(user, passwd)) {
                      out.println("User " + user + " added");
                      getLogger().info("User " + user + " added");
                  } else {
                      out.println("Error adding user " + user);
                      getLogger().info("Error adding user " + user);
                  }
              }
              out.flush();
          } else if (command.equalsIgnoreCase("DELUSER")) {
              String user = argument;
              if (user.equals("")) {
                  out.println("usage: deluser [username]");
                  return true;
              }
              try {
                  users.removeUser(user);
              } catch (Exception e) {
                  out.println("Error deleting user " + user + " : " + e.getMessage());
                  return true;
              }
              out.println("User " + user + " deleted");
              getLogger().info("User " + user + " deleted");
          } else if (command.equalsIgnoreCase("LISTUSERS")) {
              out.println("Existing accounts " + users.countUsers());
              for (Iterator it = users.list(); it.hasNext();) {
                  out.println("user: " + (String) it.next());
              }
          } else if (command.equalsIgnoreCase("COUNTUSERS")) {
              out.println("Existing accounts " + users.countUsers());
          } else if (command.equalsIgnoreCase("VERIFY")) {
              String user = argument;
              if (user.equals("")) {
                  out.println("usage: verify [username]");
                  return true;
              }
              if (users.contains(user)) {
                  out.println("User " + user + " exist");
              } else {
                  out.println("User " + user + " does not exist");
              }
          } else if (command.equalsIgnoreCase("HELP")) {
              out.println("Currently implemented commans:");
              out.println("help                            display this help");
              out.println("adduser [username] [password]   add a new user");
              out.println("deluser [username]              delete existing user");
              out.println("listusers                       display existing accounts");
              out.println("countusers                      display the number of existing accounts");
              out.println("verify [username]               verify if specified user exist");
              out.println("quit                            close connection");
              out.flush();
          } else if (command.equalsIgnoreCase("QUIT")) {
              out.println("bye");
              return false;
          } else {
              out.println("unknown command " + command);
          }
          return true;
      }
  }
  
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/services/DNSServer.java
  
  Index: DNSServer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.services;
  
  import java.util.Collection;
  
  public interface DNSServer {
      Collection findMXRecords(String hostname);
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/services/MailRepository.java
  
  Index: MailRepository.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.services;
  
  import java.util.Iterator;
  import org.apache.james.core.MailImpl;
  
  /**
   * Interface for a Repository to store Mails.
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
   */
  public interface MailRepository {
  
      /**
       * Define a MAIL repository. MAILS are stored in the specified
       * destination.
       */
      String MAIL = "MAIL";
  
  
      /**
       * Stores a message in this repository. Shouldn't this return the key
       * under which it is stored?
       */
      void store( MailImpl mc );
  
      /**
       * List string keys of messages in repository.
       *
       */
      Iterator list();
  
      /**
       * Retrieves a message given a key. At the moment, keys can be obtained
       * from list() in superinterface Store.Repository
       */
      MailImpl retrieve( String key );
  
      /**
       * Removes a specified message
       */
      void remove( MailImpl mail );
  
      /**
       * Removes a message identifed by key.
       */
      void remove( String key );
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/services/MailServer.java
  
  Index: MailServer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.services;
  
  import java.io.InputStream;
  import java.util.Collection;
  import javax.mail.MessagingException;
  import javax.mail.internet.*;
  import org.apache.mailet.Mail;
  import org.apache.mailet.MailAddress;
  import org.apache.avalon.phoenix.Service;
  
  /**
   * The interface for Phoenix blocks to the James MailServer
   *
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
   */
  public interface MailServer 
      extends Service {
  
      /**
       * Reserved user name for the mail delivery agent for multi-user mailboxes
       */
      String MDA = "JamesMDA"; 
  
      /**
       * Reserved user name meaning all users for multi-user mailboxes
       */
      String ALL = "AllMailUsers";
  
      void sendMail(MailAddress sender, Collection recipients, MimeMessage msg)
          throws MessagingException;
  
      void sendMail(MailAddress sender, Collection recipients, InputStream msg)
          throws MessagingException;
  
      void sendMail(Mail mail)
          throws MessagingException;
  
      MailRepository getUserInbox(String userName);
  
      String getId();
  
      boolean addUser(String userName, String password);
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/services/MailStore.java
  
  Index: MailStore.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.services;
  
  import org.apache.avalon.cornerstone.services.store.Store;
  
  /**
   * Interface for an object which provides MailRepositories or SpoolRepositories
   *
   * <p>The select method requires a configuration object with the form:
   *  <br><repository destinationURL="file://path-to-root-dir-for-repository"
   *  <br>            type="MAIL"
   *  <br>            model="SYNCHRONOUS"/>
   *  <br></repository>
   * <p>This configuration, including any included child elements, is used to configure 
   * the returned component.
   *
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
   */
  public interface MailStore 
      extends Store {
      // MailRepository getInbox(String user);
  }
   
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/services/SpoolRepository.java
  
  Index: SpoolRepository.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.services;
  
  /**
   * Interface for a Repository for Spooling Mails.
   * A spool repository is a transitory repository which should empty itself 
   * if inbound deliveries stop.
   *
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   */
  public interface SpoolRepository 
      extends MailRepository {
  
      /**
       * Define a STREAM repository. Streams are stored in the specified
       * destination.
       */
      String SPOOL = "SPOOL";
  
      /**
       * Returns the key for an arbitrarily selected mail deposited in this Repository.
       * Useage: SpoolManager calls accept() to see if there are any unprocessed 
       * mails in the spool repository.
       */
      String accept();
  
      /**
       * Returns the key for an arbitrarily select mail depository in this Repositry that
       * is either ready immediately for delivery, or is younger than it's last_updated plus
       * the number of failed attempts times the delay time.
       * Useage: RemoteDeliverySpool calls accept() with some delay and should block until an
       * unprocessed mail is available.
       */
      String accept(long delay);
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/services/UsersRepository.java
  
  Index: UsersRepository.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.services;
  
  import java.util.Iterator;
  
  /**
   * Interface for a repository of users. A repository represents a logical
   * grouping of users, typically by common purpose. E.g. the users served by an
   * email server or the members of a mailing list.
   *
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   */
  public interface UsersRepository {
  
      String USER = "USER";
  
      /**
       * Adds a user to the repository with the specified attributes.  In current
       * implementations, the Object attributes is generally a String password.
       */
      void addUser(String name, Object attributes);
  
      /**
       * Gets the attribute for a user.  Not clear on behavior.
       */
      Object getAttributes(String name);
  
      /**
       * Removes a user from the repository
       */
      void removeUser(String name);
  
      /**
       * Returns whether or not this user is in the repository
       */
      boolean contains(String name);
  
      /**
       * Tests a user with the appropriate attributes.  In current implementations,
       * this typically means "check the password" where a String password is passed
       * as the Object attributes.
       */
      boolean test(String name, Object attributes);
  
      /**
       * Returns a count of the users in the repository.
       */
      int countUsers();
  
      /**
       * List users in repository.
       *
       * @returns Iterator over a collection of Strings, each being one user in the repository.
       */
      Iterator list();
  
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/services/UsersStore.java
  
  Index: UsersStore.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.services;
  
  import org.apache.avalon.phoenix.Service;
  
  /**
   * Interface for Phoenix blocks to access a store of Users. A UserStore
   * contains one or more UserRepositories. Multiple UserRepositories may or may
   * not have overlapping membership. 
   *
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
   */
  public interface UsersStore 
      extends Service {
  
      UsersRepository getRepository( String name );
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org