Skip to main content

Control information access with XACML

The objectives, architecture, and basic concepts of eXtensible Access Control Markup Language

Return to article


Listing 5. Creating a PEP
public static void main(String[] args) throws Exception {
  // Create the new request.
  // Environment hashset is empty
  RequestCtx request =
      new RequestCtx(
          setupSubjects(),
          setupResource(),
          setupAction(),
          new HashSet());

  // Encode the request and print it to standard out
  request.encode(System.out, new Indenter());
}


public static Set setupSubjects() throws URISyntaxException {
  HashSet attributes = new HashSet();

  // Set up the ID and value for the requesting subject
  URI subjectId = new
  URI("urn:oasis:names:tc:xacml:1.0:subject:subject-id");
  RFC822NameAttribute value = new RFC822NameAttribute("mverma@secf.com");

  // Create the subject section with two attributes, the first with
  // the subject's identity...
  attributes.add(new Attribute(subjectId, null, null, value));
  // ...and the second with the subject's group membership

  URI groupId = new URI("group");
  StringAttribute stringAttribValue = new StringAttribute("owner");

  attributes.add(new Attribute(groupId,null,null,stringAttribValue));

  // Bundle the attributes in a subject with the default category
  HashSet subjects = new HashSet();
  subjects.add(new Subject(attributes));

  return subjects;
}

public static Set setupResource() throws URISyntaxException {
  HashSet resource = new HashSet();

  // The resource being requested
  AnyURIAttribute value =
      new AnyURIAttribute(new URI("file:///D:/Documents/Administrator/Desktop/Project Plan.html"));

  // Create the resource using a standard, required identifier for
  // the resource being requested
  resource.add(
      new Attribute(
          new URI(EvaluationCtx.RESOURCE_ID),
          null,
          null,
          value));

  return resource;
}
public static Set setupAction() throws URISyntaxException {
  HashSet action = new HashSet();

  // This is a standard URI that can optionally be used to specify
  // the action being requested
  URI actionId = new URI("urn:oasis:names:tc:xacml:1.0:action:action-id");

  // Create the action
  action.add(
      new Attribute(actionId, null, null, new StringAttribute("open")));

  return action;
}

Return to article