use of won.auth.linkeddata.AuthEnabledLinkedDataSource in project webofneeds by researchstudio-sat.
the class AclTests method testImplicitOwnerToken.
@Test(timeout = 60 * 1000)
public void testImplicitOwnerToken() throws Exception {
runTest(ctx -> {
EventBus bus = ctx.getEventBus();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final String atomUriString = atomUri.toString();
final AtomContent atomContent = AtomContent.builder(atomUri).addTitle("Unit test for implicit owner token").addSocket(Socket.builder(atomUriString + "#holderSocket").setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).addSocket(Socket.builder(atomUriString + "#buddySocket").setSocketDefinition(WXBUDDY.BuddySocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
// create an acl allowing only the atom itself to read everything
Authorization auth = Authorization.builder().addGrant(ase -> ase.addOperationsSimpleOperationExpression(OP_READ)).addGranteesAtomExpression(ae -> ae.addAtomsURI(URI.create("https://example.com/nobody"))).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(// add the acl graph
won.auth.model.RdfOutput.toGraph(auth)).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri);
final String action = "Create Atom action";
EventListener successCallback = event -> {
URI connContainerUri = uriService.createConnectionContainerURIForAtom(atomUri);
URI createMessageUri = ((SuccessResponseEvent) event).getOriginalMessageURI();
boolean passed = true;
URI tokenQuery = uriService.createTokenRequestURIForAtomURIWithScopes(atomUri, WONAUTH.OwnerToken.toString());
passed = testTokenRequest(ctx, bus, null, false, atomUri, null, tokenQuery, "test1.1 - obtain token");
Set<String> tokens = ((AuthEnabledLinkedDataSource) ctx.getLinkedDataSource()).getAuthTokens(tokenQuery, atomUri);
String token = tokens.stream().findFirst().get();
passed = passed && testTokenRequest(ctx, bus, null, true, null, token, tokenQuery, "test1.2 - request token using only token");
passed = passed && testLinkedDataRequest(ctx, bus, null, false, null, null, atomUri, "test1.3 - request atom data without any auth (continues session with token)");
passed = passed && testLinkedDataRequest(ctx, bus, null, true, atomUri, null, atomUri, "test1.4 - request atom data with webid");
passed = passed && testLinkedDataRequest(ctx, bus, null, true, null, token, atomUri, "test1.5 - request atom data with token");
if (passed) {
passTest(bus);
}
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
});
}
Aggregations