Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import "fmt"
type User struct {
Name string
Role string
Department string
}
func checkAccess(user User, resource string) bool {
// RBAC: Role based rule
if user.Role == "admin" {
return true
}
// ABAC: Attribute based rule
if user.Department == "finance" && resource == "reports" {
return true
}
// Policy based authorization
return false
}
func main() {
user := User{
Name: "Alice",
Role: "manager",
Department: "finance",
}
allowed := checkAccess(user, "reports")
fmt.Println("Access granted:", allowed)
}Coding works best on desktop or with an external keyboard.