All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anrisoftware.sscontrol.mail.postfix.saslauth.linux.BaseSaslAuth.groovy Maven / Gradle / Ivy

/*
 * Copyright 2013-2014 Erwin Müller 
 *
 * This file is part of sscontrol-mail-postfix.
 *
 * sscontrol-mail-postfix is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * sscontrol-mail-postfix is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with sscontrol-mail-postfix. If not, see .
 */
package com.anrisoftware.sscontrol.mail.postfix.saslauth.linux

import groovy.util.logging.Slf4j

import java.util.regex.Pattern

import javax.inject.Inject

import com.anrisoftware.globalpom.textmatch.tokentemplate.TokenTemplate
import com.anrisoftware.propertiesutils.ContextProperties
import com.anrisoftware.resources.templates.api.TemplateResource
import com.anrisoftware.resources.templates.api.Templates
import com.anrisoftware.resources.templates.api.TemplatesFactory
import com.anrisoftware.sscontrol.mail.postfix.linux.AuthConfig
import com.anrisoftware.sscontrol.mail.postfix.script.linux.BaseAuth
import com.anrisoftware.sscontrol.scripts.localchangeuser.LocalChangeUserFactory

/**
 * SASL/authentication.
 *
 * @author Erwin Mueller, [email protected]
 * @since 1.0
 */
@Slf4j
abstract class BaseSaslAuth extends BaseAuth implements AuthConfig {

    public static final String NAME = "sasl"

    @Inject
    private BaseSaslAuthLogger logg

    @Inject
    private TemplatesFactory templatesFactory

    @Inject
    private LocalChangeUserFactory localChangeUserFactory

    /**
     * SASL/authentication templates.
     */
    private Templates salsTemplates

    /**
     * The {@code "main.cf"} configuration templates.
     */
    private TemplateResource mainSaslConfTemplate

    /**
     * The {@code "saslauthd"} configuration templates.
     */
    private TemplateResource saslAuthConfTemplate

    @Override
    void deployAuth() {
        salsTemplates = templatesFactory.create "BaseSalsAuth"
        mainSaslConfTemplate = salsTemplates.getResource "mainconf"
        saslAuthConfTemplate = salsTemplates.getResource "saslauthconf"
        updatePostfixUser()
        makeChrootDirectory()
        deployMain()
        deploySaslauthd()
    }

    /**
     * Update the Postfix user.
     */
    void updatePostfixUser() {
        localChangeUserFactory.create(
                log: log,
                command: script.userModCommand,
                userName: postfixUser, groups: [saslGroup],
                this, threads)()
    }

    /**
     * Returns the SASL local group, for example {@code "sasl"}.
     *
     * 
    *
  • profile property {@code "sasl_group"}
  • *
* * @see #getDefaultProperties() */ String getSaslGroup() { profileProperty "sasl_group", authProperties } /** * Creates the Postfix chroot {@code saslauthd} directory. */ void makeChrootDirectory() { chrootSaslauthdDirectory.mkdirs() logg.chrootDirectoryCreated script, chrootSaslauthdDirectory } /** * Returns the Postfix chroot {@code saslauthd} directory, for * example {@code "/var/spool/postfix/var/run/saslauthd".} * *
    *
  • profile property {@code "chroot_saslauthd_directory"}
  • *
* * @see #getDefaultProperties() */ File getChrootSaslauthdDirectory() { profileDirProperty "chroot_saslauthd_directory", authProperties } /** * Configures the Postfix {@code main.cf} configuration. * * @see #getMainFile() */ void deployMain() { def configuration = [] configuration << saslAuthEnableConf() configuration << allowBrokenSaslAuthClientsConf() configuration << saslSecurityOptionsConf() configuration << saslLocalDomainConf() deployConfiguration configurationTokens(), script.currentMainConfiguration, configuration, script.mainFile } def saslAuthEnableConf() { def replace = mainSaslConfTemplate.getText(true, "authEnableConfig", "enabled", saslAuthEnabled) def search = mainSaslConfTemplate.getText(true, "authEnableConfig_search") new TokenTemplate(search, replace, escape: false) } /** * Returns that SASL authentication is enabled, for example {@code "true"}. * *
    *
  • profile property {@code "sasl_auth_enabled"}
  • *
* * @see #getDefaultProperties() */ boolean getSaslAuthEnabled() { profileBooleanProperty "sasl_auth_enabled", script.defaultProperties } def allowBrokenSaslAuthClientsConf() { def replace = mainSaslConfTemplate.getText(true, "allowBrokenSaslAuthClientsConfig", "enabled", allowBrokenSaslAuthClients) def search = mainSaslConfTemplate.getText(true, "allowBrokenSaslAuthClientsConfig_search") new TokenTemplate(search, replace, escape: false) } /** * Returns that allow broken SASL authentication is enabled, for * example {@code "true"}. * *
    *
  • profile property {@code "allow_broken_sasl_auth_clients"}
  • *
* * @see #getAuthProperties() */ boolean getAllowBrokenSaslAuthClients() { profileBooleanProperty "allow_broken_sasl_auth_clients", authProperties } def saslSecurityOptionsConf() { def replace = mainSaslConfTemplate.getText(true, "saslSecurityOptionsConfig", "options", saslSecurityOptions) def search = mainSaslConfTemplate.getText(true, "saslSecurityOptionsConfig_search") new TokenTemplate(search, replace, escape: false) } /** * Returns SASL authentication security options, for * example {@code "noanonymous"}. * *
    *
  • profile property {@code "sasl_security_options"}
  • *
* * @see #getAuthProperties() */ List getSaslSecurityOptions() { profileListProperty "sasl_security_options", authProperties } def saslLocalDomainConf() { def replace = mainSaslConfTemplate.getText(true, "saslLocalDomainConfig", "config", saslLocalDomain) def search = mainSaslConfTemplate.getText(true, "saslLocalDomainConfig_search") new TokenTemplate(search, replace, escape: false) } /** * Returns SASL authentication local domain, for * example {@code ""}. * *
    *
  • profile property {@code "sasl_local_domain"}
  • *
* * @see #getAuthProperties() */ List getSaslLocalDomain() { profileListProperty "sasl_local_domain", defaultProperties } /** * Configures the SASL {@code saslauthd} configuration. * * @see #getSaslauthdFile() */ void deploySaslauthd() { def configuration = [] configuration << saslStartEnableConf() configuration << saslOptionsConf() def config = currentConfiguration saslauthdFile deployConfiguration configurationTokens(), config, configuration, saslauthdFile } /** * Returns the SASL {@code "saslauthd"} file, for * example {@code "/etc/default/saslauthd"}. * *
    *
  • profile property {@code "sasl_authd_file"}
  • *
* * @see #getAuthProperties() */ File getSaslauthdFile() { profileProperty("sasl_authd_file", authProperties) as File } def saslStartEnableConf() { def replace = saslAuthConfTemplate.getText(true, "saslStartEnableConfig", "enabled", saslAuthEnabled) def search = saslAuthConfTemplate.getText(true, "saslStartEnableConfig_search") new TokenTemplate(search, replace) } def saslOptionsConf() { def replace = saslAuthConfTemplate.getText(true, "saslOptionsConfig", "options", saslOptions) def search = saslAuthConfTemplate.getText(true, "saslOptionsConfig_search") new TokenTemplate(search, replace, flags: Pattern.MULTILINE) } /** * Returns the SASL options, for * example {@code "-r -c -m /var/spool/postfix/var/run/saslauthd"}. * *
    *
  • profile property {@code "sasl_options"}
  • *
* * @see #getAuthProperties() */ String getSaslOptions() { profileProperty "sasl_options", authProperties } @Override String getAuthName() { NAME } /** * Returns the authentication properties. */ abstract ContextProperties getAuthProperties() }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy