Example #1
0
def _create_authentication_from_config(service_config,
                                       authentication_mode: str,
                                       authentication: dict):
    if "oauth2_implicit" == authentication_mode:
        oauth2_config = dict(service_config.oauth2)
        return OAuth2Implicit(
            authorization_url=authentication.get("oauth2_auth_url"),
            **oauth2_config)
    elif "oauth2_access_code" == authentication_mode:
        oauth2_config = dict(service_config.oauth2)
        return OAuth2AuthorizationCode(
            authorization_url=authentication.get("oauth2_auth_url"),
            token_url=authentication.get("oauth2_token_url"),
            **oauth2_config,
        )
    elif "oauth2_password" == authentication_mode:
        oauth2_config = dict(service_config.oauth2)
        return OAuth2ResourceOwnerPasswordCredentials(
            token_url=authentication.get("oauth2_token_url"), **oauth2_config)
    elif "oauth2_application" == authentication_mode:
        oauth2_config = dict(service_config.oauth2)
        return OAuth2ClientCredentials(
            token_url=authentication.get("oauth2_token_url"), **oauth2_config)
    elif "api_key" == authentication_mode:
        if authentication.get("in") == "query":
            return QueryApiKey(service_config.api_key,
                               authentication.get("name"))
        return HeaderApiKey(service_config.api_key, authentication.get("name"))
    elif "basic" == authentication_mode:
        return Basic(service_config.basic.get("username"),
                     service_config.basic.get("password"))
    else:
        logger.error(
            f"Unexpected security definition type: {authentication_mode}")
Example #2
0
def utentematricola(request, matricola):
    response = requests.get(urlEmployee[0] + str(matricola),
                            auth=Basic(user, passwd))

    response_json = response.json()

    return checkList(response_json)
Example #3
0
def _create_authentication(service_config, open_api_security_definition: dict,
                           request_content):
    if "oauth2" == open_api_security_definition.get("type"):
        flow = open_api_security_definition.get("flow")
        oauth2_config = dict(service_config.oauth2)
        if flow == "implicit":
            return OAuth2Implicit(
                authorization_url=open_api_security_definition.get(
                    "authorizationUrl",
                    request_content.extra_parameters.get("oauth2_auth_url"),
                ),
                **oauth2_config,
            )
        elif flow == "accessCode":
            return OAuth2AuthorizationCode(
                authorization_url=open_api_security_definition.get(
                    "authorizationUrl",
                    request_content.extra_parameters.get("oauth2_auth_url"),
                ),
                token_url=open_api_security_definition.get(
                    "tokenUrl",
                    request_content.extra_parameters.get("oauth2_token_url")),
                **oauth2_config,
            )
        elif flow == "password":
            return OAuth2ResourceOwnerPasswordCredentials(
                token_url=open_api_security_definition.get(
                    "tokenUrl",
                    request_content.extra_parameters.get("oauth2_token_url")),
                **oauth2_config,
            )
        elif flow == "application":
            return OAuth2ClientCredentials(
                token_url=open_api_security_definition.get(
                    "tokenUrl",
                    request_content.extra_parameters.get("oauth2_token_url")),
                **oauth2_config,
            )
        logger.warning(
            f"Unexpected OAuth2 flow: {open_api_security_definition}")
    elif "apiKey" == open_api_security_definition.get("type"):
        if open_api_security_definition["in"] == "query":
            return QueryApiKey(
                service_config.api_key,
                open_api_security_definition.get(
                    "name",
                    request_content.extra_parameters.get("api_key_name")),
            )
        return HeaderApiKey(
            service_config.api_key,
            open_api_security_definition.get(
                "name", request_content.extra_parameters.get("api_key_name")),
        )
    elif "basic" == open_api_security_definition.get("type"):
        return Basic(service_config.basic.get("username"),
                     service_config.basic.get("password"))
    else:
        logger.error(
            f"Unexpected security definition type: {open_api_security_definition}"
        )
Example #4
0
def testRest(request):
    response = requests.get(urlEmployee[2] + '*****@*****.**',
                            auth=Basic(user, passwd))

    response_json = response.json()

    return checkList(response_json)
Example #5
0
def utenteemail(request, email):
    # Se il formato della email non è corretto solleva eccezione
    if not checkEmail(email):
        raise ValueError("Formato email utente errato")

    response = requests.get(urlEmployee[2] + email, auth=Basic(user, passwd))

    response_json = response.json()

    return checkList(response_json)
Example #6
0
def dipendente_email(email):
    # Se il formato della email non è corretto solleva eccezione
    if not check_email(email):
        return None

    response = requests.get(GESTIONALE_UTENTI_ANAGRAFICA_DIPENDENTI_URL[2] + email,
                            auth=Basic(GESTIONALE_UTENTI_REST_USERNAME, GESTIONALE_UTENTI_REST_PASSWORD))
    return_value = None
    try:
        return_value = response.json()[0]
    finally:
        return return_value
Example #7
0
def utentecodicefiscale(request, codicefiscale):
    # Se il formato codice fiscale non è corretto solleva eccezione
    if not checkCodFis(codicefiscale):
        raise ValueError("Formato codicefiscale utente errato")

    codicefiscale = codicefiscale.upper(
    )  # Il Cod fis deve essere sempre con tutti i caratteri maiuscoli

    response = requests.get(urlEmployee[1] + codicefiscale,
                            auth=Basic(user, passwd))

    response_json = response.json()

    return checkList(response_json)
Example #8
0
def studente_email(email):
    # Se il formato della email non è corretto solleva eccezione
    if not check_email(email):
        return None
    response = requests.get(GESTIONALE_UTENTI_ANAGRAFICA_STUDENTI_URL[2] + email,
                            auth=Basic(GESTIONALE_UTENTI_REST_USERNAME, GESTIONALE_UTENTI_REST_PASSWORD))

    #Controllo che lo studente esista
    resp = check_list(response.json())
    if resp is not None:
        return_value = studente_filtra_ultimo_valido(response.json())
        return return_value
    else:
        return resp