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 import config as pconfig
24 class TestAuth(LoginFormBase):
26 def POST(self, *args, **kwargs):
27 username = kwargs.get("login_name")
28 password = kwargs.get("login_password")
31 if username and password:
32 if password == 'ipsilon':
33 cherrypy.log("User %s successfully authenticated." % username)
34 testdata = {'fullname': 'Test User %s' % username}
35 return self.lm.auth_successful(self.trans,
36 username, 'password', testdata)
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 """
68 'Text used to ask for the username at login time.',
72 'Text used to ask for the password at login time.',
76 'Text used to guide the user at login time.',
77 'DISABLE IN PRODUCTION, USE ONLY FOR TEST ' +
78 'Use any username they are all valid, "admin" gives ' +
79 'administrative powers. ' +
80 'Use the fixed password "ipsilon" for any user')
85 return self.get_config_value('help text')
88 def username_text(self):
89 return self.get_config_value('username text')
92 def password_text(self):
93 return self.get_config_value('password text')
95 def get_tree(self, site):
96 self.page = TestAuth(site, self, 'login/testauth')
100 class Installer(object):
102 def __init__(self, *pargs):
103 self.name = 'testauth'
107 def install_args(self, group):
108 group.add_argument('--testauth', choices=['yes', 'no'], default='no',
109 help='Configure PAM authentication')
111 def configure(self, opts):
112 if opts['testauth'] != 'yes':
116 # Add configuration data to database
117 po = PluginObject(*self.pargs)
121 # Update global config to add login plugin
123 po.save_enabled_state()