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. """,
94 self.conf_opt_order = ['FAS url', 'FAS Proxy client user Agent',
95 'FAS Insecure Auth', 'username text',
96 'password text', 'help text']
100 return self.get_config_value('help text')
103 def username_text(self):
104 return self.get_config_value('username text')
107 def password_text(self):
108 return self.get_config_value('password text')
112 return self.get_config_value('FAS url')
115 def user_agent(self):
116 return self.get_config_value('FAS Proxy client user Agent')
120 return self.get_config_value('FAS Insecure Auth')
122 def get_tree(self, site):
123 self.fpc = FasProxyClient(base_url=self.fas_url,
124 useragent=self.user_agent,
125 insecure=(self.insecure == 'YES'))
126 self.page = FAS(site, self, 'login/fas', 'login/fas.html')
130 class Installer(object):
136 def install_args(self, group):
137 group.add_argument('--fas', choices=['yes', 'no'], default='no',
138 help='Configure FAS authentication')
140 def configure(self, opts):
141 if opts['fas'] != 'yes':
144 # Add configuration data to database
149 po.wipe_config_values(FACILITY)
151 # Update global config to add login plugin
154 globalconf = po.get_plugin_config(FACILITY)
155 if 'order' in globalconf:
156 order = globalconf['order'].split(',')
160 globalconf['order'] = ','.join(order)
161 po.set_config(globalconf)
162 po.save_plugin_config(FACILITY)