<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Leeqvip on Medium]]></title>
        <description><![CDATA[Stories by Leeqvip on Medium]]></description>
        <link>https://medium.com/@leeqvip?source=rss-a1d7b9455ca5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*s8dem5QXYi3hO0q9</url>
            <title>Stories by Leeqvip on Medium</title>
            <link>https://medium.com/@leeqvip?source=rss-a1d7b9455ca5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:26:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leeqvip/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[One-Line Defense Against BOLA: Killing Data-Level if-else Hell with PHP-Casbin]]></title>
            <link>https://medium.com/@leeqvip/one-line-defense-against-bola-killing-data-level-if-else-hell-with-php-casbin-03066a9b4a95?source=rss-a1d7b9455ca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/03066a9b4a95</guid>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[abac]]></category>
            <category><![CDATA[data-permission]]></category>
            <dc:creator><![CDATA[Leeqvip]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 16:23:13 GMT</pubDate>
            <atom:updated>2026-09-10T16:23:13.732Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjiQ0e6hE9uHGgZrbnsBtw.jpeg" /><figcaption>PHP-Casbin</figcaption></figure><p>In web application security, Broken Object Level Authorization (BOLA, or IDOR) consistently haunts the top ranks of the OWASP API Security Top 10.</p><p>To put it in plain English: Alice logs into your app, views her invoice at /orders/1001, and then notices the number in her browser address bar. She casually changes 1001 to 1002, hits Enter, and suddenly she is staring at Bob&#39;s private shipping address and billing details. If your API is even sloppier, she might fire off a DELETE request and wipe out Charlie&#39;s data entirely.</p><p>Most teams initially fight this vulnerability by littering their controllers with defensive if-else checks. But as the product evolves, business code gets buried under layers of hotfixes—fix one leak here, accidentally open three new ones over there.</p><p>Here is the good news: <a href="https://github.com/php-casbin/php-casbin">PHP-Casbin</a> natively supports passing full PHP objects directly into its enforcement engine. With a single line of code, you can shut down object-level authorization bypasses for good.</p><h3>The Pain of Hardcoded Ownership Checks</h3><p>Take a look at the all-too-familiar spaghetti code in controllers without a dedicated authorization engine:</p><pre>// An everyday ownership check inside a controller<br>public function update(Request $request, int $orderId)<br>{<br>    $order = Order::findOrFail($orderId);<br>    $user = auth()-&gt;user();<br>    // Business rules and permission checks tangled together<br>    if ($user-&gt;role !== &#39;admin&#39; &amp;&amp; $order-&gt;owner_id !== $user-&gt;id) {<br>        throw new ForbiddenException(&quot;Hands off someone else&#39;s order!&quot;);<br>    }<br>    if ($order-&gt;status === &#39;archived&#39; &amp;&amp; $user-&gt;role !== &#39;admin&#39;) {<br>        throw new BusinessException(&quot;Archived orders cannot be modified.&quot;);<br>    }<br>    $order-&gt;update($request-&gt;validated());<br>}</pre><p>This brute-force approach seems easy enough on day one, but it quickly turns into a maintenance nightmare:</p><ul><li><strong>Leaks everywhere</strong>: Updating an order needs an ownership check, viewing details needs one, downloading attachments needs one, canceling needs another. You end up copy-pasting the same snippet across dozens of endpoints. The moment a newcomer forgets that check on a new route, you have a critical security vulnerability in production.</li><li><strong>Modifying rules feels like walking through a minefield</strong>: The product manager suddenly asks: “Can quality assurance leads temporarily edit orders during business hours?” You now have to hunt down every single related controller and append new conditions to those if statements, praying you did not miss one.</li><li><strong>Permission clutter overshadows business logic</strong>: The core purpose of your method is simply updating a few fields, yet half the code is occupied with detective work verifying who owns what.</li></ul><h3>Busting the Myth: Casbin Only Takes Strings?</h3><p>Many developers who have dabbled in Casbin remember it looking something like this:</p><pre>// The classic route-level interception<br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;/api/orders&#39;, &#39;POST&#39;);</pre><p>This leaves an unfortunate misconception: people assume Casbin only accepts plain strings, works exclusively at the gateway or middleware layer, and can only answer questions like “Can this user call this route?” When it comes to “Can this user edit <em>this specific record</em>?”, many believe Casbin cannot help.</p><p>That could not be further from the truth. The PERM metamodel behind Casbin is remarkably expressive. In PHP-Casbin, enforce() can take real PHP objects directly. While evaluating the matcher expression, the engine dynamically reaches into the object, inspects its properties, and performs the check on the fly.</p><h3>Rule Configuration: Decoupling Policy from Code</h3><p>All you need is a concise abac_model.conf file to declare your ownership rules and business constraints in one clean place:</p><pre>[request_definition]<br>r = sub, obj, act<br><br>[policy_definition]<br>p = sub, obj, act<br><br>[policy_effect]<br>e = some(where (p.eft == allow))<br><br>[matchers]<br>m = r.sub.role == &quot;admin&quot; || (r.sub.id == r.obj.owner_id &amp;&amp; r.act in [&quot;read&quot;, &quot;update&quot;] &amp;&amp; r.obj.status != &quot;archived&quot;)</pre><p>The configuration is brief, and the logic is straightforward:</p><ul><li>r.sub represents the subject (the requester). You can pass the authenticated user object directly; the engine will automatically resolve r.sub.id and r.sub.role.</li><li>r.obj represents the target resource. You pass the retrieved order model directly; the engine compares r.obj.owner_id and checks r.obj.status.</li><li>m serves as the referee: system administrators get an immediate green light; regular users must satisfy two strict conditions—they must own the data, and the order must not be archived.</li></ul><h3>In the Controller: Keeping Business Logic Clean</h3><p>With the policy declared externally, your controller code suddenly becomes a breath of fresh air:</p><pre>use Casbin\Enforcer;<br><br>class OrderController<br>{<br>    public function update(Request $request, int $orderId, Enforcer $enforcer)<br>    {<br>        $order = Order::findOrFail($orderId);<br>        $user = auth()-&gt;user();<br><br>        // One clean line: pass the user, the resource, and the action to Casbin<br>        if (!$enforcer-&gt;enforce($user, $order, &#39;update&#39;)) {<br>            abort(403, &quot;You do not have permission to modify this record.&quot;);<br>        }<br><br>        // Clean, uncluttered business execution<br>        $order-&gt;update($request-&gt;validated());<br>        return response()-&gt;json([&#39;message&#39; =&gt; &#39;Updated successfully&#39;]);<br>    }<br>}</pre><p>The controller no longer cares about the intricate relationship between users, roles, and resource states. It merely hands the user and the data model over to the enforcer. If it receives false, it returns a 403.</p><p>If product requirements change tomorrow — say, giving support supervisors temporary edit access — you only need to adjust the matcher in your configuration file. Not a single line of your controller code needs to be touched.</p><h3>Native Compatibility with Real-World PHP Objects</h3><p>You might wonder: “My project uses Laravel Eloquent with dynamic attributes via __get(), and my teammate prefers strongly-typed DTOs. Can Casbin handle that?&quot;</p><p>The answer is yes. PHP-Casbin comes with adaptive introspection built in:</p><pre>// Plain DTOs, stdClass instances, or Eloquent models all work out of the box<br>$user = auth()-&gt;user();<br>$order = Order::findOrFail($orderId);<br><br>// The engine transparently resolves public properties, getters, and magic attributes<br>$enforcer-&gt;enforce($user, $order, &#39;update&#39;);<br></pre><p>Whether you pass standard PHP entities, dynamic data objects, or framework models with magic getters, the engine resolves the requested fields effortlessly. There is zero need to flatten objects into arrays or serialize them to JSON beforehand. Just pass the objects as they are.</p><h3>Wrapping Up</h3><p>If access control stops at route-level checks, it is like a security guard who checks IDs at the building’s front entrance while leaving every apartment door wide open.</p><p>Stop cluttering your business logic with defensive, error-prone ownership checks. By leveraging object-level ABAC in <a href="https://github.com/php-casbin/php-casbin">PHP-Casbin</a>, you can extract permission rules into a clean declarative model. You will shut down BOLA vulnerabilities before they hit production, and you will save your team countless hours of frustrating bug-hunting down the road.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03066a9b4a95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Cryptography in Go: Introducing go-think/openssl]]></title>
            <link>https://medium.com/@leeqvip/mastering-cryptography-in-go-introducing-go-think-openssl-9970fb96e694?source=rss-a1d7b9455ca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9970fb96e694</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[ae]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[gcm]]></category>
            <dc:creator><![CDATA[Leeqvip]]></dc:creator>
            <pubDate>Fri, 21 Aug 2026 05:10:54 GMT</pubDate>
            <atom:updated>2026-08-21T05:10:54.042Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvHNkEbWqwaC4fHfqHWKVg.jpeg" /><figcaption><strong>A pure Go cryptographic library providing OpenSSL-compatible symmetric and asymmetric encryption (AES, DES, 3DES, RSA, GCM), digital signatures, and SHA/HMAC — 100% interoperable with PHP, Java, and Node.js.</strong></figcaption></figure><blockquote><strong><em>Zero-Boilerplate, 100% Cross-Language Compatible Encryption for Go Developers</em></strong></blockquote><p>Cryptography in Go has always been a tale of two worlds.</p><p>On one hand, Go’s standard library crypto/* packages are well-crafted, secure, and fast. On the other hand, implementing everyday cryptographic workflows—like encrypting a payload with <strong>AES-CBC (PKCS#7)</strong>, performing <strong>AES-ECB</strong> for legacy systems, or handling <strong>RSA encryption for large payloads</strong>—requires writing dozens of lines of repetitive boilerplate code.</p><p>Even worse, subtle differences in padding schemes, IV handlings, or key truncations often lead to frustrating cross-language decryption failures when communicating with <strong>PHP (</strong><strong>openssl_encrypt)</strong>, <strong>Java (</strong><strong>javax.crypto)</strong>, <strong>Python (</strong><strong>pycryptodome)</strong>, or <strong>Node.js</strong>.</p><p>To solve these headaches once and for all, meet <a href="https://github.com/go-think/openssl"><strong>go-think/openssl</strong></a> — a developer-friendly, pure Go cryptographic toolkit that brings simplicity and seamless cross-platform interoperability to Go applications.</p><h3>💡 Why go-think/openssl?</h3><ol><li><strong>Pure Go, No CGO Dependencies</strong>: Lightweight, cross-compilation friendly, and built on top of standard Go crypto primitives.</li><li><strong>Zero-Boilerplate API</strong>: Do what used to take 40 lines in just 2 or 3 lines.</li><li><strong>100% Cross-Language Compatibility</strong>: Produces identical binary ciphertext to OpenSSL, PHP, Java, Python, and Node.js.</li><li><strong>Smart Padding &amp; Chunking</strong>:</li></ol><ul><li>Native support for <strong>PKCS#7 (PKCS#5)</strong> and <strong>ZeroPadding</strong>.</li><li><strong>Automatic chunking</strong> for RSA encryption and decryption of arbitrarily long messages.</li></ul><ol><li><strong>Batteries Included</strong>: AES, DES, 3DES, RSA, MD5, SHA-1 to SHA-512, and HMAC.</li></ol><h3>🚀 Quick Installation</h3><pre>go get -u github.com/go-think/openssl</pre><h3>🛠️ Code in Action</h3><h3>1. Symmetric Encryption: AES (CBC, ECB &amp; GCM)</h3><p>Standard Go requires manual block padding, block mode initialization, and slice slicing. With go-think/openssl, it is as simple as:</p><h4>AES-CBC with PKCS#7 Padding</h4><pre>package main<br><br>import (<br>    &quot;encoding/base64&quot;<br>    &quot;fmt&quot;<br>    &quot;github.com/go-think/openssl&quot;<br>)<br><br>func main() {<br>    src := []byte(&quot;Hello, Cross-Language World!&quot;)<br>    key := []byte(&quot;1234567890123456&quot;) // 16-byte key for AES-128<br>    iv  := []byte(&quot;1234567890123456&quot;) // 16-byte IV<br>    // Encrypt<br>    cipherText, err := openssl.AesCBCEncrypt(src, key, iv, openssl.PKCS7_PADDING)<br>    if err != nil {<br>        panic(err)<br>    }<br>    fmt.Println(&quot;Base64 Ciphertext:&quot;, base64.StdEncoding.EncodeToString(cipherText))<br>    // Decrypt<br>    plainText, err := openssl.AesCBCDecrypt(cipherText, key, iv, openssl.PKCS7_PADDING)<br>    if err != nil {<br>        panic(err)<br>    }<br>    fmt.Println(&quot;Decrypted:&quot;, string(plainText))<br>}</pre><h4>Modern AEAD: AES-GCM (Authenticated Encryption)</h4><p>For applications that require authenticated encryption with integrity checks:</p><pre>nonce := []byte(&quot;123456789012&quot;)          // 12-byte standard nonce<br>aad   := []byte(&quot;authenticated_header&quot;) // Additional authenticated data<br><br>// Encrypt<br>dst, err := openssl.AesGCMEncrypt(src, key, nonce, aad)<br><br>// Decrypt<br>plain, err := openssl.AesGCMDecrypt(dst, key, nonce, aad)</pre><p>Also supports <strong>CFB</strong>, <strong>OFB</strong>, <strong>CTR</strong>, as well as legacy <strong>DES</strong> and <strong>3DES</strong> ciphers out of the box.</p><h3>2. Painless RSA: Key Generation, Signatures &amp; Auto-Chunking</h3><p>One notorious limitation of raw RSA is that it cannot encrypt data larger than its key size minus padding overhead. Usually, developers must write chunking and buffer reassembly logic. go-think/openssl handles this automatically:</p><pre>package main<br><br>import (<br>    &quot;bytes&quot;<br>    &quot;crypto&quot;<br>    &quot;fmt&quot;<br>    &quot;github.com/go-think/openssl&quot;<br>)<br><br>func main() {<br>    // 1. Generate a 2048-bit RSA Key Pair in PEM format<br>    var privBuf, pubBuf bytes.Buffer<br>    _ = openssl.RSAGenerateKey(2048, &amp;privBuf)<br>    _ = openssl.RSAGeneratePublicKey(privBuf.Bytes(), &amp;pubBuf)<br><br>    privKey := privBuf.Bytes()<br>    pubKey  := pubBuf.Bytes()<br><br>    // 2. Encrypt arbitrary-length data (Automatic chunking under the hood)<br>    longData := []byte(&quot;A very long message that exceeds standard RSA block size limit...&quot;)<br>    encrypted, _ := openssl.RSAEncrypt(longData, pubKey)<br><br>    // Decrypt<br>    decrypted, _ := openssl.RSADecrypt(encrypted, privKey)<br>    fmt.Println(&quot;Decrypted RSA:&quot;, string(decrypted))<br><br>    // 3. Digital Signatures (RSASign &amp; RSAVerify)<br>    signature, _ := openssl.RSASign(longData, privKey, crypto.SHA256)<br>    <br>    err := openssl.RSAVerify(longData, signature, pubKey, crypto.SHA256)<br>    if err == nil {<br>        fmt.Println(&quot;Signature verified successfully!&quot;)<br>    }<br>}</pre><blockquote><strong><em>Note</em></strong><em>: </em><em>RSAEncrypt also seamlessly accepts X.509 </em><em>CERTIFICATE PEM blocks!</em></blockquote><h3>3. One-Liner Hashes &amp; HMACs</h3><p>Stop creating hash.Hash interfaces just to get a hex digest:</p><pre>// MD5<br>hexMD5 := openssl.Md5ToString(&quot;hello world&quot;)<br><br>// SHA-256<br>hexSHA := openssl.Sha256ToString(&quot;hello world&quot;)<br><br>// HMAC-SHA256<br>hmacStr := openssl.HmacSha256ToString(&quot;secret-key&quot;, &quot;hello world&quot;)</pre><h3>🌐 100% Interoperability: Go vs. PHP vs. Java</h3><p>Let’s test if the ciphertext generated by Go matches other platforms bit-for-bit.</p><h3>In Go (go-think/openssl):</h3><pre>src := []byte(&quot;123456&quot;)<br>key := []byte(&quot;1234567890123456&quot;)<br>iv  := []byte(&quot;1234567890123456&quot;)<br><br>dst, _ := openssl.AesCBCEncrypt(src, key, iv, openssl.PKCS7_PADDING)<br>fmt.Println(base64.StdEncoding.EncodeToString(dst))<br>// Output: 1jdzWuniG6UMtoa3T6uNLA==</pre><h3>In PHP (openssl_encrypt):</h3><pre>&lt;?php<br>$data = &quot;123456&quot;;<br>$key  = &quot;1234567890123456&quot;;<br>$iv   = &quot;1234567890123456&quot;;<br><br>$encrypted = openssl_encrypt($data, &#39;aes-128-cbc&#39;, $key, OPENSSL_RAW_DATA, $iv);<br>echo base64_encode($encrypted);<br>// Output: 1jdzWuniG6UMtoa3T6uNLA== (Identical!)</pre><h3>In Java (javax.crypto):</h3><pre>Cipher cipher = Cipher.getInstance(&quot;AES/CBC/PKCS5Padding&quot;);<br>cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes(), &quot;AES&quot;), new IvParameterSpec(iv.getBytes()));<br>byte[] encrypted = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));<br>System.out.println(Base64.getEncoder().encodeToString(encrypted));<br>// Output: 1jdzWuniG6UMtoa3T6uNLA== (Identical!)</pre><h3>📦 Summary</h3><p>If you are building Go microservices that need to interact with external APIs, legacy systems, mobile apps, or other backends without wrestling with cryptographic discrepancies, go-think/openssl will save you hours of debugging.</p><ul><li><strong>GitHub Repository</strong>: <a href="https://github.com/go-think/openssl">https://github.com/go-think/openssl</a></li><li><strong>Go Package Documentation</strong>: <a href="https://pkg.go.dev/github.com/go-think/openssl">pkg.go.dev/github.com/go-think/openssl</a></li><li><strong>License</strong>: Apache 2.0</li></ul><p>Give it a ⭐ on GitHub if you find it useful, and feel free to submit issues or pull requests!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9970fb96e694" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yii-Permission 3.0 Released: Built for Yii 3.0]]></title>
            <link>https://medium.com/@leeqvip/yii-permission-3-0-released-built-for-yii-3-0-484ea7d06249?source=rss-a1d7b9455ca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/484ea7d06249</guid>
            <category><![CDATA[access-control]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[yii]]></category>
            <dc:creator><![CDATA[Leeqvip]]></dc:creator>
            <pubDate>Fri, 31 Jul 2026 03:10:51 GMT</pubDate>
            <atom:updated>2026-07-31T03:10:51.501Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nyCoEQ9kqdoBMmEFX6MA1g.png" /><figcaption>Yii-Permission</figcaption></figure><p>In modern web development and enterprise system architecture, a flexible and efficient access control system is the ultimate cornerstone of application security. As a powerful and high-performance open-source access control framework, <strong>Casbin</strong> supports various access control models — including ACL, RBAC, and ABAC — and is widely adopted across multiple language ecosystems.</p><h3>Embracing Yii 3.0’s Standalone Component Ecosystem</h3><p>The core highlight of v3.0 lies in its full adaptation to the Yii 3.0 framework architecture. As Yii 3.0 transitions toward a modernized, highly componentized, and PSR-standard-compliant design, yii-permission has undergone a complete architectural redesign—from low-level design to interface integration:</p><ul><li><strong>Higher Minimum Environment Requirements:</strong> The package now requires <strong>PHP 8.2+</strong>, taking full advantage of the latest type system and strong typing to boost code robustness.</li><li><strong>Modern DI Container Configuration:</strong> Upgraded configuration management powered by yiisoft/config ensures that declaring and initializing the Casbin authorization engine aligns seamlessly with Yii 3.0 native standards.</li></ul><h3>Complete Decoupling: From Traditional Components to PSR-15 Middleware</h3><p>In the Yii 2.0 era, access control was largely dependent on controller-level behaviors or Application components. Following modern PHP web architecture trends, yii-permission 3.0 introduces <strong>PSR-15 standard HTTP middleware</strong>:</p><ul><li><strong>EnforcerMiddleware</strong>: Intercepts requests directly within the HTTP pipeline to execute Casbin model-based authorization.</li><li><strong>RequestMiddleware</strong>: Facilitates context preprocessing and extraction from incoming requests.</li></ul><p>With PSR-15 middleware, authorization logic can be effortlessly attached to global request pipelines or specific route groups, significantly improving middleware reusability and execution efficiency.</p><h3>Seamless Integration with Yiisoft Access Interface</h3><p>To deliver a consistent developer experience for Yii users, yii-permission 3.0 introduces a new AccessChecker class implementing the Yiisoft\Access\AccessCheckerInterface.</p><p>This allows developers to continue using Yii’s native access-checking semantics:</p><pre>// Easily perform permission checks in controllers or services using the unified interface<br>if ($user-&gt;can(&#39;article.update&#39;, [&#39;article&#39; =&gt; $article])) {<br>    // Permission granted: perform update operation<br>}</pre><h3>Key Updates Summary</h3><p>According to the official GitHub Release notes, here is a summary of the key features and breaking changes in <strong>v3.0.0</strong>:</p><ul><li><strong>Yii 3.0 Compatibility:</strong> Full support for Yii 3.0’s standalone component ecosystem and Dependency Injection (DI) standards.</li><li><strong>Updated Requirements:</strong> Requires PHP 8.2 or higher and Yii 3.0 framework packages.</li><li><strong>PSR-15 Middleware Architecture:</strong> Introduced EnforcerMiddleware and RequestMiddleware to replace legacy controller components.</li><li><strong>Native </strong><strong>AccessChecker Support:</strong> Added the AccessChecker class implementing Yiisoft\Access\AccessCheckerInterface, seamlessly empowering $user-&gt;can().</li><li><strong>Configuration &amp; CI Optimization:</strong> Integrated yiisoft/config for DI configuration management; updated GitHub Actions CI workflows, PHP testing matrices, and code coverage configurations.</li></ul><h3>Recommendation &amp; Upgrade Advice</h3><p>If you are building a new project with <strong>PHP 8.2+ and Yii 3.0</strong>, or planning to upgrade an existing application to Yii 3’s modern component stack, <strong>php-casbin/yii-permission 3.0</strong> is the premier access control solution.</p><p>Whether you need simple RBAC for single-tenant systems, or complex, multi-tenant ABAC (Attribute-Based Access Control) for high-concurrency environments, it provides a clean, standardized, and high-performance security layer.</p><ul><li><strong>GitHub Repository:</strong> <a href="https://github.com/php-casbin/yii-permission">https://github.com/php-casbin/yii-permission</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=484ea7d06249" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP-Casbin is a powerful and efficient open-source access control library for PHP projects]]></title>
            <link>https://medium.com/@leeqvip/php-casbin-is-a-powerful-and-efficient-open-source-access-control-library-for-php-projects-749ba8a7c202?source=rss-a1d7b9455ca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/749ba8a7c202</guid>
            <category><![CDATA[casbin]]></category>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[rbac]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Leeqvip]]></dc:creator>
            <pubDate>Mon, 06 Jan 2025 03:28:52 GMT</pubDate>
            <atom:updated>2025-01-06T03:28:52.915Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wM-wmsiRnDCc6UTmgPMCBQ.png" /><figcaption>PHP-Casbin</figcaption></figure><p>The three core concepts of Casbin are: Model, Policy, Enforcer.</p><p>In Casbin, an access control model is abstracted into a CONF file based on the PERM metamodel (Policy, Effect, Request, Matchers).</p><p>Policy is the stored dynamic policy rules, which can be stored in a .csv file or in a database.</p><p>Enforcer decides whether a &quot;subject&quot; can access a &quot;object&quot; with the operation &quot;action&quot;.</p><h3>Installation</h3><p>Via composer.</p><pre>composer require casbin/casbin</pre><h3>Try it</h3><p>Create a model.conf and policy.csv file.</p><p>model.conf:</p><pre>[request_definition]<br>r = sub, obj, act<br><br>[policy_definition]<br>p = sub, obj, act<br><br>[policy_effect]<br>e = some(where (p.eft == allow))<br><br>[matchers]<br>m = r.sub == p.sub &amp;&amp; r.obj == p.obj &amp;&amp; r.act == p.act</pre><p>policy.csv:</p><pre>p, alice, data1, read<br>p, bob, data2, write</pre><p>New a Casbin enforcer with a model file and a policy file:</p><pre>use Casbin\Enforcer;<br><br>$enforcer = new Enforcer(&quot;path/to/model.conf&quot;, &quot;path/to/policy.csv&quot;);</pre><p>Add an enforcement hook into your code right before the access happens</p><pre>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;data1&#39;, &#39;read&#39;); // true<br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;data2&#39;, &#39;write&#39;); // false<br><br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;data1&#39;, &#39;read&#39;); // false<br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;data2&#39;, &#39;write&#39;); // true</pre><p>For more explanation, please check its Github repository：<a href="https://github.com/php-casbin/php-casbin">php-casbin/php-casbin: An authorization library that supports access control models like ACL, RBAC, ABAC in PHP .</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=749ba8a7c202" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Casbin for permission control in PHP]]></title>
            <link>https://medium.com/@leeqvip/using-casbin-for-permission-control-in-php-e578933de110?source=rss-a1d7b9455ca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e578933de110</guid>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[access-control]]></category>
            <category><![CDATA[casbin]]></category>
            <category><![CDATA[rbac]]></category>
            <dc:creator><![CDATA[Leeqvip]]></dc:creator>
            <pubDate>Fri, 27 Dec 2024 11:02:36 GMT</pubDate>
            <atom:updated>2024-12-27T11:02:36.923Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*biB0-GrqbOwkjXdimO8ZMg.png" /></figure><p><a href="https://github.com/php-casbin/php-casbin"><strong>PHP-Casbin</strong></a> is a powerful and efficient open-source access control library for PHP projects. It provides support for enforcing authorization based on various access control models, like ACL, RBAC, ABAC etc.</p><p>This article will introduce how to use Casbin in PHP and implement an RBAC+RESTful permission control.</p><h3>Get Started</h3><p>The three core concepts of Casbin are: Model, Policy, Enforcer.</p><p>In Casbin, an access control model is abstracted into a CONF file based on the PERM metamodel (Policy, Effect, Request, Matchers).</p><p>Policy is the stored dynamic policy rules, which can be stored in a .csv file or in a database.</p><p>Enforcer decides whether a &quot;subject&quot; can access a &quot;object&quot; with the operation &quot;action&quot;.</p><h3>Installation</h3><p>Via composer.</p><pre>composer require casbin/casbin</pre><h3>Try it</h3><p>Create a model.conf and policy.csv file.</p><p>model.conf:</p><pre>[request_definition]<br>r = sub, obj, act<br><br>[policy_definition]<br>p = sub, obj, act<br><br>[policy_effect]<br>e = some(where (p.eft == allow))<br><br>[matchers]<br>m = r.sub == p.sub &amp;&amp; r.obj == p.obj &amp;&amp; r.act == p.act</pre><p>policy.csv:</p><pre>p, alice, data1, read<br>p, bob, data2, write</pre><p>New a Casbin enforcer with a model file and a policy file:</p><pre>use Casbin\Enforcer;<br><br>$enforcer = new Enforcer(&quot;path/to/model.conf&quot;, &quot;path/to/policy.csv&quot;);<br><br>// Add an enforcement hook into your code right before the access happens<br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;data1&#39;, &#39;read&#39;); // true<br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;data2&#39;, &#39;write&#39;); // false<br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;data1&#39;, &#39;read&#39;); // false<br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;data2&#39;, &#39;write&#39;); // true</pre><h3>RBAC with Casbin</h3><p>Here we use the officially provided <a href="https://github.com/php-casbin/dbal-adapter">DBAL Adapter</a>.</p><pre>composer require casbin/casbin<br>composer require casbin/dbal-adapter</pre><h3>Use RBAC Model</h3><p>Our model.conf has the following contents:</p><pre>[request_definition]<br>r = sub, obj, act<br><br>[policy_definition]<br>p = sub, obj, act<br><br>#  the definition for the RBAC role inheritance relations<br>[role_definition]<br>g = _, _<br><br>[policy_effect]<br>e = some(where (p.eft == allow))<br><br>[matchers]<br>m = g(r.sub, p.sub) &amp;&amp; keyMatch2(r.obj, p.obj) &amp;&amp; regexMatch(r.act, p.act)</pre><p>New a Casbin enforcer with RBAC Model</p><pre>use Casbin\Enforcer;<br>use CasbinAdapter\DBAL\Adapter;<br><br>$adapter = Adapter::newAdapter([<br>    &#39;driver&#39; =&gt; &#39;pdo_mysql&#39;,<br>    &#39;host&#39; =&gt; &#39;127.0.0.1&#39;,<br>    &#39;dbname&#39; =&gt; &#39;test&#39;,<br>    &#39;user&#39; =&gt; &#39;root&#39;,<br>    &#39;password&#39; =&gt; &#39;&#39;,<br>    &#39;port&#39; =&gt; &#39;3306&#39;,<br>]);<br><br>$enforcer = new Enforcer(&#39;path/to/model.conf&#39;, $adapter);</pre><h3>Add Policy</h3><p>Assign roles to Alice and bob</p><pre>// alice has the admin role<br>$enforcer-&gt;addRoleForUser(&#39;alice&#39;, &#39;admin&#39;); <br>// bob has the member role<br>$enforcer-&gt;addRoleForUser(&#39;bob&#39;, &#39;member&#39;);</pre><p>Assign permissions to roles, member has all read operations:</p><pre>$enforcer-&gt;addPermissionForUser(&#39;member&#39;, &#39;/foo&#39;, &#39;GET&#39;);<br>$enforcer-&gt;addPermissionForUser(&#39;member&#39;, &#39;/foo/:id&#39;, &#39;GET&#39;);</pre><p>admin has all read and wirte operations:</p><pre>// admin inherits all permissions of member<br>$enforcer-&gt;addRoleForUser(&#39;admin&#39;, &#39;member&#39;);<br><br>$enforcer-&gt;addPermissionForUser(&#39;admin&#39;, &#39;/foo&#39;, &#39;POST&#39;);<br>$enforcer-&gt;addPermissionForUser(&#39;admin&#39;, &#39;/foo/:id&#39;, &#39;PUT&#39;);<br>$enforcer-&gt;addPermissionForUser(&#39;admin&#39;, &#39;/foo/:id&#39;, &#39;DELETE&#39;);</pre><p>Now the policy rules in the database are probably like this:</p><pre>g, alice, admin<br>g, bob, member<br><br>p, memeber, /foo, GET<br>p, memeber, /foo/:id, GET<br><br>g, admin, member<br><br>p, admin, /foo, POST<br>p, admin, /foo/:id, PUT<br>p, admin, /foo/:id, DELETE</pre><h3>Verify permissions</h3><p>alice has all the permissions of /foo.</p><pre>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;/foo&#39;, &#39;GET&#39;); // true<br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;/foo&#39;, &#39;GET&#39;); // true<br><br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;/foo&#39;, &#39;POST&#39;); // true<br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;/foo/1&#39;, &#39;PUT&#39;); // true<br>$enforcer-&gt;enforce(&#39;alice&#39;, &#39;/foo/1&#39;, &#39;DELETE&#39;); // true</pre><p>bob has member role, only read permission for /foo.</p><pre>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;/foo&#39;, &#39;GET&#39;); // true<br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;/foo&#39;, &#39;GET&#39;); // true<br><br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;/foo&#39;, &#39;POST&#39;); // false<br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;/foo/1&#39;, &#39;PUT&#39;); // false<br>$enforcer-&gt;enforce(&#39;bob&#39;, &#39;/foo/1&#39;, &#39;DELETE&#39;); // false</pre><h3>Conclusion</h3><p>In this article, we demonstrated how to use Casbin in PHP. We created a Enforcer using model files and policy files. We also used a database adapter to store policies in the database, assigned roles to users, and added RBAC+RESTFul interface policies. Casbin is a versatile library that can be customized to your specific access control needs. It also provides many extensions that can quickly integrate Casbin in <a href="https://github.com/php-casbin/laravel-authz"><strong>Laravel</strong></a>, <a href="https://github.com/php-casbin/yii-permission"><strong>Yii</strong></a>, and <a href="https://github.com/php-casbin/codeigniter-permission"><strong>Codeigniter</strong></a>. You can find more information about <a href="https://github.com/php-casbin/php-casbin"><strong>PHP-Casbin</strong></a> in Github.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e578933de110" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>