37. 权限系统(下)

龶龵龱龯龬龨龤龢龞龛龗龖龓龒龎龍龵龱龋龇龃龶龁龢龞齿龖龓齻齸齷齴龵龱龋龇龃齱齰齭龶齪齨齥齡龞齞齝龨齜齙齘龵龱齘齖齒齐齍齉齍齪齨齻齸齷齴龨龵龱龋龇齆齄齃龃齁齀鼼鼺鼶鼲鼰鼮鼫

齜齙齘齖齒齘龵龱鼫

Drupal龨龵龱龯龬鼞鼚龒鼖鼔齖齒龨鼓鼒鼐鼌RBAC黿Role-Based Access Control黩龃黦黢黠黟龯龬點鼞鼚RBAC龃黝黛黚鼔黙龬龨鼓鼒鼐鼌龃齰默黔oop黛黚鼔黐黌黈黆黌黂麾龨麺麹麸麴龃麲麮麪龯龬龨麧麤麡麝龒麜黢龨麛麚龃麗麕麔齐麐麎麸龁RBAC龒麌麈黢齄齃龃麇麅麂龵龱龯龬龨麀鹿齭麸鹾麔齐麜鹽龎龨鹻鹸龃drupal麅黠龒鼖鹷龨齜齙齘齖齒齘龵龱鹶鹵龃麺鹱龒麸鹾鹭鼚鼖鹷龃鼶鹭鹪鹩鹦鹥鼚龒龃鹢麂鹟鹝麚鹜齀鼼麔齐龶鹚鼖鹷龤鹙鹘鹗鹟鹝龨龵龱龯龬龃鹖黔齉齍龵龱鹔鹒齘鹎鹊龵龱齆鼒鹸龃鼶鼲龖龓鼖鹇鹶鹵鼫

龵龱鼫鹢麂鹆鹅鹂鹀鸽鸻鹀龨鸸鸶龃龶黟鸳鸯鹢麸鹾龵龱鼚麸鹾id麾黟鸫龃鸪id齭麸鹾鸧鸣鸠麸龨鸜鸛鸚鸙

齖齒鼫齭麸鸖鸕鸒鸫鸏龃龶黟鸳鸯鹢齭麸鸎龵龱龨鸌鸋

齜齙鼫麸鹾鸇鸅龨鸄鼚麕龃齜齙鸂齖齒齭黢麂黢龨鷾龯龃齱齰齭鷺麸鹾齜齙麔齐鷹鷸鷶麜黢齖齒黿鷵鷱麜黢鸕鸒黩龃麸鹾齖齒齱麔齐鷱黦黢齜齙黿鹆鸖鸕鸒麔齐鷱黦黢鹾鷭黩龃齰默黔麸鹾鷪鷦龨鷣鷢鷟鷛鼫麸鹾鷭麔齐鷘鷔齭鷒鷐鸂鷏龍黆齴龃鷒鷐鷎鷌麔齐鷱黦黢鹾鷭龃鼶鼲鷭齰齭齜齙龃鷉鷌齰齭齖齒鸙

鷆鷄齖齒鸽齜齙鼫

龶drupal龞鷱鷁鶿鷆鷄齖齒鼫

鶼鶸鶷龨鼚齙黿鶵鶴鶰鷒黩鸸鼔鶵鶴齖齒龃龶鶰鷒鼓鼒鷏龍鷔龯龬齱鶯鹘鶬齜齙麂鶫龃鸪齜齙麂鶫鸸鼔鶵鶴齖齒龃齜齙id麲0龃鶵鶴齖齒齭鸻鹀鷹鼚鼔齜齙鷸鷶龨黿齱齰齭鷺鶵鶴齖齒鸂麇鶨齖齒齭鶧鶣龨龃麸鹾齜鶟鸻鹀鷘鷔鷵鷱鶵鶴齖齒鸂麇鶨鹆齖齒黩龃鶞麔齐麲黝鷸鷶龵龱齐鼐鼌鶰鷒龨鶚鶙龵龱鸙

龯龬鶘鶔鶓鼮麝齥鶯鹘鶬齪齨鶒齖齒龃鸪齖齒鷵鷱鶐鷱龵龱龃麇麅龶龯龬齄鶌鶉鶅齭鸇鶂齪齨鶒齖齒龃鵿鹇齰鸻鶯鵻鵷鵳龵龱龋龇齷齴龃鵱鵰鵬鵫鵨黦龃鸪齖齒鸻鹀鵥鵳龵龱鷸鷶龃鶞麔齐鵥鵳齜齙鷸鷶龃鵣鹚龯龬麔齐鷱黢鹾鵡鵟齪齨鶒龃齱鵝麲鵜鵛齜鶟龃麸鵗鷸鷶鼶鹾齖齒齥龃齰鵖鷱鵓鶅鷸鷶麇鶨齖齒龒龃龶麅鵑鹅鹂龞鵐鼔鼶鹾齖齒龵龱鵏麮鹘鵍鸻鶅鼚鼶麴龨齜鶟鵻鶸鶷鵌鵈鶘鸧鵇鵃龃鵀鷔鼚鷔鸄鼚鴾鴺龨齜鶟龃鴹鸄鷹鴶鶟龃鴲鴱齱齭鷱龱龨鸙

鴭齐龤鷁鹾鷆鷄齖齒鴪龃鶐鷱鶸鶷龨齜鶟鴧鸸鼔鹩鶸鶷齖齒龃鴤鹎鷸鷶鴣鸻麔鴠鴜龃鸄鼚鸪齖齒麔齐麲鹩鶸鶷鼚齙鷶鴙鼖鹇龨龵龱龃黝鸂鶵鶴齖齒齘齪齨鶒齖齒齭龯龬鶘鶔齥鶚鶙鹘鶬龨鴖麮齖齒鸙

鹭黐龵龱麾鼐鼌鹀鴓鼓鼒鹆鴒鹢鼫

齱麔齐鷺齭鹭黐龵龱麾鴏鴋鹀鴓鵥龎鹆鹾鴇鵐龃鼶齭龶鴇鵐鴄鴃鼲鹢麧鴙龵龱龋龇鴂麾麅黠龨黿鴁龤龢黩鼫

鼚齙龵龱龋龇鴂access_check.permission鼫

龋龇鳱鳮鼫 _permission龃鳫鳩鼫access龃鳧鳤鳡鳞麂鶫

鶿鼫Drupal\user\Access\PermissionAccessCheck

龋龇鳱鳮龨鳘黟鸫鼚齙龵龱龃齜齙麂鶫鳔鳐鴹麔鵥龎龃鳍鳋鳈鳄龃黢鹾龵龱鸄鼚鷸鳀鸛鷸鲿龃鷸鳀鸛鲽+鲻鸫鸏OR鷾龯龃鲽龃鲻鸫鸏AND鷾龯龃鼶鷁鸖鷸鳀鸛鸻麔麸鲸鸄鼚龃鹟鹝鴏鴋麔齐鸄鼚鴤鴄鴃鵫鲶龋龇鴂麾鲴鸙

OR鸂AND鸻鹀麸鲸鸄鼚麲鲱鲯鲮鲬龵龱鲫齭鲨鲯麾龨鲮鲬黔鲦鴏鴋鼚齙齭鴓鸇鶂鹆龵龱鲬黂鲢鼶鸎鼒鹸麾齞齞drupal齭鲨鲯麅黠龨鸙

鼚齙龵龱鴏鴋鼫

鴏鴋鼚齙齭鴓鸇鶂鹆龵龱齭鼺鼚齙齜齙麂鶫龞鲡鲝龨龃鶚鶙齜齙麂鶫麲鼫

Drupal\Core\Session\UserSession

龶龤龢龞鹩鹦鷺鲕龒黝齭黔鲦鶓鼮麝龃齐齍黔鲦龶龯龬龞鲑鴠龃麅鲎麝齜齙麂鶫齭龶鼫

Drupal\user\Authentication\Provider\Cookie龨getUserFromSession(SessionInterface $session)鳫鳩龞

麔齐齞鹗鸄鼚龒鷁鱽鱺鱹鱵鸫鼫

users_field_data鼫鱲鱮鼚齙龨鼖鹇鱬鱫

user__roles鼫鱲鱮鼚齙龨齖齒鱬鱫龃鷘麸鹾鼚齙鷱黢鱨鹾齖齒鱥鲯龶鸪鸫龞齰鶯鷱黢鱨鱣鱠鶷黿鶵鶴齖齒鸂鹩鱞鱝齖齒鸻鶯鱮鱚黩龃鱖鼚齙鱮龶鴣鵖鷱鷹鱔鼚龨麚鹜龁龃鶯龇鱐鸪鸫龃齿齖齒鱏鱎鸌鱍齝鼖鹇鱬鱫鱺鷣龞龃麸鲸黙鱋齜齙麂鶫龃鼶鼲鳤鶅鱞鱈鱅鱃鷱鸎鸜鱂龶齜齙麂鶫龞鵖鷱鸸鸶鰿鲕龃鶞鰻鱃鶯鷹鱞龎龃鹖黔鼫

$user = \Drupal::currentUser()->getAccount();

echo $user->pass;

麾齞麸齞鼶鷁鹾鸫龨麧麤鼫

users_field_data鸫鼫

uid鼫鼚齙id,鰬鰪麲10龨鰨麪龃麔齐齞鹗鹀鱞鱝鰦鰤鵟鰡鱺鰞龨鼚齙

langcode鼫鰛鰘黟鸳龃鹖黔龞鰗麲zh-hans,鰒鰗麲en

preferred_langcode鼫鰐鰏鰛鰘龨鰛鰘黟鸳

preferred_admin_langcode鼫齪齨鰎鹢龞鰐鰏鰛鰘龨鰛鰘黟鸳

name鼫鼚齙鶴龃鰬鰪麲60鰒鰗鸜鸛龃麲齜齙鶴龃鰌鸻齭龶鴒鹢龞鰉鸏龨鰅鵝

pass鼫鰃鰀鯽齨龨鯻鸳hash龃鰬鰪麔齐麲255鰒鰗鸜鸛

mail鼫鼚齙鯱鯭

timezone鼫鼚齙鷔鯫鳱鳮鸛

status鼫鼚齙鯩鹊龃鼚齐鸫鸏鼚齙齭鴓鷹鯥鯣鱔鼚龃1麲鯠鹪龃0麲鱔鼚

created鼫齜齙鯝鹘鷔鯜龃unix鷔鯜鯗鯓黈

changed鼫齜齙鯒鯑鷔鯜

access鼫齜齙鯏齥麸鯌鼓鼒龨鷔鯜

login鼫鼚齙鯏齥鶸鶷龨鷔鯜

init鼫鯝鹘齜鶟鷔鸄鼚龨鼚齙鯱鯭

default_langcode鼫鶚鶙鰛鰘黟鸳

鼚齙龶齪齨齥齡鯊鰃龨齜齙鯆鯄鸜鱂鸻鶯鱮鱚龶鸪鸫龞龃鰌齭鯂鹾鸜鱂鴧鯀鶬鮼鮺麸鱽鱺鱹鱵鸫

user__roles鸫鼫

bundle鼫鱺鱹鸸鼔鮴鹾鮲鮰

deleted鼫鸫鲕鱺鱹齭鴓鹩鹦鷹鮬鴭龃bool鳘

entity_id鼫鱺鱹鶐鸸龨麅鸅id龃齱齰齭uid

revision_id鼫鱺鱹鶐鸸麅鸅鮧鹇龃麂鼔鼚齙齜齙麅鸅麾鷺鸻鱮龶麅鸅鮧鹇龃黝鸂麅鸅id麸麴

langcode鼫鰛鰘黟鸳

delta鼫黢鳘鷔鮤鮡鸄鼚

roles_target_id鼫鮝鳱麅鸅龨id龃齖齒麇麅齭麸鹾麅鸅

鮙麔鹀鹩鹦鱈鳮齝龒齖齒鶐鸇鶂龨龵龱鱏鱎鱍鵖鷱鱮鱚龶鼶鷁鸫龞龃麅鵑龤黝鵐鷶鴙龯龬鸂麅鸅龯龬麾鮗鮓鮑鱮鸂麺鹱鸄鼚鵰鮍龃鵐鼔鼶鷁鹾龯龬齉齍齄齃黚黢龃龶龯龬龞鯽鼔麜鮊鶅龨鷌鴙龃鸻鮈鸄鼚龶龵龱龯龬龞龃鮇鸄鼚龶鰡龨鮄鳫龃鶐齐鹇龯鮁齿鷸鰡魿鯀魽麌龃鼶鼲魻鷔鮈麺鹱鸄鼚龨鵰鮍龃鸻鵓鹽龎龒麌鸇鸅龗魸鸙

龶鼚齙齜齙麂鶫龞鷱鷁鹾鸂龵龱黛鷾龨鳫鳩龃齭龵龱龯龬麺鹱龨鼰魶鵰鮍龃麔齐鹱齀鼼麾鵥鵳龵龱鴏鴋鼫

鲑鴠鼚齙鸇鶂龨齖齒鼫

public function getRoles($exclude_locked_roles = FALSE)

龶鼐鼌鴂龞龨鸄鼚鳫鳩鼫\Drupal::currentUser()->getRoles($exclude_locked_roles = FALSE);

鲡齝鼚齙鶐鸸龨齖齒龃鵬鵫麸鹾鱺鷣龃龯龬鷱鷁鹾鷆鷄齖齒鼫鶵鶴齖齒齘鹩鱞鱝鼚齙齖齒龃魲鱺麲true鷔鮤鴭鼶鷁鹾鷆鷄齖齒

鴏鴋鼚齙齭鴓鸇鶂鹆龵龱鼫

public function hasPermission($permission)

龶鼐鼌鴂龞龨鸄鼚鳫鳩鼫\Drupal::currentUser()->hasPermission($permission);

鵬鵫bool龃鸫鲕鼚齙齭鴓鷱鹆龵龱龃uid麲1龨鼚齙齜齙麲龯龬鵜鵛齜齙龃龶龯龬鶘鶔鷔麧鴙龃黝鷵鷱鶐鷱龵龱

魱魯鼫

鱖鹆齜齙鷘鷔鸇鶂鷁鹾齖齒龃鶞齖齒鴄鴃龨龵龱黛魮魭龃龯龬鲨鲯鯽齨鲬鹖黔魩麂鹆龵龱麸鹾齖齒鵨黦龃魧鴪麸鹾鸻鵨黦鸙

鼶鶉齭鹾龵龱鷱鳧龨鼒鹸龃鷱龵龱齰鵨黦龃鳍鳋鸻鵨黦龃鶉鶅鸇鶂龨齖齒龞鷱麸鹾齖齒鷱龵龱龃魣魡齰鷱龵龱龃龶鹚鳫鳩龞麔齐齞鹗麾鼫Drupal\user\RoleStorage:: isPermissionInRoles($permission, array $rids).

鹇龢齰龖龓齝鼶鼲龃魠齝鷶鴙龯龬鸂麅鸅龯龬龖龓魜魛龃齿麂鶐鷱龗魸鸧鱃龒麌鸙

API魗鳫魲魯鼫

https://api.drupal.org/api/drupal/core%21core.api.php/group/user_api/8.3.x

本书共71小节:

评论 (写第一个评论)