3 # Copyright (C) 2014 Ipsilon contributors, see COPYING file for license
6 from ipsilon.login.common import LoginFormBase, LoginManagerBase
7 from ipsilon.login.common import FACILITY
8 from ipsilon.util.plugin import PluginObject
11 from fedora.client.fasproxy import FasProxyClient
12 from fedora.client import AuthError
15 class FAS(LoginFormBase):
17 def POST(self, *args, **kwargs):
18 username = kwargs.get("login_name")
19 password = kwargs.get("login_password")
22 if username and password:
25 _, data = self.lm.fpc.login(username, password)
27 cherrypy.log.error("Authentication error [%s]" % str(e))
28 except Exception, e: # pylint: disable=broad-except
29 cherrypy.log.error("Unknown Error [%s]" % str(e))
30 if data and data.user:
31 return self.lm.auth_successful(data.user['username'],
32 userdata={'fas': data.user})
34 error = "Authentication failed"
35 cherrypy.log.error(error)
37 error = "Username or password is missing"
38 cherrypy.log.error("Error: " + error)
40 context = self.create_tmpl_context(
43 error_password=not password,
44 error_username=not username
46 # pylint: disable=star-args
47 return self._template(self.formtemplate, **context)
50 class LoginManager(LoginManagerBase):
52 def __init__(self, *args, **kwargs):
53 super(LoginManager, self).__init__(*args, **kwargs)
56 self.service_name = 'fas'
59 self.description = """
60 Form based login Manager that uses the Fedora Authentication Server
64 """ The text shown to guide the user at login time. """,
66 'Login wth your FAS credentials'
69 """ The text shown to ask for the username in the form. """,
74 """ The text shown to ask for the password in the form. """,
81 'https://admin.fedoraproject.org/accounts/'
83 'FAS Proxy client user Agent': [
84 """ The User Agent presented to the FAS Server. """,
88 'FAS Insecure Auth': [
89 """ If 'YES' skips FAS server cert verification. """,
97 return self.get_config_value('help text')
100 def username_text(self):
101 return self.get_config_value('username text')
104 def password_text(self):
105 return self.get_config_value('password text')
109 return self.get_config_value('FAS url')
112 def user_agent(self):
113 return self.get_config_value('FAS Proxy client user Agent')
117 return self.get_config_value('FAS Insecure Auth')
119 def get_tree(self, site):
120 self.fpc = FasProxyClient(base_url=self.fas_url,
121 useragent=self.user_agent,
122 insecure=(self.insecure == 'YES'))
123 self.page = FAS(site, self, 'login/fas', 'login/fas.html')
127 class Installer(object):
133 def install_args(self, group):
134 group.add_argument('--fas', choices=['yes', 'no'], default='no',
135 help='Configure FAS authentication')
137 def configure(self, opts):
138 if opts['fas'] != 'yes':
141 # Add configuration data to database
146 po.wipe_config_values(FACILITY)
148 # Update global config to add login plugin
151 globalconf = po.get_plugin_config(FACILITY)
152 if 'order' in globalconf:
153 order = globalconf['order'].split(',')
157 globalconf['order'] = ','.join(order)
158 po.set_config(globalconf)
159 po.save_plugin_config(FACILITY)