@param SecurityIdentityInterface $securityIdentity
@param int                       $mask
@param int                       $noInheritMask
@param int                       $stopMask
@param string|null               $contentLanguage

@return $this
485700
public function setAce(
        SecurityIdentityInterface $securityIdentity,
        $mask,
        $noInheritMask,
        $stopMask,
        $contentLanguage = null
    ) {
        if ($contentLanguage === '_all_') {
            $contentLanguage = null;
        }

        $ace = null;
        foreach ($this->entries as $entry) {
            if ($entry->getSecurityIdentifier() === $securityIdentity->getIdentifier() && $entry->getSecurityType() === $securityIdentity->getType()) {
                $ace = $entry;
                break;
            }
        }

        if (!$ace) {
            $ace = new Entry();
            $ace
                ->setObjectType($this->objectIdentity->getType())
                ->setObjectId($this->objectIdentity->getIdentifier())
                ->setSecurityType($securityIdentity->getType())
                ->setSecurityId($securityIdentity->getIdentifier())
                ->setObjectLanguage($contentLanguage);
        }

        $ace
            ->setMask((int) $mask)
            ->setStopMask((int) $stopMask)
            ->setNoInheritMask((int) $noInheritMask);

        return $this;
    }
840008
protected function applyIpV4Mask($ip, $maskLength)
    {
        $i = strlen($ip);
        if ($maskLength > $i) {
            $maskLength = $i;
        }

        while ($maskLength-- > 0) {
            $ip[--$i] = chr(0);
        }
        return (string)$ip;
    }
651671
private function addWhereSecurityIdentitiesForSharing(GetFilterEvent $event, ClassMetadata $meta)
    {
        $where = '';
        $mapSids = (array) $event->getRealParameter('map_security_identities');
        $mapSids = !empty($mapSids) ? $mapSids : ['_without_security_identity' => 'null'];
        $connection = $event->getConnection();

        foreach ($mapSids as $type => $stringIds) {
            $where .= '' === $where ? '' : ' OR ';
            $where .= sprintf(
                '(s.%s = %s AND s.%s IN (%s))',
                $meta->getColumnName('identityClass'),
                $connection->quote($type),
                $meta->getColumnName('identityName'),
                $stringIds
            );
        }

        return $where;
    }
817270
public function setSmtpSecurity($security)
    {
        $security = strtoupper($security);
        $validSecurity = [ '', 'TLS', 'SSL' ];

        if (!in_array($security, $validSecurity)) {
            throw new InvalidArgumentException(
                'SMTP Security is not valid. Must be "", "TLS" or "SSL".'
            );
        }

        $this->smtpSecurity = $security;

        return $this;
    }
851537
protected function applyIpV6Mask($ip, $maskLength):string
    {
        $masks = ['ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 'ffff:ffff:ffff:ffff::', 'ffff:ffff:ffff:0000::', 'ffff:ff00:0000:0000::'];
        $packedAddress = inet_pton($masks[$maskLength]);
        $binaryString = pack('a16', $packedAddress);
        return (string)($ip & $binaryString);
    }
102697
public function authenticate(TokenInterface $token)
    {
        if (false === $this->supports($token)) {
            throw new SecurityException('Invalid token provided', SecurityException::UNSUPPORTED_TOKEN);
        }

        try {
            $user = $this->userProvider->loadUserByUsername($token->getUsername());
            $secret = $user->getPassword();
            if ($this->encoderFactory) {
                try {
                    $encoder = $this->encoderFactory->getEncoder($user);

                    if ($encoder instanceof PlaintextPasswordEncoder) {
                        $secret = md5($secret);
                    } elseif ($encoder instanceof MessageDigestPasswordEncoder) {
                        // $secret is already md5 encoded
                        // NB: only md5 algo without salt is currently supported due to frontend dependency
                    } else {
                        // currently there is a dependency on md5 in frontend so all other encoders can't be supported
                        throw new \RuntimeException('Encoder is not supported: '.get_class($encoder));
                    }
                } catch (\RuntimeException $e) {
                    // no encoder defined
                    $secret = md5($secret);
                }
            } else {
                // no encoder - still have to encode with md5
                $secret = md5($secret);
            }

            $this->checkNonce($token, $secret);
        } catch (\Exception $e) {
            $this->clearNonce($token);
            throw $e;
        }

        $validToken = new BBUserToken($user->getRoles());
        $validToken
            ->setUser($user)
            ->setNonce($token->getNonce())
            ->setCreated(new \DateTime())
            ->setLifetime($this->lifetime)
        ;

        $this->writeNonceValue($validToken);

        return $validToken;
    }
812674
protected function applyIpMask(string $ip, int $maskLength): string
    {
        if (empty($ip) || $maskLength === 0) {
            return $ip;
        }

        // IPv4 or mapped IPv4 in IPv6
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            return $this->applyIpV4Mask($ip, $maskLength);
        }

        return $this->applyIpV6Mask($ip, $maskLength);
    }
342609
public function getIdentity(): ?IdentityInterface
    {
        if (!$this->identity) {
            // check user agent
            if (Session::get('auth:agent') === Request::getServer('HTTP_USER_AGENT')) {
                $this->identity = Session::get('auth:identity');
            } else {
                $this->clearIdentity();
            }
        }
        return $this->identity;
    }
923817
public function encrypt(InputOutputInterface $cipherInputOutput, $embedContentInfo = true)
    {
        try {
            return $this->cipher->encrypt($cipherInputOutput->getInput(), $embedContentInfo);
        } catch (Exception $exception) {
            throw new CipherException($exception->getMessage(), $exception->getCode());
        }
    }
76526
private function addContentsRights(array $config, UserSecurityIdentity $securityIdentity)
    {
        $rights = $this->getActionsOnResources($config);
        foreach ((array) $rights as $resource => $actions) {
            if ('all' === $resource) {
                $this->addClassAcl(AbstractClassContent::class, $securityIdentity, $actions);
                $this->writeln(sprintf('    - Setting [%s] on all content', implode(', ', $actions)), OutputInterface::VERBOSITY_DEBUG);
                continue;
            }

            try {
                $classname = AbstractClassContent::getFullClassname($resource);
                if (class_exists($classname)) {
                    $this->addClassAcl($classname, $securityIdentity, $actions);
                    $this->writeln(sprintf('    - Setting [%s] on %s', implode(', ', $actions), $cclassname), OutputInterface::VERBOSITY_DEBUG);
                }
            } catch (\Exception $ex) {
                $this->writeln(sprintf('    - Unknown content `%s`', $classname), OutputInterface::VERBOSITY_DEBUG);
            }
        }
    }
1090176
public function authenticate(SecurityContextInterface &$context) {

        $token = $this->generateEmptyToken($this->getSession());

        try {
            $this->userAuthenticationProvider->loadClientByCredentials($token->getClient()->getCredentials());
        } catch (ClientCredentialsNotFoundException $e) {

            $this->logger->addAlert('Client not found ' . $e->getMessage());
            throw $e;
        }

        //validate the client, if good then add to the context
        if (true) {
            $context->setToken($token);
        }
    }
778243
private function resolveMask($masks, $object)
    {
        $integerMask = 0;

        if (is_integer($masks)) {
            $integerMask = $masks;
        } elseif (is_string($masks)) {
            $permission = $this->permissionMap->getMasks($masks, $object);
            $integerMask = $this->resolveMask($permission, $object);
        } elseif (is_array($masks)) {
            foreach ($masks as $mask) {
                $integerMask += $this->resolveMask($mask, $object);
            }
        } else {
            throw new \RuntimeException('Not a valid mask type');
        }

        return $integerMask;
    }
158586
public function generateSignature($content, VirgilPrivateKey $signerPrivateKey)
    {
        try {
            return $this->cryptoService->sign($content, $signerPrivateKey->getValue());
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
964486
public function mask($mask = null){
        $mask = $mask !== null ? $mask : $this->mask;
        if(class_exists($mask)){
            return new $mask($this);
        }

        throw new MaskNotFoundException("Unknown mask provided: ".$mask);
    }
281453
public function addGroupSecurityIdentities(AddSecurityIdentityEvent $event): void
    {
        try {
            $sids = $event->getSecurityIdentities();
            $sids = IdentityUtils::merge(
                $sids,
                GroupSecurityIdentity::fromToken($event->getToken())
            );
            $event->setSecurityIdentities($sids);
        } catch (\InvalidArgumentException $e) {
            // ignore
        }
    }
1066775
public static function hashCredential(CredentialInterface $identity, $plaintext, $saltLength = 30){
        $dbPassword = $identity->getCredential();
        $salt = substr($dbPassword, 0, (int) $saltLength);
        return self::hashAndPrependSalt($salt, (string) $plaintext);
    }
484896
public function withMask(IPAddressInterface $mask): IPAddressInterface
    {
        $octets = $this->getParts();
        $maskOctets = $mask->getParts();

        for ($i = 0; $i < 4; $i++) {
            $octets[$i] = $octets[$i] & $maskOctets[$i];
        }

        return new self($octets);
    }