예제 #1
0
from database.Models import Permission, User, Group, PermissionEnum, PermissionTypeEnum
import controller.RelationshipController as rship
from database.Models import UserPermission, GroupPermission, UserGroup
from database.flaskAlchemyInit import HTTPRequestError
from database.inputConf import UserLimits, PermissionLimits, GroupLimits
import database.Cache as cache
import database.historicModels as inactiveTables
import conf
import kongUtils
from controller.KafkaPublisher import Publisher
import controller.PasswordController as pwdc
from database.Models import MVUserPermission, MVGroupPermission

from dojot.module import Log

LOGGER = Log().color_log()


def check_user(user):
    """
    Helper function to check if user is valid (regardless where it is used)

    TODO Check whether this function really must return the same user. Wouldn't it be enough to throw exceptions?

    :param user: The user to be checked.
    :return: The same user
    """
    if not user.get('username', ""):
        raise HTTPRequestError(400, "Missing username")

    if len(user['username']) > UserLimits.username:
예제 #2
0
파일: webRoutes.py 프로젝트: jonaphael/auth
import controller.CRUDController as crud
import controller.RelationshipController as rship
import controller.PDPController as pdpc
import controller.AuthenticationController as auth
import controller.ReportController as reports
import controller.PasswordController as pwdc
import auth.kongUtils as kong
from database.flaskAlchemyInit import app, db, format_response
from database.flaskAlchemyInit import HTTPRequestError, make_response, load_json_from_request
import database.Cache as cache
from controller.KafkaPublisher import Publisher

from utils.serialization import json_serial
from dojot.module import Log

LOGGER = Log().color_log()


# Authentication endpoint
@app.route('/', methods=['POST'])
def authenticate():
    try:
        auth_data = load_json_from_request(request)
        jwt = auth.authenticate(db.session, auth_data)
        return make_response(json.dumps({'jwt': jwt}), 200)
    except HTTPRequestError as err:
        return format_response(err.errorCode, err.message)


# User CRUD
@app.route('/user', methods=['POST'])