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(self.trans,
32 data.user['username'],
33 userdata={'fas': data.user})
35 error = "Authentication failed"
36 cherrypy.log.error(error)
38 error = "Username or password is missing"
39 cherrypy.log.error("Error: " + error)
41 context = self.create_tmpl_context(
44 error_password=not password,
45 error_username=not username
47 # pylint: disable=star-args
48 return self._template(self.formtemplate, **context)
51 class LoginManager(LoginManagerBase):
53 def __init__(self, *args, **kwargs):
54 super(LoginManager, self).__init__(*args, **kwargs)
57 self.service_name = 'fas'
60 self.description = """
61 Form based login Manager that uses the Fedora Authentication Server
65 """ The text shown to guide the user at login time. """,
67 'Login wth your FAS credentials'
70 """ The text shown to ask for the username in the form. """,
75 """ The text shown to ask for the password in the form. """,
82 'https://admin.fedoraproject.org/accounts/'
84 'FAS Proxy client user Agent': [
85 """ The User Agent presented to the FAS Server. """,
89 'FAS Insecure Auth': [
90 """ If 'YES' skips FAS server cert verification. """,
95 self.conf_opt_order = ['FAS url', 'FAS Proxy client user Agent',
96 'FAS Insecure Auth', 'username text',
97 'password text', 'help text']
101 return self.get_config_value('help text')
104 def username_text(self):
105 return self.get_config_value('username text')
108 def password_text(self):
109 return self.get_config_value('password text')
113 return self.get_config_value('FAS url')
116 def user_agent(self):
117 return self.get_config_value('FAS Proxy client user Agent')
121 return self.get_config_value('FAS Insecure Auth')
123 def get_tree(self, site):
124 self.fpc = FasProxyClient(base_url=self.fas_url,
125 useragent=self.user_agent,
126 insecure=(self.insecure == 'YES'))
127 self.page = FAS(site, self, 'login/fas', 'login/fas.html')
131 class Installer(object):
137 def install_args(self, group):
138 group.add_argument('--fas', choices=['yes', 'no'], default='no',
139 help='Configure FAS authentication')
141 def configure(self, opts):
142 if opts['fas'] != 'yes':
145 # Add configuration data to database
150 po.wipe_config_values(FACILITY)
152 # Update global config to add login plugin
155 globalconf = po.get_plugin_config(FACILITY)
156 if 'order' in globalconf:
157 order = globalconf['order'].split(',')
161 globalconf['order'] = ','.join(order)
162 po.set_config(globalconf)
163 po.save_plugin_config(FACILITY)