Ejemplo n.º 1
0
    def check_accounts(self, test_accounts):
        db_identities = list_identities()
        for account in test_accounts:
            # check existence
            db_account = get_account(account=account['account'])
            assert_equal(db_account['account'], account['account'])

            # check properties
            email = account.get('email')
            if email:
                assert_equal(db_account['email'], account['email'])

            # check identities
            identities = account.get('identities')
            if identities:
                for identity in identities:
                    # check identity creation and identity-account association
                    identity_type = IdentityType.from_sym(identity['type'])
                    identity = identity['identity']
                    assert_in((identity, identity_type), db_identities)
                    accounts_for_identity = list_accounts_for_identity(
                        identity, identity_type)
                    assert_in(account['account'], accounts_for_identity)

        # check removal of account
        account = get_account(self.old_account_1)
        assert_equal(account['status'], AccountStatus.DELETED)

        # check removal of identities
        accounts_for_identity = list_accounts_for_identity(
            self.identity_to_be_removed, IdentityType.X509)
        assert_true(account['account'] not in accounts_for_identity)
Ejemplo n.º 2
0
def del_identity(identity_key, id_type, issuer, vo='def', session=None):
    """
    Deletes a user identity.
    :param identity_key: The identity key name. For example x509 DN, or a username.
    :param id_type: The type of the authentication (x509, gss, userpass, ssh, saml).
    :param issuer: The issuer account.
    :param vo: the VO of the issuer.
    :param session: The database session in use.
    """
    id_type = IdentityType[id_type.upper()]
    kwargs = {
        'accounts':
        identity.list_accounts_for_identity(identity_key,
                                            id_type,
                                            session=session)
    }
    if not permission.has_permission(issuer=issuer,
                                     vo=vo,
                                     action='del_identity',
                                     kwargs=kwargs,
                                     session=session):
        raise exception.AccessDenied('Account %s can not delete identity' %
                                     (issuer))

    return identity.del_identity(identity_key, id_type, session=session)
Ejemplo n.º 3
0
def list_accounts_for_identity(identity_key, type):
    """
    Returns a list of all accounts for an identity.

    :param identity: The identity key name. For example x509 DN, or a username.
    :param type: The type of the authentication (x509, gss, userpass).

    returns: A list of all accounts for the identity.
    """
    return identity.list_accounts_for_identity(identity_key, IdentityType.from_sym(type))
Ejemplo n.º 4
0
def list_accounts_for_identity(identity_key, id_type):
    """
    Returns a list of all accounts for an identity.

    :param identity: The identity key name. For example x509 DN, or a username.
    :param id_type: The type of the authentication (x509, gss, userpass, ssh).

    returns: A list of all accounts for the identity.
    """
    return identity.list_accounts_for_identity(identity_key,
                                               IdentityType.from_sym(id_type))
Ejemplo n.º 5
0
def list_accounts_for_identity(identity_key, id_type):
    """
    Returns a list of all accounts for an identity.

    :param identity: The identity key name. For example x509 DN, or a username.
    :param id_type: The type of the authentication (x509, gss, userpass, ssh, saml).

    returns: A list of all accounts for the identity.
    """
    accounts = identity.list_accounts_for_identity(
        identity_key, IdentityType[id_type.upper()])
    return [account.external for account in accounts]
Ejemplo n.º 6
0
def select_account_name(identitystr, identity_type, vo=None):
    """
    Looks for account (and VO if not known) corresponding to the provided identity.
    :param identitystr: identity string
    :param identity_type: identity_type e.g. x509, saml, oidc, userpass
    :returns: Tuple of None or account string, None or VO string or list of VO strings
    """
    ui_account = None
    if not MULTI_VO:
        vo = 'def'
    if vo is not None:
        accounts = identity.list_accounts_for_identity(identitystr,
                                                       identity_type)
    else:
        internal_accounts = identity_core.list_accounts_for_identity(
            identitystr, IdentityType.from_sym(identity_type))
        accounts = [account.external for account in internal_accounts]
        vos = [account.vo for account in internal_accounts]
        if vos:
            vos = list(set(vos))
            # If we only have 1 VO that matches the identity use that, otherwise return all possible VOs so the user can choose
            if len(vos) == 1:
                vo = vos[0]
            else:
                return None, vos

    if len(accounts) == 0:
        return None, vo
    # check if ui_account param is set
    if 'ui_account' in input():
        ui_account = input()['ui_account']
    # if yes check if the accounts provided for users identity include this account
    if not ui_account and 'account' in input():
        ui_account = input()['account']
    if ui_account:
        if ui_account not in accounts:
            return None, vo
        else:
            return ui_account, vo
    else:
        # try to set the default account to the user account, if not available take the first account.
        def_account = accounts[0]
        for account in accounts:
            account_info = get_account_info(account, vo=vo)
            if account_info.account_type == AccountType.USER:
                def_account = account
                break
        selected_account = cookies().get('rucio-selected-account')
        if (selected_account):
            def_account = selected_account
        ui_account = def_account
    return ui_account, vo
Ejemplo n.º 7
0
def del_identity(identity_key, id_type, issuer):
    """
    Deletes a user identity.
    :param identity_key: The identity key name. For example x509 DN, or a username.
    :param id_type: The type of the authentication (x509, gss, userpass, ssh, saml).
    :param issuer: The issuer account.
    """
    id_type = IdentityType.from_sym(id_type)
    kwargs = {'accounts': identity.list_accounts_for_identity(identity_key, id_type)}
    if not permission.has_permission(issuer=issuer, action='del_identity', kwargs=kwargs):
        raise exception.AccessDenied('Account %s can not delete identity' % (issuer))

    return identity.del_identity(identity_key, id_type)