X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Fproviders%2Fsaml2%2Fauth.py;h=955f01f9e246e641a98c6ad435401741c32db97a;hp=4adb95915b973473e63e225e19e379e941d93737;hb=51f2e1822ce32983c52435185afb5f803d3d150a;hpb=87f1f56c157145e81efa6b58ec9b0d7f89facfc0 diff --git a/ipsilon/providers/saml2/auth.py b/ipsilon/providers/saml2/auth.py index 4adb959..955f01f 100755 --- a/ipsilon/providers/saml2/auth.py +++ b/ipsilon/providers/saml2/auth.py @@ -18,6 +18,9 @@ # along with this program. If not, see . from ipsilon.providers.common import ProviderPageBase +from ipsilon.providers.saml2.provider import ServiceProvider +from ipsilon.providers.saml2.provider import InvalidProviderId +from ipsilon.providers.saml2.provider import NameIdNotAllowed from ipsilon.util.user import UserSession import cherrypy import datetime @@ -52,6 +55,7 @@ class AuthenticateRequest(ProviderPageBase): self.STAGE_INIT = 0 self.STAGE_AUTH = 1 self.stage = self.STAGE_INIT + self.nameidfmt = None def auth(self, login): try: @@ -130,7 +134,19 @@ class AuthenticateRequest(ProviderPageBase): # record it consent = True - # TODO: check Name-ID Policy + # TODO: check destination + + try: + provider = ServiceProvider(self.cfg, login.remoteProviderId) + nameid = provider.get_valid_nameid(login.request.nameIdPolicy) + except NameIdNotAllowed, e: + raise AuthenticationError( + str(e), lasso.SAML2_STATUS_CODE_INVALID_NAME_ID_POLICY) + except InvalidProviderId, e: + raise AuthenticationError( + str(e), lasso.SAML2_STATUS_CODE_AUTHN_FAILED) + + self.nameidfmt = nameid # TODO: check login.request.forceAuthn @@ -143,7 +159,8 @@ class AuthenticateRequest(ProviderPageBase): authtime_notbefore = authtime - skew authtime_notafter = authtime + skew - user = UserSession().get_user() + us = UserSession() + user = us.get_user() # TODO: get authentication type fnd name format from session # need to save which login manager authenticated and map it to a @@ -156,11 +173,23 @@ class AuthenticateRequest(ProviderPageBase): None, authtime_notbefore.strftime(timeformat), authtime_notafter.strftime(timeformat)) - login.assertion.subject.nameId.format = \ - lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT - login.assertion.subject.nameId.content = user.name - # TODO: add user attributes as policy requires taking from 'user' + nameid = None + if self.nameidfmt == lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT: + nameid = user.name ## TODO map to something else ? + elif self.nameidfmt == lasso.SAML2_NAME_IDENTIFIER_FORMAT_TRANSIENT: + nameid = user.name ## TODO map to something else ? + elif self.nameidfmt == lasso.SAML2_NAME_IDENTIFIER_FORMAT_KERBEROS: + nameid = us.get_data('user', 'krb_principal_name') + + if nameid: + login.assertion.subject.nameId.format = self.nameidfmt + login.assertion.subject.nameId.content = nameid + else: + raise AuthenticationError("Unavailable Name ID type", + lasso.SAML2_STATUS_CODE_AUTHN_FAILED) + + # TODO: add user attributes as policy requires taking from 'usersession' def saml2error(self, login, code, message): status = lasso.Samlp2Status()