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
19 from ipsilon.util.plugin import PluginObject
20 from ipsilon.util.user import UserSession
21 from ipsilon.util import config as pconfig
22 from string import Template
27 class Form(LoginFormBase):
29 def POST(self, *args, **kwargs):
33 if not user.is_anonymous:
34 return self.lm.auth_successful(self.trans, user.name, 'password')
37 error = cherrypy.request.headers['EXTERNAL_AUTH_ERROR']
39 error = "Unknown error using external authentication"
40 cherrypy.log.error("Error: %s" % error)
41 return self.lm.auth_failed(self.trans)
44 class LoginManager(LoginManagerBase):
46 def __init__(self, *args, **kwargs):
47 super(LoginManager, self).__init__(*args, **kwargs)
51 self.service_name = 'form'
52 self.description = """
53 Form based login Manager. Relies on mod_intercept_form_submit plugin for
54 actual authentication. """
59 'Text used to ask for the username at login time.',
63 'Text used to ask for the password at login time.',
67 'Text used to guide the user at login time.',
68 'Insert your Username and Password and then submit.')
73 return self.get_config_value('help text')
76 def username_text(self):
77 return self.get_config_value('username text')
80 def password_text(self):
81 return self.get_config_value('password text')
83 def get_tree(self, site):
84 self.page = Form(site, self, 'login/form')
89 LoadModule intercept_form_submit_module modules/mod_intercept_form_submit.so
90 LoadModule authnz_pam_module modules/mod_authnz_pam.so
92 <Location /${instance}/login/form>
93 InterceptFormPAMService ${service}
94 InterceptFormLogin login_name
95 InterceptFormPassword login_password
96 # InterceptFormLoginSkip admin
97 # InterceptFormClearRemoteUserForSkipped on
98 InterceptFormPasswordRedact on
103 class Installer(object):
105 def __init__(self, *pargs):
110 def install_args(self, group):
111 group.add_argument('--form', choices=['yes', 'no'], default='no',
112 help='Configure External Form authentication')
113 group.add_argument('--form-service', action='store', default='remote',
114 help='PAM service name to use for authentication')
116 def configure(self, opts):
117 if opts['form'] != 'yes':
120 confopts = {'instance': opts['instance'],
121 'service': opts['form_service']}
123 tmpl = Template(CONF_TEMPLATE)
124 hunk = tmpl.substitute(**confopts) # pylint: disable=star-args
125 with open(opts['httpd_conf'], 'a') as httpd_conf:
126 httpd_conf.write(hunk)
128 # Add configuration data to database
129 po = PluginObject(*self.pargs)
132 po.wipe_config_values()
134 # Update global config to add login plugin
136 po.save_enabled_state()
138 # for selinux enabled platforms, ignore if it fails just report
140 subprocess.call(['/usr/sbin/setsebool', '-P',
141 'httpd_mod_auth_pam=on'])
142 except Exception: # pylint: disable=broad-except