Esempio n. 1
0
 def is_group(self) -> bool:
     """bool: Whether or not the profile represents a group. True when the 
     ``group_declare`` property is equal to true
     """
     prop = self.props.get('group_declare', '')
     if not isinstance(prop, str):
         raise exceptions.AccessServerProfileIntegrityError(
             f'Type of group_declare must be str, not a {type(prop)}')
     return prop.lower() == 'true'
Esempio n. 2
0
    def is_banned(self) -> bool:
        """bool: Whether or not the profile is banned.
        
        Derived from the ``prop_deny`` property.

        Default behaviour is False
        """
        prop = self.props.get('prop_deny', '')
        if not isinstance(prop, str):
            raise exceptions.AccessServerProfileIntegrityError(
                f'Type of prop_deny must be str, not a {type(prop)}')
        return prop.lower() == 'true'
Esempio n. 3
0
    def will_check_password_strength(self) -> bool:
        """bool: Whether the server should check the password strength when a 
        user derived from this profile tries to change it.
        
        Derived from the ``prop_pwd_strength`` property.

        Default behaviour is True
        """
        prop = self.props.get('prop_pwd_strength', 'true')
        if not isinstance(prop, str):
            raise exceptions.AccessServerProfileIntegrityError(
                f'Type of prop_pwd_strength must be str, not a {type(prop)}')
        return prop.lower() == 'true'
Esempio n. 4
0
    def can_autologin(self) -> bool:
        """bool: Whether or not users derived from this profile can download a 
        connection profile which allows them to connect without a password.
        
        Derived from the ``prop_autologin`` property.

        Default behaviour is False
        """
        prop = self.props.get('prop_autologin', '')
        if not isinstance(prop, str):
            raise exceptions.AccessServerProfileIntegrityError(
                f'Type of prop_autologin must be str, not a {type(prop)}')
        return prop.lower() == 'true'
Esempio n. 5
0
    def can_change_password(self) -> bool:
        """bool: Whether or not users derived from this profile can change
        their password via the web interface.
        
        Derived from the ``prop_pwd_change`` property.

        Default behaviour is False
        """
        prop = self.props.get('prop_pwd_change', '')
        if not isinstance(prop, str):
            raise exceptions.AccessServerProfileIntegrityError(
                f'Type of prop_pwd_change must be str, not a {type(prop)}')
        return prop.lower() == 'true'
Esempio n. 6
0
 def will_autogenerate_client(self) -> bool:
     """bool: Whether or not the server will autogenerate a connection 
     profile for users derived from this profile. If set to true and the 
     given user tries to access their client, the server will generate one 
     if it doesn't exist.
     
     Derived from the ``prop_autogenerate`` property.
     
     Default behaviour is True.
     """
     prop = self.props.get('prop_autogenerate', 'true')
     if not isinstance(prop, str):
         raise exceptions.AccessServerProfileIntegrityError(
             f'Type of prop_autogenerate must be str, not a {type(prop)}')
     return prop.lower() == 'true'
Esempio n. 7
0
    def __setattr__(self, key: str, value: Any):
        """Prevent setting an attribute that would cause the profile to become 
        a user profile

        Args:
            key (str): Name of the attribute to set
            value (Any): Value to set the attribute to

        Raises:
            AccessServerProfileIntegrityError: Tried to set a property that
                would cause the profile to become a user
        """
        if (key == 'group_declare' and str(value).lower() != 'true'):
            raise exceptions.AccessServerProfileIntegrityError(
                'Attempt made to set group_declare to a false value on a '
                'GroupProfile. This is an illegal operation.')
        super().__setattr__(key, value)
Esempio n. 8
0
    def __init__(self, group_name: str, profile: Profile, **attrs):
        if profile is not None and not isinstance(profile, Profile):
            raise TypeError(
                f"Expected 'Profile' for arg 'profile', got {type(profile)}")
        elif profile is not None:
            props = profile._attrs
        else:
            props = {}

        for key, value in attrs.items():
            props[key] = value

        super().__init__(**props)
        if not self.is_group:
            raise exceptions.AccessServerProfileIntegrityError(
                'Properties given do not describe a GroupProfile')
        # __setattr__ issues, see Profile class
        object.__setattr__(self, 'group_name', group_name)
        self.group_name = group_name
Esempio n. 9
0
    def __init__(self, username: str, profile: Profile = None, **attrs):
        if profile is not None and not isinstance(profile, Profile):
            raise TypeError(
                f"Expected 'Profile' for arg 'profile', got {type(profile)}")
        elif profile is not None:
            props = profile._attrs
        else:
            props = {}

        for key, value in attrs.items():
            props[key] = value

        super().__init__(**props)
        if self.type not in self.USER_TYPES:
            raise exceptions.AccessServerProfileIntegrityError(
                f"Properties given do not describe a UserProfile")
        # __setattr__ issues, see Profile class
        object.__setattr__(self, 'username', username)
        self.username = username