3 # Copyright (C) 2013 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 LoginPageBase, LoginManagerBase
25 class Pam(LoginPageBase):
27 def _authenticate(self, username, password):
28 if self.lm.service_name:
29 ok = pam.authenticate(username, password, self.lm.service_name)
31 ok = pam.authenticate(username, password)
34 cherrypy.log("User %s successfully authenticated." % username)
37 cherrypy.log("User %s failed authentication." % username)
40 def GET(self, *args, **kwargs):
41 return self._template('login/pam.html', title='Login',
42 action='%s/login/pam' % self.basepath,
43 service_name=self.lm.service_name,
44 help_text=self.lm.help_text,
45 username_text=self.lm.username_text,
46 password_text=self.lm.password_text)
48 def POST(self, *args, **kwargs):
52 for key, value in kwargs.iteritems():
53 if key == 'login_name':
55 elif key == 'login_password':
57 if username is not None and password is not None:
58 user = self._authenticate(username, password)
60 cherrypy.log.error("Error: Username or password is missing")
63 return self.lm.auth_successful(user)
65 return self.lm.auth_failed()
67 def root(self, *args, **kwargs):
68 op = getattr(self, cherrypy.request.method, self.GET)
70 return op(*args, **kwargs)
73 class LoginManager(LoginManagerBase):
75 def __init__(self, *args, **kwargs):
76 super(LoginManager, self).__init__(*args, **kwargs)
80 self.description = """
81 Form based login Manager that uses the system's PAM infrastructure
82 for authentication. """
85 """ The name of the PAM service used to authenticate. """,
90 """ The text shown to guide the user at login time. """,
92 'Insert your Username and Password and then submit.'
95 """ The text shown to ask for the username in the form. """,
100 """ The text shown to ask for the password in the form. """,
107 def service_name(self):
108 return self.get_config_value('service name')
112 return self.get_config_value('help text')
115 def username_text(self):
116 return self.get_config_value('username text')
119 def password_text(self):
120 return self.get_config_value('password text')
122 def get_tree(self, site):
123 self.page = Pam(site, self)