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 username_text=self.lm.username_text,
45 password_text=self.lm.password_text)
47 def POST(self, *args, **kwargs):
51 for key, value in kwargs.iteritems():
52 if key == 'login_name':
54 elif key == 'login_password':
56 if username is not None and password is not None:
57 user = self._authenticate(username, password)
59 cherrypy.log.error("Error: Username or password is missing")
62 return self.lm.auth_successful(user)
64 return self.lm.auth_failed()
66 def root(self, *args, **kwargs):
67 op = getattr(self, cherrypy.request.method, self.GET)
69 return op(*args, **kwargs)
72 class LoginManager(LoginManagerBase):
74 def __init__(self, *args, **kwargs):
75 super(LoginManager, self).__init__(*args, **kwargs)
79 self.description = """
80 Form based login Manager that uses the system's PAM infrastructure
81 for authentication. """
84 """ The name of the PAM service used to authenticate. """,
89 """ The text shown to ask for the username in the form. """,
94 """ The text shown to ask for the password in the form. """,
101 def service_name(self):
102 return self.get_config_value('service name')
105 def username_text(self):
106 return self.get_config_value('username text')
109 def password_text(self):
110 return self.get_config_value('password text')
112 def get_tree(self, site):
113 self.page = Pam(site, self)