from ipsilon.login.common import LoginPageBase, LoginManagerBase
from ipsilon.login.common import FACILITY
from ipsilon.util.plugin import PluginObject
+from ipsilon.util.user import UserSession
from string import Template
import cherrypy
import os
class KrbAuth(LoginPageBase):
def root(self, *args, **kwargs):
+ trans = self.get_valid_transaction('login', **kwargs)
# If we can get here, we must be authenticated and remote_user
# was set. Check the session has a user set already or error.
- if self.user and self.user.name:
+ us = UserSession()
+ us.remote_login()
+ self.user = us.get_user()
+ if not self.user.is_anonymous:
userdata = {'krb_principal_name': self.user.name}
- return self.lm.auth_successful(self.user.name, userdata)
+ return self.lm.auth_successful(trans, self.user.name,
+ 'krb', userdata)
else:
- return self.lm.auth_failed()
+ return self.lm.auth_failed(trans)
class KrbError(LoginPageBase):
# If we have no negotiate header return whatever mod_auth_kerb
# generated and wait for the next request
- if not 'WWW-Authenticate' in cherrypy.request.headers:
+ if 'WWW-Authenticate' not in cherrypy.request.headers:
cherrypy.response.status = 401
if self.lm.next_login:
cont=conturl)
# If we get here, negotiate failed
- return self.lm.auth_failed()
+ trans = self.get_valid_transaction('login', **kwargs)
+ return self.lm.auth_failed(trans)
class LoginManager(LoginManagerBase):
self.page = Krb(site, self)
self.page.__dict__['negotiate'] = KrbAuth(site, self)
self.page.__dict__['unauthorized'] = KrbError(site, self)
+ self.page.__dict__['failed'] = KrbError(site, self)
return self.page
CONF_TEMPLATE = """
-<Location /idp/login/krb/negotiate>
+<Location /${instance}/login/krb/negotiate>
AuthType Kerberos
AuthName "Kerberos Login"
KrbMethodNegotiate on
# KrbLocalUserMapping On
Require valid-user
- ErrorDocument 401 /idp/login/krb/unauthorized
+ ErrorDocument 401 /${instance}/login/krb/unauthorized
+ ErrorDocument 500 /${instance}/login/krb/failed
</Location>
"""
if opts['krb'] != 'yes':
return
- keytab = ' # Krb5KeyTab - No Keytab provided'
- if opts['krb_httpd_keytab'] is None:
- if os.path.exists('/etc/httpd/conf/http.keytab'):
- keytab = ' Krb5KeyTab /etc/httpd/conf/http.keytab'
+ confopts = {'instance': opts['instance']}
+
+ if os.path.exists(opts['krb_httpd_keytab']):
+ confopts['keytab'] = ' Krb5KeyTab %s' % opts['krb_httpd_keytab']
else:
- if os.path.exists(opts['krb_httpd_keytab']):
- keytab = ' Krb5KeyTab %s' % opts['krb_httpd_keytab']
- else:
- raise Exception('Keytab not found')
+ raise Exception('Keytab not found')
if opts['krb_realms'] is None:
- realms = ' # KrbAuthRealms - Any trusted realm is allowed'
+ confopts['realms'] = ' # KrbAuthRealms - Any realm is allowed'
else:
- realms = ' KrbAuthRealms %s' % opts['krb_realms']
+ confopts['realms'] = ' KrbAuthRealms %s' % opts['krb_realms']
tmpl = Template(CONF_TEMPLATE)
- hunk = tmpl.substitute(keytab=keytab, realms=realms)
+ hunk = tmpl.substitute(**confopts) # pylint: disable=star-args
with open(opts['httpd_conf'], 'a') as httpd_conf:
httpd_conf.write(hunk)
order = []
order.insert(0, 'krb')
globalconf['order'] = ','.join(order)
- po.set_config(globalconf)
- po.save_plugin_config(FACILITY)
+ po.save_plugin_config(FACILITY, globalconf)