3 # Copyright (C) 2014 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from ipsilon.login.common import LoginFormBase, LoginManagerBase
21 from ipsilon.login.common import FACILITY
22 from ipsilon.util.plugin import PluginObject
23 from ipsilon.util.user import UserSession
24 from string import Template
29 class Form(LoginFormBase):
31 def POST(self, *args, **kwargs):
35 if not user.is_anonymous:
36 return self.lm.auth_successful(user.name, 'password')
39 error = cherrypy.request.headers['EXTERNAL_AUTH_ERROR']
41 error = "Unknown error using external authentication"
42 cherrypy.log.error("Error: %s" % error)
43 return self.lm.auth_failed()
46 class LoginManager(LoginManagerBase):
48 def __init__(self, *args, **kwargs):
49 super(LoginManager, self).__init__(*args, **kwargs)
53 self.service_name = 'form'
54 self.description = """
55 Form based login Manager. Relies on mod_intercept_form_submit plugin for
56 actual authentication. """
59 """ The text shown to guide the user at login time. """,
61 'Insert your Username and Password and then submit.'
64 """ The text shown to ask for the username in the form. """,
69 """ The text shown to ask for the password in the form. """,
74 self.conf_opt_order = ['username text', 'password text', 'help text']
78 return self.get_config_value('help text')
81 def username_text(self):
82 return self.get_config_value('username text')
85 def password_text(self):
86 return self.get_config_value('password text')
88 def get_tree(self, site):
89 self.page = Form(site, self, 'login/form')
94 LoadModule intercept_form_submit_module modules/mod_intercept_form_submit.so
95 LoadModule authnz_pam_module modules/mod_authnz_pam.so
97 <Location /${instance}/login/form>
98 InterceptFormPAMService ${service}
99 InterceptFormLogin login_name
100 InterceptFormPassword login_password
101 # InterceptFormLoginSkip admin
102 # InterceptFormClearRemoteUserForSkipped on
103 InterceptFormPasswordRedact on
108 class Installer(object):
114 def install_args(self, group):
115 group.add_argument('--form', choices=['yes', 'no'], default='no',
116 help='Configure External Form authentication')
117 group.add_argument('--form-service', action='store', default='remote',
118 help='PAM service name to use for authentication')
120 def configure(self, opts):
121 if opts['form'] != 'yes':
124 confopts = {'instance': opts['instance'],
125 'service': opts['form_service']}
127 tmpl = Template(CONF_TEMPLATE)
128 hunk = tmpl.substitute(**confopts) # pylint: disable=star-args
129 with open(opts['httpd_conf'], 'a') as httpd_conf:
130 httpd_conf.write(hunk)
132 # Add configuration data to database
136 po.wipe_config_values(FACILITY)
138 # Update global config, put 'krb' always first
140 globalconf = po.get_plugin_config(FACILITY)
141 if 'order' in globalconf:
142 order = globalconf['order'].split(',')
146 globalconf['order'] = ','.join(order)
147 po.set_config(globalconf)
148 po.save_plugin_config(FACILITY)
150 # for selinux enabled platforms, ignore if it fails just report
152 subprocess.call(['/usr/sbin/setsebool', '-P',
153 'httpd_mod_auth_pam=on'])
154 except Exception: # pylint: disable=broad-except