auth_saml: separate idps blocks on login page (#38248)
This commit is contained in:
parent
3b2da052ad
commit
a2c3bc9cce
|
@ -328,6 +328,7 @@ def login(request, template_name='authentic2/login.html',
|
|||
if hasattr(authenticator, 'instances'):
|
||||
for instance_id, instance in authenticator.instances(**parameters):
|
||||
parameters['instance'] = instance
|
||||
parameters['instance_id'] = instance_id
|
||||
block = utils.get_authenticator_method(authenticator, 'login', parameters)
|
||||
# update block id in order to separate instances
|
||||
block['id'] = '%s_%s' % (block['id'], instance_id)
|
||||
|
|
|
@ -33,12 +33,19 @@ class SAMLAuthenticator(object):
|
|||
def name(self):
|
||||
return gettext_noop('SAML')
|
||||
|
||||
def instances(self, request, *args, **kwargs):
|
||||
for idx, idp in enumerate(get_idps()):
|
||||
yield(idx, idp)
|
||||
|
||||
def login(self, request, *args, **kwargs):
|
||||
context = kwargs.pop('context', {})
|
||||
submit_name = 'login-%s' % self.id
|
||||
instance_id = kwargs.get('instance_id')
|
||||
submit_name = 'login-%s-%s' % (self.id, instance_id)
|
||||
context['submit_name'] = submit_name
|
||||
if request.method == 'POST' and submit_name in request.POST:
|
||||
return redirect_to_login(request, login_url='mellon_login')
|
||||
instance = kwargs.get('instance')
|
||||
return redirect_to_login(request, login_url='mellon_login',
|
||||
params={'entityID': instance['ENTITY_ID']})
|
||||
return render(request, 'authentic2_auth_saml/login.html', context)
|
||||
|
||||
def profile(self, request, *args, **kwargs):
|
||||
|
|
|
@ -24,6 +24,23 @@ from django.contrib.auth import get_user_model
|
|||
from authentic2.models import Attribute
|
||||
|
||||
|
||||
def test_providers_on_login_page(db, app, settings):
|
||||
settings.A2_AUTH_SAML_ENABLE = True
|
||||
PROVIDERS = [
|
||||
{'METADATA': 'meta1.xml', 'ENTITY_ID': 'idp1'},
|
||||
]
|
||||
settings.MELLON_IDENTITY_PROVIDERS = PROVIDERS
|
||||
response = app.get('/login/')
|
||||
assert response.pyquery('button[name="login-saml-0"]')
|
||||
assert not response.pyquery('button[name="login-saml-1"]')
|
||||
|
||||
PROVIDERS.append({'METADATA': 'meta1.xml', 'ENTITY_ID': 'idp1'})
|
||||
response = app.get('/login/')
|
||||
# two frontends should be present on login page
|
||||
assert response.pyquery('button[name="login-saml-0"]')
|
||||
assert response.pyquery('button[name="login-saml-1"]')
|
||||
|
||||
|
||||
def test_provision_attributes(db, caplog, simple_role):
|
||||
from authentic2_auth_saml.adapters import AuthenticAdapter
|
||||
|
||||
|
|
Loading…
Reference in New Issue