Question: Language: Java - Just need some help starting it out. Purpose: To implement an authorization system using access control matrix. Instructions: - Access control matrix:

Language: Java

- Just need some help starting it out.

Purpose:

To implement an authorization system using access control matrix.

Instructions:

- Access control matrix: For this task, you will implement a simple security program using access control matrix. You will load a plain text file with the following format.

alice, bob, carol, eve

top-secret, secret, public

rw,

r, rw, rw

, r, rw

, , r

- The first two lines are comma-separated lists of subjects and objects respectiviely. The subsequent lines are access control matrix, where each cell is a string that contains read and/or write permissions. The matrix has the following meaning,

top-secret secret public

alice rw

bob r rw rw

carol r rw

eve r

- where r means readable, w means writable, and rw means both readable and writable. The absence of an entry means neither readable nor writable. For example, given this matrix, alice can read or write top-secret files but she cant read or write secret or public files.

__________________________________________________________________________________________

CODE:

import java.io.FileReader;

import java.util.Arrays;

import java.util.Scanner;

/*

* Load an access control matrix from a file

* First line: subjects

* Second line: objects

* Subsequent lines: access control matrix (comma separated)

* e.g

*

* alice, bob, carol, eve

* top-secret, secret, public

* rw,

* r, rw, rw

* , r, rw

* , , r

*/

public class AccessControl {

// Define any fields or methods as necessary.

// load access control matrix from a file by the name of "fileName"

void load(String fileName) {

// The name of the file is ac_matrix

//Should use Scanner in = new Scanner(new FileReader(fileName));

}

public String toString() {

// This should return a string representation of the access control matrix(ac_matrix)

// This format is shown above

}

boolean check(String subj, String op, String obj) {

// returns true if and only if subj can perform operation op on obj according to the //access control matrix

}

// Driver method

public static void main(String[] args) {

AccessControl ac = new AccessControl();

ac.load("ac_matrix");

System.out.println(ac);

Scanner in = new Scanner(System.in);

System.out.println("Enter your command (e.g. alice r secret):");

String cmd = in.nextLine().trim();

while(!cmd.equals("")) {

String[] triple = cmd.split(" ");

if(triple.length != 3) {

System.out.println("Illegal command. Try again");

}

else {

String subj = triple[0], op = triple[1], obj = triple[2];

try {

if(ac.check(subj, op, obj)) {

System.out.printf("%s is allowed to perform %s operation on %s ", subj, op, obj);

}

else {

System.out.printf("%s is NOT allowed to perform %s operation on %s ", subj, op, obj);

}

} catch(Exception e) { System.out.println(e); }

}

System.out.println(" Enter your command");

cmd = in.nextLine().trim();

}

in.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!