Filter
Filter
filter: `({ action, params, context, util }) => {
if (action === "player.remove") {
return context.user.player.isAdmin && context.user.player.id != params.id;
} else if (action === "player.create") {
return context.user && (!context.user.player || context.user.player.isAdmin);
}
return true;
}`,
},
๋ค์์ผ๋ก filter
์ ๊ทผ ์ ์ด ํ๋ฌ๊ทธ์ธ์ ๋ฐ๋ผ action
|event
, params
, context
, util
์ ์ฃผ์
ํ์ฌ ํจ์๋ฅผ ์คํํ๋ฉฐ, true
๊ฐ์ด ๋ฐํ๋๋ ๊ฒฝ์ฐ ํต๊ณผํฉ๋๋ค. FBAC์ ACL์ด๋ RBAC์ฒ๋ผ ๋์คํ๋์ง๋ ์์์ผ๋, ABAC์ ํ์ฅ ๋ชจ๋ธ๋ก ์ดํดํ ์ ์์ต๋๋ค. ๋งค์ฐ ์ ์ฐํ์ฌ ๋ถ์ฐ ํ๊ฒฝ์ ์ ํฉํ๋ฉฐ ํ๋ก๋์
์์ ๊ฒ์ฆ๋ ๋ฐฉ์์
๋๋ค.
filter
์ ๊ทผ์ ์ด ํ๋ฌ๊ทธ์ธ ์ญ์ map
์ปค๋ฅํฐ์ฒ๋ผ Gateway์ Node.js VM ์๋๋ฐ์ค์์ ์คํ๋ฉ๋๋ค. filter
ํจ์๋ฅผ ํ๊ฐํ๋ ์ค์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ ๋๋ฒ๊ทธ ๋ฉ์์ง๊ฐ Gateway์์ ์ถ์ฒ ๋
ธ๋๋ก ์ ๋ฌ๋๋ฉฐ ์ ๊ทผ์ด ๊ฑฐ๋ถ๋ฉ๋๋ค.
{
description: "player can get associated team, admin can get all the teams",
actions: ["team.get"],
scopes: ["player", "player.admin"],
filter: (({ action, params, context, util }) => {
if (context.user.player.isAdmin || params.id === context.user.player.teamId) {
return true;
}
return false;
}).toString(),
},
],
์์ฒ๋ผ player
์๋น์ค์ API ์คํค๋ง๋ ๊ผญ player
์๋น์ค์ ์ก์
๋ง ํธ์ถํ์ง ์์ต๋๋ค. ๋ฐ๋ผ์ player
API์์ ๋
ธ์ถํ๋ team
์๋น์ค์ ์ก์
์ ๋ํ ์ ๊ทผ ์ ์ด ์ญ์ player
์คํค๋ง์์ ์ ์ํ๊ฒ ๋ฉ๋๋ค.
publish: [
{
description: "Only admins can publish player events",
events: ["player.**"],
scopes: ["player"],
filter: (({ event, params, context, util }) => {
return context.user.player.isAdmin;
}).toString(),
},
],
publish
, subscribe
์ปค๋ฅํฐ์ ์ ์ฑ
์๋ actions
๋์ events
ํ๋๊ฐ ์์ฑ๋ฉ๋๋ค.
subscribe: [
{
events: ["player.**"],
description: "Any user can receive player events",
scopes: ["openid"],
},
],
},
}
์์ฒ๋ผ filter
๊ฐ ์๋ต๋ ๊ฒฝ์ฐ scopes
๋ง ์ ์ฉ๋๋ฉฐ filter
๋ ํต๊ณผํ ๊ฒ์ฒ๋ผ ํ๊ฐ๋ฉ๋๋ค.
{
actions: ["**"],
scopes: ["**"],
filter: `() => true`,
}
์ ๊ทผ์ ์ด ํ๋ฌ๊ทธ์ธ์ ๋นํ์ฑํํ๋ ๊ฒ์ ์ ์ ์ฑ ์ ์์ฑํ๋ ๊ฒ๊ณผ ๋์ผํฉ๋๋ค.
{
actions: ["**"],
scopes: ["**"],
filter: `(action, params, context) => {
console.log("policy filter", action, params, context);
}`,
}
๋๋ฒ๊น
์ค์ Inline JavaScript Function String์์ console
๊ฐ์ฒด๋ฅผ ์ฌ์ฉํด ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ ๊ฒฝ์ฐ, ๊ทธ ๋ฉ์ธ์ง๋ Gateway์ VM ์์์ ์ถ๋ ฅ๋์ง ์๊ณ Gateway๊ฐ ์ถ์ฒ ๋
ธ๋๋ก ์ ๋ฌํฉ๋๋ค.
Last updated
Was this helpful?