1 # Copyright (C) 2014 Simo Sorce <simo@redhat.com>
3 # see file 'COPYING' for use and warranty information
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from ipsilon.login.common import LoginFormBase, LoginManagerBase, \
20 from ipsilon.util.plugin import PluginObject
21 from ipsilon.util.user import UserSession
22 from ipsilon.util import config as pconfig
23 from string import Template
28 class Form(LoginFormBase):
30 def POST(self, *args, **kwargs):
34 if not user.is_anonymous:
35 return self.lm.auth_successful(self.trans, user.name, 'password')
38 error = cherrypy.request.headers['EXTERNAL_AUTH_ERROR']
40 error = "Unknown error using external authentication"
41 cherrypy.log.error("Error: %s" % error)
42 return self.lm.auth_failed(self.trans)
45 class LoginManager(LoginManagerBase):
47 def __init__(self, *args, **kwargs):
48 super(LoginManager, self).__init__(*args, **kwargs)
52 self.service_name = 'form'
53 self.description = """
54 Form based login Manager. Relies on mod_intercept_form_submit plugin for
55 actual authentication. """
60 'Text used to ask for the username at login time.',
64 'Text used to ask for the password at login time.',
68 'Text used to guide the user at login time.',
69 'Insert your Username and Password and then submit.')
74 return self.get_config_value('help text')
77 def username_text(self):
78 return self.get_config_value('username text')
81 def password_text(self):
82 return self.get_config_value('password text')
84 def get_tree(self, site):
85 self.page = Form(site, self, 'login/form')
90 LoadModule intercept_form_submit_module modules/mod_intercept_form_submit.so
91 LoadModule authnz_pam_module modules/mod_authnz_pam.so
93 <Location /${instance}/login/form>
94 InterceptFormPAMService ${service}
95 InterceptFormLogin login_name
96 InterceptFormPassword login_password
97 # InterceptFormLoginSkip admin
98 # InterceptFormClearRemoteUserForSkipped on
99 InterceptFormPasswordRedact on
104 class Installer(LoginManagerInstaller):
106 def __init__(self, *pargs):
107 super(Installer, self).__init__()
111 def install_args(self, group):
112 group.add_argument('--form', choices=['yes', 'no'], default='no',
113 help='Configure External Form authentication')
114 group.add_argument('--form-service', action='store', default='remote',
115 help='PAM service name to use for authentication')
117 def configure(self, opts):
118 if opts['form'] != 'yes':
121 confopts = {'instance': opts['instance'],
122 'service': opts['form_service']}
124 tmpl = Template(CONF_TEMPLATE)
125 hunk = tmpl.substitute(**confopts)
126 with open(opts['httpd_conf'], 'a') as httpd_conf:
127 httpd_conf.write(hunk)
129 # Add configuration data to database
130 po = PluginObject(*self.pargs)
133 po.wipe_config_values()
135 # Update global config to add login plugin
137 po.save_enabled_state()
139 # for selinux enabled platforms, ignore if it fails just report
141 subprocess.call(['/usr/sbin/setsebool', '-P',
142 'httpd_mod_auth_pam=on'])
143 except Exception: # pylint: disable=broad-except