THINK FIRST·CODE LATER

← All labs

Access matrix: ACLs and capability lists

Problem

Maintain an access matrix (domains × objects; rights are single letters, o = owner).

Commands:

  • create D O — domain D creates object O and gets rights o, r, w. Print D creates O (owner).
  • grant BY TO O rights — only a domain with o on O may grant: print BY grants rights on O to TO, or DENIED: BY is not owner of O.
  • revoke BY FROM O rights — same ownership rule: BY revokes rights on O from FROM.
  • check D O r — print check D r O: ALLOWED or DENIED.

At the end print Capability lists: with one line per domain (alphabetical) bob -> data:orw, report:r (objects alphabetical, rights sorted, empty cells omitted, none if empty), then Access control lists: with one line per object (alphabetical) report -> alice:orw, bob:r.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os14-2-data-1.txt

create alice report
create bob data
grant alice bob report r
grant bob carol report r
check bob report r
check bob report w
grant bob alice data rw
revoke alice bob report r
check bob report r
check alice data w
What your program must print for os14-2-data-1.txt
alice creates report (owner)
bob creates data (owner)
alice grants r on report to bob
DENIED: bob is not owner of report
check bob r report: ALLOWED
check bob w report: DENIED
bob grants rw on data to alice
alice revokes r on report from bob
check bob r report: DENIED
check alice w data: ALLOWED
Capability lists:
  alice -> data:rw, report:orw
  bob -> data:orw
Access control lists:
  data -> alice:rw, bob:orw
  report -> alice:orw

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os14-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os14-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.