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
26 class TestAuth(LoginFormBase):
28 def POST(self, *args, **kwargs):
29 username = kwargs.get("login_name")
30 password = kwargs.get("login_password")
33 if username and password:
34 if password == 'ipsilon':
35 cherrypy.log("User %s successfully authenticated." % username)
36 return self.lm.auth_successful(username, 'password')
38 cherrypy.log("User %s failed authentication." % username)
39 error = "Authentication failed"
41 error = "Username or password is missing"
42 cherrypy.log.error("Error: " + error)
44 context = self.create_tmpl_context(
47 error_password=not password,
48 error_username=not username
50 # pylint: disable=star-args
51 return self._template('login/form.html', **context)
54 class LoginManager(LoginManagerBase):
56 def __init__(self, *args, **kwargs):
57 super(LoginManager, self).__init__(*args, **kwargs)
58 self.name = 'testauth'
59 self.service_name = 'testauth'
60 self.path = 'testauth'
62 self.description = """
63 Form based TEST login Manager, DO NOT EVER ACTIVATE IN PRODUCTION """
66 """ The text shown to guide the user at login time. """,
68 'Insert your Username and Password and then submit.'
71 """ The text shown to ask for the username in the form. """,
76 """ The text shown to ask for the password in the form. """,
84 return self.get_config_value('help text')
87 def username_text(self):
88 return self.get_config_value('username text')
91 def password_text(self):
92 return self.get_config_value('password text')
94 def get_tree(self, site):
95 self.page = TestAuth(site, self, 'login/testauth')
99 class Installer(object):
102 self.name = 'testauth'
105 def install_args(self, group):
106 group.add_argument('--testauth', choices=['yes', 'no'], default='no',
107 help='Configure PAM authentication')
109 def configure(self, opts):
110 if opts['testauth'] != 'yes':
113 # Add configuration data to database
118 # Update global config to add login plugin
121 globalconf = po.get_plugin_config(FACILITY)
122 if 'order' in globalconf:
123 order = globalconf['order'].split(',')
126 order.append('testauth')
127 globalconf['order'] = ','.join(order)
128 po.set_config(globalconf)
129 po.save_plugin_config(FACILITY)