Multi-level access verification system with interfaces
Go
Hard
interfaces
Task «Multi-level access verification system with interfaces»
Implement a resource access checking system using interfaces. Define an AccessChecker interface with methods CheckAccess(resource string, user string) bool and GetPermissions(resource string) []string. Implement three structures: AdminAccess (always returns true and a list of all permissions containing 'admin'), UserAccess (checks if the user is in the list of allowed users for the resource and returns permissions starting with 'user_'), GuestAccess (checks if the resource is in the list of public resources and returns the 'read' permission if accessible). Then implement a function CreateAccessChecker(accessType string, config map[string]interface{}) (AccessChecker, error), which creates the corresponding object based on the accessType string ('admin', 'user', 'guest') and configuration. Input: first an integer N (1..100) — the number of requests. Then N lines of the form: accessType resource user. After that, a line with configuration: for admin — an empty string; for user — a string of the form 'resource1:user1,user2;resource2:user3'; for guest — a string of the form 'resource1;resource2'. For each request, output 'allowed' or 'denied'. If the accessType is unknown, output 'unknown type'.
Input Format
N (integer)
N lines: accessType resource user
configuration string
Output Format
N lines: 'allowed' or 'denied' or 'unknown type'
Examples
Example 1
INPUT
3
admin secret admin
user docs alice
guest public bob
OUTPUT
allowed
denied
denied
Example 2
INPUT
2
admin vault eve
user reports john
resource1:alice,bob;resource2:charlie
OUTPUT
allowed
denied
Example 3
INPUT
1 2 3 4 5
6 7 8 9 10
OUTPUT
unknown type
Example 4
INPUT
1
superuser root root
OUTPUT
unknown type
Example 5
INPUT
-1 2 3 -4 5
6 -7 8 -9 10
OUTPUT
unknown type
main.go