access-control

sql
-- Create roles
CREATE ROLE readonly;
CREATE ROLE readwrite;
CREATE ROLE admin WITH LOGIN PASSWORD 'secure_password';

-- Grant permissions to roles

Database security and access control

database security permissions
by Maria Garcia 2 tabs
java
package com.shop.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;

Guard a Checkout Endpoint with @PreAuthorize and a Custom PermissionEvaluator in Spring Boot

spring-boot spring-security authorization
by codesnips 3 tabs
php
<?php

namespace App\Security\Voter;

use App\Entity\Comment;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

Enforce Comment Ownership With a Symfony Voter and Controller Authorization Check

symfony security voter
by codesnips 3 tabs
typescript
export const PERMISSIONS = {
  READ_POSTS: 'posts:read',
  WRITE_POSTS: 'posts:write',
  DELETE_POSTS: 'posts:delete',
  MANAGE_USERS: 'users:manage',
} as const;

Typed Role-Based Route Guards with Permission Middleware in Express

express authorization rbac
by codesnips 3 tabs
ruby
class ApplicationPolicy
  attr_reader :user, :record

  def initialize(user, record)
    @user = user
    @record = record

Enforcing Controller Authorization with a Pundit-Style Policy Object in Rails

rails authorization pundit
by codesnips 4 tabs
php
<?php

namespace App\Policies;

use App\Models\Post;
use App\Models\User;

Authorize Post Editing With a Laravel Policy and Gate the Controller

laravel authorization policies
by codesnips 3 tabs
ruby
module Authorizable
  extend ActiveSupport::Concern

  class NotAuthorized < StandardError; end

  included do

Rails Policy Authorization with a before_action Concern and 403 Rendering

rails authorization controllers
by codesnips 3 tabs