AlgoMaster Logo
AlgoMasterImplement a Secure Report Proxyeasy

Implement a Secure Report Proxy

easy

A report service can answer every request, but an application may need to restrict who is allowed to reach it. A protection proxy exposes the same operation, checks the caller's current role, and delegates only approved requests.

The starter code already provides:

  • ReportService, the contract shared by the proxy and the backend.
  • RealReportService, which returns report data and counts every call it receives.
  • ProxyDriver, the public test harness that creates and forwards calls to your proxy.

Your task is to implement only SecureReportProxy.

SecureReportProxy behaves as follows:

  • SecureReportProxy(String role) creates a proxy with that current role and a fresh real service.
  • String viewReport(String name) delegates and returns "Report data: <name>" when the role is admin or analyst.
  • Every other role is denied. A denied view returns "ACCESS DENIED" without calling the real service.
  • boolean setRole(String role) changes the role and returns true, or returns false when it was already current.
  • String role() returns the current role.
  • int serviceCallCount() returns how many allowed views reached the real service.
  • int deniedCount() returns how many views the proxy refused.
  • String lastDecision() returns "NONE" before the first view, then "ALLOWED: <name>" or "DENIED: <name>" for the latest one.

Changing roles does not reset the counters or the last decision. Do not modify the provided backend, and never call it for a denied request. The examples use ProxyDriver operations because it is the public test harness; your code changes belong only inside SecureReportProxy.

Example 0:

Input:

Output:

Explanation: A guest is not allowed to view reports. The proxy refuses the request before delegation, so the backend call count remains zero.

Example 1:

Input:

Output:

Explanation: After the role changes to analyst, both requests pass through the proxy to the real service. The last decision records the most recent report.

Constraints

  • 1 <= role.length <= 20
  • 1 <= name.length <= 40
  • Roles and report names contain letters, digits, spaces, underscores, and hyphens only.
  • At most 100 calls are made across all methods.

Starter Code

Only SecureReportProxy is unfinished. The supporting types and ProxyDriver test harness are pre-implemented; do not modify them.

How the design is graded

needs 7/10 to pass
  • Proxy and backend share one contract

    Full marks when SecureReportProxy and RealReportService implement ReportService and allowed reports are produced by delegating through that interface. Lose points heavily when the proxy constructs report data itself or does not wrap the supplied backend.

  • Denied requests reach nothing

    Full marks when every role except admin and analyst receives ACCESS DENIED before the backend is called, so serviceCallCount is unchanged and deniedCount rises once. Lose points when access is checked after delegation.

  • Role and decision state are accurate

    Full marks when setRole reports whether the role changed, role returns the current role, lastDecision starts as NONE and records ALLOWED: <name> or DENIED: <name> for the latest view, and methods return values rather than printing. Lose points when changing roles resets counters or decisions.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new ProxyDriver("guest")null
viewReport("Q1")"ACCESS DENIED"
serviceCallCount()0
deniedCount()1
lastDecision()"DENIED: Q1"
role()"guest"

A guest is not allowed to view reports. The proxy refuses the request before delegation, so the backend call count remains zero.

Run checks these cases. Submit also runs a larger hidden set.