Search in sources :

Example 6 with InvalidConfigurationException

use of org.alfresco.jlan.server.config.InvalidConfigurationException in project alfresco-repository by Alfresco.

the class ServerConfigurationBean method processCoreServerConfig.

/**
 * Process the core server configuration
 *
 * @exception InvalidConfigurationException
 */
protected void processCoreServerConfig() throws InvalidConfigurationException {
    // Create the core server configuration section
    CoreServerConfigSection coreConfig = new CoreServerConfigSection(this);
    if (coreServerConfigBean == null) {
        // Configure a default memory pool
        coreConfig.setMemoryPool(DefaultMemoryPoolBufSizes, DefaultMemoryPoolInitAlloc, DefaultMemoryPoolMaxAlloc);
        // Configure a default thread pool size
        coreConfig.setThreadPool(DefaultThreadPoolInit, DefaultThreadPoolMax);
        threadPool = coreConfig.getThreadPool();
        return;
    }
    // Check if the thread pool size has been specified
    Integer initSize = coreServerConfigBean.getThreadPoolInit();
    if (initSize == null) {
        initSize = DefaultThreadPoolInit;
    }
    Integer maxSize = coreServerConfigBean.getThreadPoolMax();
    if (maxSize == null) {
        maxSize = DefaultThreadPoolMax;
    }
    if (initSize < ThreadRequestPool.MinimumWorkerThreads)
        throw new InvalidConfigurationException("Thread pool size below minimum allowed size");
    if (initSize > ThreadRequestPool.MaximumWorkerThreads)
        throw new InvalidConfigurationException("Thread pool size above maximum allowed size");
    if (maxSize < ThreadRequestPool.MinimumWorkerThreads)
        throw new InvalidConfigurationException("Thread pool maximum size below minimum allowed size");
    if (maxSize > ThreadRequestPool.MaximumWorkerThreads)
        throw new InvalidConfigurationException("Thread pool maximum size above maximum allowed size");
    if (maxSize < initSize)
        throw new InvalidConfigurationException("Initial size is larger than maxmimum size");
    // Configure the thread pool
    coreConfig.setThreadPool(initSize, maxSize);
    threadPool = coreConfig.getThreadPool();
    if (coreServerConfigBean.getThreadPoolDebug())
        coreConfig.getThreadPool().setDebug(true);
    // Check if the packet sizes/allocations have been specified
    List<MemoryPacketConfigBean> packetSizes = coreServerConfigBean.getMemoryPacketSizes();
    if (packetSizes != null) {
        // Calculate the array size for the packet size/allocation arrays
        int elemCnt = packetSizes.size();
        // Create the packet size, initial allocation and maximum allocation arrays
        int[] pktSizes = new int[elemCnt];
        int[] initSizes = new int[elemCnt];
        int[] maxSizes = new int[elemCnt];
        int elemIdx = 0;
        // Process the packet size elements
        for (MemoryPacketConfigBean curChild : packetSizes) {
            // Get the packet size
            int pktSize = -1;
            Long pktSizeLong = curChild.getSize();
            if (pktSizeLong == null)
                throw new InvalidConfigurationException("Memory pool packet size not specified");
            try {
                pktSize = MemorySize.getByteValueInt(pktSizeLong.toString());
            } catch (NumberFormatException ex) {
                throw new InvalidConfigurationException("Memory pool packet size, invalid size value, " + pktSizeLong);
            }
            if (elemIdx > 0 && pktSizes[elemIdx - 1] >= pktSize)
                throw new InvalidConfigurationException("Invalid packet size specified, less than/equal to previous packet size");
            // Get the initial allocation for the current packet size
            Integer initAlloc = curChild.getInit();
            if (initAlloc == null)
                throw new InvalidConfigurationException("Memory pool initial allocation not specified");
            if (initAlloc < MemoryPoolMinimumAllocation)
                throw new InvalidConfigurationException("Initial memory pool allocation below minimum of " + MemoryPoolMinimumAllocation);
            if (initAlloc > MemoryPoolMaximumAllocation)
                throw new InvalidConfigurationException("Initial memory pool allocation above maximum of " + MemoryPoolMaximumAllocation);
            // Get the maximum allocation for the current packet size
            Integer maxAlloc = curChild.getMax();
            if (maxAlloc == null)
                throw new InvalidConfigurationException("Memory pool maximum allocation not specified");
            if (maxAlloc < MemoryPoolMinimumAllocation)
                throw new InvalidConfigurationException("Maximum memory pool allocation below minimum of " + MemoryPoolMinimumAllocation);
            if (initAlloc > MemoryPoolMaximumAllocation)
                throw new InvalidConfigurationException("Maximum memory pool allocation above maximum of " + MemoryPoolMaximumAllocation);
            // Set the current packet size elements
            pktSizes[elemIdx] = pktSize;
            initSizes[elemIdx] = initAlloc;
            maxSizes[elemIdx] = maxAlloc;
            elemIdx++;
        }
        if (elemIdx < pktSizes.length) {
            // Re-allocate the packet size/allocation arrays
            int[] newPktSizes = new int[elemIdx];
            int[] newInitSizes = new int[elemIdx];
            int[] newMaxSizes = new int[elemIdx];
            // Copy the values to the shorter arrays
            System.arraycopy(pktSizes, 0, newPktSizes, 0, elemIdx);
            System.arraycopy(initSizes, 0, newInitSizes, 0, elemIdx);
            System.arraycopy(maxSizes, 0, newMaxSizes, 0, elemIdx);
            // Move the new arrays into place
            pktSizes = newPktSizes;
            initSizes = newInitSizes;
            maxSizes = newMaxSizes;
        }
        // Configure the memory pool
        coreConfig.setMemoryPool(pktSizes, initSizes, maxSizes);
    } else {
        // Configure a default memory pool
        coreConfig.setMemoryPool(DefaultMemoryPoolBufSizes, DefaultMemoryPoolInitAlloc, DefaultMemoryPoolMaxAlloc);
    }
}
Also used : CoreServerConfigSection(org.alfresco.jlan.server.config.CoreServerConfigSection) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException)

Example 7 with InvalidConfigurationException

use of org.alfresco.jlan.server.config.InvalidConfigurationException in project alfresco-repository by Alfresco.

the class ServerConfigurationBean method processFTPServerConfig.

/**
 * Process the FTP server configuration
 */
protected void processFTPServerConfig() {
    if (ftpConfigBean == null) {
        removeConfigSection(FTPConfigSection.SectionName);
        return;
    }
    if (!ftpConfigBean.getServerEnabled()) {
        removeConfigSection(FTPConfigSection.SectionName);
        return;
    }
    // Create the FTP configuration section
    FTPConfigSection ftpConfig = new FTPConfigSection(this);
    try {
        // Check for a bind address
        String bindText = ftpConfigBean.getBindTo();
        if (bindText != null && bindText.length() > 0 && !bindText.equals(BIND_TO_IGNORE)) {
            try {
                // Check the bind address
                InetAddress bindAddr = InetAddress.getByName(bindText);
                // Set the bind address for the FTP server
                ftpConfig.setFTPBindAddress(bindAddr);
            } catch (UnknownHostException ex) {
                throw new AlfrescoRuntimeException("Unable to find FTP bindto address, " + bindText, ex);
            }
        }
        // Check for an FTP server port
        Integer port = ftpConfigBean.getPort();
        if (port != null) {
            ftpConfig.setFTPPort(port);
            if (ftpConfig.getFTPPort() <= 0 || ftpConfig.getFTPPort() >= 65535)
                throw new AlfrescoRuntimeException("FTP server port out of valid range");
        } else {
            // Use the default FTP port
            ftpConfig.setFTPPort(DefaultFTPServerPort);
        }
        // Check for an FTP server timeout for connection to client
        Integer sessionTimeout = ftpConfigBean.getSessionTimeout();
        if (sessionTimeout != null) {
            ftpConfig.setFTPSrvSessionTimeout(sessionTimeout);
            if (ftpConfig.getFTPSrvSessionTimeout() < 0)
                throw new AlfrescoRuntimeException("FTP server session timeout must have positive value or zero");
        } else {
            // Use the default timeout
            ftpConfig.setFTPSrvSessionTimeout(DefaultFTPSrvSessionTimeout);
        }
        if (ftpConfigBean.getAllowAnonymous()) {
            // Enable anonymous login to the FTP server
            ftpConfig.setAllowAnonymousFTP(true);
            // Check if an anonymous account has been specified
            String anonAcc = ftpConfigBean.getAnonymousAccount();
            if (anonAcc != null && anonAcc.length() > 0) {
                // Set the anonymous account name
                ftpConfig.setAnonymousFTPAccount(anonAcc);
                if (ftpConfig.getAnonymousFTPAccount() == null || ftpConfig.getAnonymousFTPAccount().length() == 0) {
                    throw new AlfrescoRuntimeException("Anonymous FTP account invalid");
                }
            } else {
                // Use the default anonymous account name
                ftpConfig.setAnonymousFTPAccount(DefaultFTPAnonymousAccount);
            }
        } else {
            // Disable anonymous logins
            ftpConfig.setAllowAnonymousFTP(false);
        }
        // Check if a root path has been specified
        String rootPath = ftpConfigBean.getRootDirectory();
        if (rootPath != null && rootPath.length() > 0) {
            try {
                // Parse the path
                new FTPPath(rootPath);
                // Set the root path
                ftpConfig.setFTPRootPath(rootPath);
            } catch (InvalidPathException ex) {
                throw new AlfrescoRuntimeException("Invalid FTP root directory, " + rootPath);
            }
        }
        // Check for FTP debug flags
        String flags = ftpConfigBean.getDebugFlags();
        int ftpDbg = 0;
        if (flags != null) {
            // Parse the flags
            flags = flags.toUpperCase();
            StringTokenizer token = new StringTokenizer(flags, ",");
            while (token.hasMoreTokens()) {
                // Get the current debug flag token
                String dbg = token.nextToken().trim();
                // Find the debug flag name
                int idx = 0;
                while (idx < m_ftpDebugStr.length && m_ftpDebugStr[idx].equalsIgnoreCase(dbg) == false) idx++;
                if (idx >= m_ftpDebugStr.length)
                    throw new AlfrescoRuntimeException("Invalid FTP debug flag, " + dbg);
                // Set the debug flag
                ftpDbg += 1 << idx;
            }
            // Set the FTP debug flags
            ftpConfig.setFTPDebug(ftpDbg);
        }
        // Check if a character set has been specified
        String charSet = ftpConfigBean.getCharSet();
        if (charSet != null && charSet.length() > 0) {
            try {
                // Validate the character set name
                Charset.forName(charSet);
                // Set the FTP character set
                ftpConfig.setFTPCharacterSet(charSet);
            } catch (IllegalCharsetNameException ex) {
                throw new AlfrescoRuntimeException("FTP Illegal character set name, " + charSet);
            } catch (UnsupportedCharsetException ex) {
                throw new AlfrescoRuntimeException("FTP Unsupported character set name, " + charSet);
            }
        }
        // Check if an authenticator has been specified
        FTPAuthenticator auth = ftpConfigBean.getAuthenticator();
        if (auth != null) {
            // Initialize and set the authenticator class
            ftpConfig.setAuthenticator(auth);
        } else
            throw new AlfrescoRuntimeException("FTP authenticator not specified");
        if (ftpConfigBean.getDataPortFrom() != 0 && ftpConfigBean.getDataPortTo() != 0) {
            // Range check the data port values
            int rangeFrom = ftpConfigBean.getDataPortFrom();
            int rangeTo = ftpConfigBean.getDataPortTo();
            if (rangeFrom != 0 && rangeTo != 0) {
                if (rangeFrom < 1024 || rangeFrom > 65535)
                    throw new InvalidConfigurationException("Invalid FTP data port range from value, " + rangeFrom);
                if (rangeTo < 1024 || rangeTo > 65535)
                    throw new InvalidConfigurationException("Invalid FTP data port range to value, " + rangeTo);
                if (rangeFrom >= rangeTo)
                    throw new InvalidConfigurationException("Invalid FTP data port range, " + rangeFrom + "-" + rangeTo);
                // Set the FTP data port range
                ftpConfig.setFTPDataPortLow(rangeFrom);
                ftpConfig.setFTPDataPortHigh(rangeTo);
                // Log the data port range
                logger.info("FTP server data ports restricted to range " + rangeFrom + ":" + rangeTo);
            }
        }
        // Check for an external address
        String ExtAddr = ftpConfigBean.getExternalAddress();
        if (ExtAddr != null && ExtAddr.length() > 0) {
            ftpConfig.setFTPExternalAddress(ExtAddr);
        }
        if (ftpConfigBean.getKeyStorePath() != null && ftpConfigBean.getKeyStorePath().length() > 0) {
            // Get the path to the key store, check that the file exists
            String keyStorePath = ftpConfigBean.getKeyStorePath();
            File keyStoreFile = new File(keyStorePath);
            if (keyStoreFile.exists() == false)
                throw new InvalidConfigurationException("FTPS key store file does not exist, " + keyStorePath);
            else if (keyStoreFile.isDirectory())
                throw new InvalidConfigurationException("FTPS key store path is a directory, " + keyStorePath);
            // Set the key store path
            ftpConfig.setKeyStorePath(keyStorePath);
            if (ftpConfigBean.getKeyStoreType() != null && ftpConfigBean.getKeyStoreType().length() > 0) {
                // Get the key store type, and validate
                String keyStoreType = ftpConfigBean.getKeyStoreType();
                if (keyStoreType == null || keyStoreType.length() == 0)
                    throw new InvalidConfigurationException("FTPS key store type is invalid");
                try {
                    KeyStore.getInstance(keyStoreType);
                } catch (KeyStoreException ex) {
                    throw new InvalidConfigurationException("FTPS key store type is invalid, " + keyStoreType, ex);
                }
                // Set the key store type
                ftpConfig.setKeyStoreType(keyStoreType);
            }
            if (ftpConfigBean.getKeyStorePassphrase() != null && ftpConfigBean.getKeyStorePassphrase().length() > 0) {
                // Set the key store passphrase
                ftpConfig.setKeyStorePassphrase(ftpConfigBean.getKeyStorePassphrase());
            }
        }
        if (ftpConfigBean.getTrustStorePath() != null && ftpConfigBean.getTrustStorePath().length() > 0) {
            // Get the path to the trust store, check that the file exists
            String trustStorePath = ftpConfigBean.getTrustStorePath();
            File trustStoreFile = new File(trustStorePath);
            if (trustStoreFile.exists() == false)
                throw new InvalidConfigurationException("FTPS trust store file does not exist, " + trustStorePath);
            else if (trustStoreFile.isDirectory())
                throw new InvalidConfigurationException("FTPS trust store path is a directory, " + trustStorePath);
            // Set the trust store path
            ftpConfig.setTrustStorePath(trustStorePath);
            if (ftpConfigBean.getTrustStoreType() != null && ftpConfigBean.getTrustStoreType().length() > 0) {
                // Get the trust store type, and validate
                String trustStoreType = ftpConfigBean.getTrustStoreType();
                if (trustStoreType == null || trustStoreType.length() == 0)
                    throw new InvalidConfigurationException("FTPS trust store type is invalid");
                try {
                    KeyStore.getInstance(trustStoreType);
                } catch (KeyStoreException ex) {
                    throw new InvalidConfigurationException("FTPS trust store type is invalid, " + trustStoreType, ex);
                }
                // Set the trust store type
                ftpConfig.setTrustStoreType(trustStoreType);
            }
            if (ftpConfigBean.getTrustStorePassphrase() != null && ftpConfigBean.getTrustStorePassphrase().length() > 0) {
                // Set the trust store passphrase
                ftpConfig.setTrustStorePassphrase(ftpConfigBean.getTrustStorePassphrase());
            }
        }
        if (ftpConfigBean.hasRequireSecureSession()) {
            // Only allow secure sessions to logon to the FTP server
            ftpConfig.setRequireSecureSession(true);
        }
        // MNT-7301 FTPS server requires unnecessarly to have a trustStore while a keyStore should be sufficient
        if (ftpConfig.getKeyStorePath() != null) {
            if (ftpConfig.getKeyStorePath() == null)
                throw new InvalidConfigurationException("FTPS configuration requires keyStore to be set");
        }
        if (ftpConfigBean.hasSslEngineDebug()) {
            // Enable SSLEngine debug output
            System.setProperty("javax.net.debug", "ssl,handshake");
        }
    } catch (InvalidConfigurationException ex) {
        throw new AlfrescoRuntimeException(ex.getMessage());
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) KeyStoreException(java.security.KeyStoreException) InvalidPathException(org.alfresco.jlan.ftp.InvalidPathException) FTPAuthenticator(org.alfresco.jlan.ftp.FTPAuthenticator) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) StringTokenizer(java.util.StringTokenizer) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FTPConfigSection(org.alfresco.jlan.ftp.FTPConfigSection) InetAddress(java.net.InetAddress) File(java.io.File) FTPPath(org.alfresco.jlan.ftp.FTPPath)

Example 8 with InvalidConfigurationException

use of org.alfresco.jlan.server.config.InvalidConfigurationException in project alfresco-repository by Alfresco.

the class AbstractServerConfigurationBean method parseAdapterName.

/**
 * Parse an adapter name string and return the matching address
 *
 * @param adapter String
 * @return InetAddress
 * @exception InvalidConfigurationException
 */
protected final InetAddress parseAdapterName(String adapter) throws InvalidConfigurationException {
    NetworkInterface ni = null;
    try {
        ni = NetworkInterface.getByName(adapter);
    } catch (SocketException ex) {
        throw new InvalidConfigurationException("Invalid adapter name, " + adapter);
    }
    if (ni == null)
        throw new InvalidConfigurationException("Invalid network adapter name, " + adapter);
    // Get the IP address for the adapter
    InetAddress adapAddr = null;
    Enumeration<InetAddress> addrEnum = ni.getInetAddresses();
    while (addrEnum.hasMoreElements() && adapAddr == null) {
        // Get the current address
        InetAddress addr = addrEnum.nextElement();
        if (IPAddress.isNumericAddress(addr.getHostAddress()))
            adapAddr = addr;
    }
    if (adapAddr == null)
        throw new InvalidConfigurationException("Adapter " + adapter + " does not have a valid IP address");
    return adapAddr;
}
Also used : SocketException(java.net.SocketException) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException)

Example 9 with InvalidConfigurationException

use of org.alfresco.jlan.server.config.InvalidConfigurationException in project alfresco-repository by Alfresco.

the class AbstractServerConfigurationBean method init.

/**
 * Initialize the configuration using the configuration service
 */
public void init() {
    if (m_authenticationComponent == null) {
        throw new AlfrescoRuntimeException("Property 'authenticationComponent' not set");
    } else if (m_authenticationService == null) {
        throw new AlfrescoRuntimeException("Property 'authenticationService' not set");
    } else if (m_nodeService == null) {
        throw new AlfrescoRuntimeException("Property 'nodeService' not set");
    } else if (m_personService == null) {
        throw new AlfrescoRuntimeException("Property 'personService' not set");
    } else if (m_transactionService == null) {
        throw new AlfrescoRuntimeException("Property 'transactionService' not set");
    } else if (m_repoDiskInterface == null) {
        throw new AlfrescoRuntimeException("Property 'diskInterface' not set");
    } else if (m_authorityService == null) {
        throw new AlfrescoRuntimeException("Property 'authorityService' not set");
    }
    // Set the platform type
    determinePlatformType();
    // Create the debug output configuration using a logger for all file server debug output
    DebugConfigSection debugConfig = new DebugConfigSection(this);
    try {
        debugConfig.setDebug("org.alfresco.filesys.debug.FileServerDebugInterface", new GenericConfigElement("params"));
    } catch (InvalidConfigurationException ex) {
    }
    // Create the global configuration and Alfresco configuration sections
    new GlobalConfigSection(this);
    new AlfrescoConfigSection(this);
    // Install the Alfresco client information factory
    ClientInfo.setFactory(new AlfrescoClientInfoFactory());
    try {
        // Get the CIFS server config section and extract the WINS server config, if available
        processWINSServerConfig();
    } catch (Exception ex) {
        // Configuration error
        logger.error("File server configuration error (WINS), " + ex.getMessage(), ex);
    }
    try {
        // Process the core server configuration
        processCoreServerConfig();
        // Process the security configuration
        processSecurityConfig();
        // Process the filesystems configuration
        processFilesystemsConfig();
    } catch (Exception ex) {
        // Configuration error
        throw new AlfrescoRuntimeException("File server configuration error, " + ex.getMessage(), ex);
    }
    try {
        // Process the FTP server configuration
        processFTPServerConfig();
        // Log the successful startup
        logger.info("FTP server " + (isFTPServerEnabled() ? "" : "NOT ") + "started");
    } catch (Exception ex) {
        // Configuration error
        logger.error("FTP server configuration error, " + ex.getMessage(), ex);
    }
}
Also used : GenericConfigElement(org.springframework.extensions.config.element.GenericConfigElement) AlfrescoClientInfoFactory(org.alfresco.filesys.alfresco.AlfrescoClientInfoFactory) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) GlobalConfigSection(org.alfresco.jlan.server.config.GlobalConfigSection) DebugConfigSection(org.alfresco.jlan.debug.DebugConfigSection) SocketException(java.net.SocketException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException) BeansException(org.springframework.beans.BeansException) UnknownHostException(java.net.UnknownHostException) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (org.alfresco.jlan.server.config.InvalidConfigurationException)9 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 GenericConfigElement (org.springframework.extensions.config.element.GenericConfigElement)3 InetAddress (java.net.InetAddress)2 SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 AccessControlListBean (org.alfresco.filesys.config.acl.AccessControlListBean)2 AccessControlList (org.alfresco.jlan.server.auth.acl.AccessControlList)2 SecurityConfigSection (org.alfresco.jlan.server.config.SecurityConfigSection)2 FilesystemsConfigSection (org.alfresco.jlan.server.filesys.FilesystemsConfigSection)2 FileStateLockManager (org.alfresco.jlan.server.filesys.cache.FileStateLockManager)2 StandaloneFileStateCache (org.alfresco.jlan.server.filesys.cache.StandaloneFileStateCache)2 File (java.io.File)1 IOException (java.io.IOException)1 NetworkInterface (java.net.NetworkInterface)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 KeyStoreException (java.security.KeyStoreException)1 LinkedList (java.util.LinkedList)1 StringTokenizer (java.util.StringTokenizer)1