def test_basic_authn_authenticate_as():
    pwd_database = {'Diana': 'Piano player', 'NonAscii': '€&+%#@äää'}
    ba = BasicAuthn(None, pwd=pwd_database)

    for user, passwd in pwd_database.items():
        credentials = "{}:{}".format(quote_plus(user), quote_plus(passwd))

        authz = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
        authorization_string = "Basic {}".format(authz)

        uid, when = ba.authenticated_as(authorization=authorization_string)
        assert uid == {'uid': user}
Exemple #2
0
def test_basic_authn_authenticate_as():
    pwd_database = {
        'Diana': 'Piano player',
        'NonAscii': '€&+%#@äää'
    }
    ba = BasicAuthn(None, pwd=pwd_database)

    for user, passwd in pwd_database.items():
        credentials = "{}:{}".format(quote_plus(user),
                                     quote_plus(passwd))

        authz = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
        authorization_string = "Basic {}".format(authz)

        uid, when = ba.authenticated_as(authorization=authorization_string)
        assert uid == {'uid': user}
Exemple #3
0
def set_permission(environ, session):
    query = parse_qs(environ["QUERY_STRING"])
    try:
        _user = query["user"][0]
    except KeyError:
        try:
            _user = session["user"]
        except KeyError:
            try:
                authn_info = environ["HTTP_AUTHORIZATION"]
                ident = BasicAuthn(
                    AUTHZSRV,
                    uma_as.PASSWD).authenticated_as(authorization=authn_info)
                _user = ident["uid"]
            except KeyError:
                return authenticate(environ, session, "set_permission")

    AUTHZSRV.store_permission(_user, query["sp_entity_id"][0],
                              query["rsname"][0], query["perm"])
    return Response("Succeeded"), {}
Exemple #4
0
 def __init__(self, srv, symkey):
     BasicAuthn.__init__(self, srv, None, 0)
     self.symkey = symkey
Exemple #5
0
 def __init__(self, srv, symkey):
     BasicAuthn.__init__(self, srv, None, 0)
     self.symkey = symkey
Exemple #6
0
authzsrv = Provider("foo", SessionDB(), CDB, None, AUTHZ,
                    verify_client, "1234567890", keyjar=KeyJar())

authzsrv.baseurl = "https://as.example.com/"

AUTHN_BROKER = AuthnBroker()
AUTHN_BROKER.add(UNSPECIFIED, DummyAuthn(None, user="******"), 0,
                 "http://%s" % socket.gethostname())
# AUTHN_BROKER.add(PASSWORD,
#                  UsernamePasswordMako(
#                      None, "login.mako", LOOKUP, PASSWD,
#                      "%s/authorization" % authzsrv.baseurl),
#                  10, "http://%s" % socket.gethostname())
AUTHN_BROKER.add(PASSWORD,
                 BasicAuthn(None, PASSWD),
                 10, "http://%s" % socket.gethostname())

authzsrv.set_authn_broker(AUTHN_BROKER)

ressrv.set_client(authzsrv.baseurl, rs_client)

# -------------------- find authzsrv info --------------------

pcr = ProviderConfiguration().from_json(
    authzsrv.providerinfo_endpoint().message)
rs_client.provider_info[pcr["issuer"]] = pcr
for key, val in list(pcr.items()):
    if key.endswith("_endpoint"):
        setattr(rs_client, key, val)