Model model = ModelFactory.createDefaultModel();
URL url = SecurityExample.class.getClassLoader().getResource(
"org/apache/jena/security/example/example.ttl");
model.read(url.toExternalForm());
ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
System.out.println("All the messages");
while (ri.hasNext()) {
Resource msg = ri.next();
Statement to = msg.getProperty(pTo);
Statement from = msg.getProperty(pFrom);
Statement subj = msg.getProperty(pSubj);
System.out.println(String.format("%s to: %s from: %s subj: %s",
msg, to.getObject(), from.getObject(), subj.getObject()));
}
System.out.println();
ExampleEvaluator evaluator = new ExampleEvaluator(model);
model = Factory.getInstance(evaluator,
"http://example.com/SecuredModel", model);
for (String userName : names) {
evaluator.setPrincipal(userName);
System.out.println("Messages " + userName + " can manipulate");
ri = model.listSubjectsWithProperty(RDF.type, msgType);
while (ri.hasNext()) {
Resource msg = ri.next();
Statement to = msg.getProperty(pTo);
Statement from = msg.getProperty(pFrom);
Statement subj = msg.getProperty(pSubj);
System.out.println(String.format(
"%s to: %s from: %s subj: %s", msg, to.getObject(),
from.getObject(), subj.getObject()));
}
ri.close();
for (String name : names)
{
System.out.println( String.format( "%s messages to %s", model.listSubjectsWithProperty( pTo, name ).toList().size(), name ) );
}
System.out.println();