Exemplo n.º 1
0
def create(entity):
    try:
        attrs = {}
        attrs.update({'objectClass': ROLE_OCS})
        attrs.update({global_ids.CN: entity.name})
        attrs.update({ROLE_NAME: entity.name})
        # generate random id:
        entity.internal_id = str(uuid.uuid4())
        attrs.update({global_ids.INTERNAL_ID: entity.internal_id})

        # string:
        if entity.description:
            attrs.update({global_ids.DESC: entity.description})
        # list of strings
        if entity.props is not None and len(entity.props) > 0:
            attrs.update({global_ids.PROPS: entity.props})
        # list of comma delimited strings:
        if entity.constraint is None:
            entity.constraint = Constraint(name=entity.name)
        #if entity.constraint is not None:
        attrs.update({global_ids.CONSTRAINT: entity.constraint.get_raw()})

        conn = ldaphelper.open()
        conn.add_s(__get_dn(entity), add_to_modlist(attrs))
    except ldap.ALREADY_EXISTS:
        raise NotUnique(msg='Role create failed, already exists:' + entity.uid,
                        id=global_ids.ROLE_ADD_FAILED)
    except ldap.LDAPError as e:
        raise RbacError(msg='Role create failed result=' + str(e),
                        id=global_ids.ROLE_ADD_FAILED)
    except Exception as e:
        raise RbacError(msg='Role create error=' + str(e),
                        id=global_ids.ROLE_ADD_FAILED)
    return entity
Exemplo n.º 2
0
def create_obj(entity):
    try:
        attrs = {}
        attrs.update({'objectClass': PERM_OBJ_OCS})
        attrs.update({OBJ_NM: entity.obj_name})
        # generate random id:
        entity.internal_id = str(uuid.uuid4())
        attrs.update({global_ids.INTERNAL_ID: entity.internal_id})
        # ou is req'd for organizationalUnit object class, if caller did not set, use obj name.
        if not entity.ou:
            entity.ou = entity.obj_name
        attrs.update({global_ids.OU: entity.ou})
        if entity.description:
            attrs.update({global_ids.DESC: entity.description})
        if entity.type:
            attrs.update({TYPE: entity.type})
        # list of comma delimited strings:
        if entity.props is not None and len(entity.props) > 0:
            attrs.update({global_ids.PROPS: entity.props})
        conn = ldaphelper.open()
        conn.add_s(__get_obj_dn(entity), add_to_modlist(attrs))
    except ldap.ALREADY_EXISTS:
        raise NotUnique(msg='PermObj create failed, already exists:' +
                        entity.uid,
                        id=global_ids.PERM_ADD_FAILED)
    except ldap.LDAPError as e:
        raise FortressError(msg='PermObj create failed result=' + str(e),
                            id=global_ids.PERM_ADD_FAILED)
    except Exception as e:
        raise FortressError(msg='PermObj create error=' + str(e),
                            id=global_ids.PERM_ADD_FAILED)
    return entity
Exemplo n.º 3
0
def create_suffix(name):
    dn = DC_NAME + '=' + name + ',' + DC_NAME + '=com'
    try:
        attrs = {}
        attrs.update({'objectClass': SUFX_OCS})
        attrs.update({DC_NAME: name})
        attrs.update({O: name})
        conn = ldaphelper.open()
        conn.add_s(dn, add_to_modlist(attrs))
    except Exception as e:
        raise NotUnique(msg='Suffix create failed, already exists:' + dn,
                        id=global_ids.SUFX_ALREADY_EXISTS)
    except ldap.ALREADY_EXISTS:
        raise RbacError(msg='Suffix create failed, dn=' + dn + ', result=' +
                        str(e),
                        id=global_ids.SUFX_CREATE_FAILED)
    except Exception as e:
        raise RbacError(msg='Suffix create dn=' + dn + ', error=' + str(e),
                        id=global_ids.SUFX_CREATE_FAILED)
Exemplo n.º 4
0
def create_ou(name, desc=None):
    __validate(name)
    try:
        attrs = {}
        attrs.update({'objectClass': OU_OCS})
        attrs.update({OU_NAME: name})
        if not desc:
            desc = 'py-fortress Container ' + name
        attrs.update({global_ids.DESC: desc})
        conn = ldaphelper.open()
        conn.add_s(ldaphelper.get_container_dn(name), add_to_modlist(attrs))
    except Exception as e:
        raise RbacError(msg='OU create error=' + str(e),
                        id=global_ids.CNTR_CREATE_FAILED)
    except ldap.ALREADY_EXISTS:
        raise NotUnique(msg='OU create failed, already exists:' + name,
                        id=global_ids.CNTR_ALREADY_EXISTS)
    except ldap.LDAPError as e:
        raise RbacError(msg='OU create failed result=' + str(e),
                        id=global_ids.CNTR_CREATE_FAILED)
Exemplo n.º 5
0
def create(entity):
    try:
        attrs = {}
        attrs.update({'objectClass': PERM_OCS})
        attrs.update({OBJ_NM: entity.obj_name})
        attrs.update({OP_NM: entity.op_name})
        entity.abstract_name = entity.obj_name + '.' + entity.op_name
        attrs.update({global_ids.CN: entity.abstract_name})

        # generate random id:
        entity.internal_id = str(uuid.uuid4())
        attrs.update({global_ids.INTERNAL_ID: entity.internal_id})
        if entity.obj_id:
            attrs.update({OBJ_ID: entity.obj_id})
        if entity.description:
            attrs.update({global_ids.DESC: entity.description})
        if entity.abstract_name:
            attrs.update({PERM_NAME: entity.abstract_name})
        if entity.type:
            attrs.update({TYPE: entity.type})
        # list of strings:
        if entity.props is not None and len(entity.props) > 0:
            attrs.update({global_ids.PROPS: entity.props})
        if entity.users is not None and len(entity.users) > 0:
            attrs.update({USERS: entity.users})
        if entity.roles is not None and len(entity.roles) > 0:
            attrs.update({ROLES: entity.roles})
        conn = ldaphelper.open()
        conn.add_s(__get_dn(entity), add_to_modlist(attrs))
    except ldap.ALREADY_EXISTS:
        raise NotUnique(msg='Perm create failed, already exists:' +
                        entity.obj_name,
                        id=global_ids.PERM_ADD_FAILED)
    except ldap.LDAPError as e:
        raise RbacError(msg='Perm create failed result=' + str(e),
                        id=global_ids.PERM_ADD_FAILED)
    except Exception as e:
        raise RbacError(msg='Perm create error=' + str(e),
                        id=global_ids.PERM_ADD_FAILED)
    return entity
Exemplo n.º 6
0
def create(entity):
    try:
        attrs = {}
        attrs.update({'objectClass': USER_OCS})
        attrs.update({global_ids.UID: entity.uid})
        # generate random id:
        entity.internal_id = str(uuid.uuid4())
        attrs.update({global_ids.INTERNAL_ID: entity.internal_id})
        # cn is req'd for iNetOrgPerson, if caller did not set, use uid value
        if not entity.cn:
            entity.cn = entity.uid
        attrs.update({global_ids.CN: entity.cn})
        # likewise sn is req'd for iNetOrgPerson, if caller did not set, use uid value
        if not entity.sn:
            entity.sn = entity.uid
        attrs.update({global_ids.SN: entity.sn})
        # strings:
        if entity.password:
            attrs.update({PW: entity.password})
        if entity.description:
            attrs.update({global_ids.DESC: entity.description})
        if entity.ou:
            attrs.update({global_ids.OU: entity.ou})
        if entity.display_name:
            attrs.update({DISPLAY_NAME: entity.display_name})
        if entity.employee_type:
            attrs.update({EMPLOYEE_TYPE: entity.employee_type})
        if entity.title:
            attrs.update({TITLE: entity.title})
        if entity.department_number:
            attrs.update({DEPT_NUM: entity.department_number})
        if entity.l:
            attrs.update({LOCATION: entity.l})
        if entity.physical_delivery_office_name:
            attrs.update(
                {PHYSICAL_OFFICE_NM: entity.physical_delivery_office_name})
        if entity.postal_code:
            attrs.update({POSTAL_CODE: entity.postal_code})
        if entity.room_number:
            attrs.update({RM_NUM: entity.room_number})
        if entity.pw_policy:
            attrs.update({PW_POLICY: entity.pw_policy})
        # boolean:
        if entity.system is not None:
            attrs.update({IS_SYSTEM: 'TRUE' if entity.system else 'FALSE'})
        # list of strings:
        if entity.phones is not None and len(entity.phones) > 0:
            attrs.update({TELEPHONE_NUMBER: entity.phones})
        if entity.mobiles is not None and len(entity.mobiles) > 0:
            attrs.update({MOBILE: entity.mobiles})
        if entity.emails is not None and len(entity.emails) > 0:
            attrs.update({MAIL: entity.emails})
        if entity.props is not None and len(entity.props) > 0:
            attrs.update({global_ids.PROPS: entity.props})
        # list of delimited strings:
        if entity.constraint:
            attrs.update({global_ids.CONSTRAINT: entity.constraint.get_raw()})

        conn = ldaphelper.open()
        conn.add_s(__get_dn(entity), add_to_modlist(attrs))
    except ldap.ALREADY_EXISTS:
        raise NotUnique(msg='User create failed, already exists:' + entity.uid,
                        id=global_ids.USER_ADD_FAILED)
    except ldap.LDAPError as e:
        raise RbacError(msg='User create failed result=' + str(e),
                        id=global_ids.USER_ADD_FAILED)
    except Exception as e:
        raise RbacError(msg='User create error=' + str(e),
                        id=global_ids.USER_ADD_FAILED)
    return entity