public static XDIAddress getOwnerXDIAddress(Graph graph) { XDIArc ownerPeerRootXDIArc = getOwnerPeerRootXDIArc(graph); if (ownerPeerRootXDIArc == null) return null; return XdiPeerRoot.getXDIAddressOfPeerRootXDIArc(ownerPeerRootXDIArc); }
@Override public XDIAddress getOwnerXDIAddress() { return GraphUtil.getOwnerXDIAddress(this.getGraph()); }
@Override public boolean ownsPeerRootXDIArc(XDIArc peerRootXDIArc) { return GraphUtil.ownsPeerRootXDIArc(this.getGraph(), peerRootXDIArc); }
@Override public SecretKey getSecretKey(XDIAddress signerXDIAddress) throws GeneralSecurityException { // signer address if (signerXDIAddress == null) { signerXDIAddress = GraphUtil.getOwnerXDIAddress(this.getSecretKeyGraph()); } // signer entity XdiEntity signerXdiEntity = XdiCommonRoot.findCommonRoot(this.getSecretKeyGraph()).getXdiEntity(signerXDIAddress, false); signerXdiEntity = signerXdiEntity == null ? null : signerXdiEntity.dereference(); if (log.isDebugEnabled()) log.debug("Signer entity: " + signerXdiEntity + " in graph " + GraphUtil.getOwnerPeerRootXDIArc(this.getSecretKeyGraph())); if (signerXdiEntity == null) return null; // find secret key SecretKey secretKey = aesSecretKeyFromSecretKeyString(Keys.getSecretKey(signerXdiEntity)); // done return secretKey; }
public void testPublicLinkContract() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); GraphUtil.setOwnerXDIAddress(graph, XDIAddress.create("=markus")); assertEquals(GraphUtil.getOwnerXDIAddress(graph), XDIAddress.create("=markus")); PublicLinkContract l = PublicLinkContract.findPublicLinkContract(graph, true); assertNotNull(l); assertEquals(l.getXdiEntity().getXDIAddress(), XDIAddress.create("(=markus/$public)$contract")); assertNotNull(PublicLinkContract.findPublicLinkContract(graph, false)); assertTrue(LinkContract.fromXdiEntity(l.getXdiEntity()) instanceof PublicLinkContract); assertEquals(l.getRequestingAuthority(), XDILinkContractConstants.XDI_ADD_PUBLIC); assertEquals(l.getAuthorizingAuthority(), XDIAddress.create("=markus")); assertNull(l.getTemplateAuthorityAndId()); graph.close(); }
public static XdiSubGraph<?> fromXDIAddress(XDIAddress XDIaddress) { return fromContextNode(GraphUtil.contextNodeFromComponents(XDIaddress)); } }
@Override public void setOwnerXDIAddress(XDIAddress ownerXDIAddress) { GraphUtil.setOwnerXDIAddress(this.getGraph(), ownerXDIAddress); }
@Override public List<Relation> replaceRelation(Relation relation) { XDIAddress contextNodeXDIAddress = relation.getContextNode().getXDIAddress(); XDIAddress XDIaddress = relation.getXDIAddress(); XDIAddress targetXDIAddress = relation.getTargetXDIAddress(); XDIAddress replacedContextNodeXDIAddress = replaceXDIAddress(contextNodeXDIAddress); XDIAddress replacedTargetXDIAddress = replaceXDIAddress(targetXDIAddress); if (log.isTraceEnabled()) log.trace("Replaced " + contextNodeXDIAddress + " with " + replacedContextNodeXDIAddress); if (log.isTraceEnabled()) log.trace("Replaced " + targetXDIAddress + " with " + replacedTargetXDIAddress); Relation replacedRelation = GraphUtil.relationFromComponents(replacedContextNodeXDIAddress, XDIaddress, replacedTargetXDIAddress); return Collections.singletonList(replacedRelation); }
/** * Return the relative inner graph of this XDI inner root. * @return The relative inner graph. */ public Graph getInnerGraph() { return GraphUtil.relativeGraph(this.getContextNode()); }
@Override public SecretKey getSecretKey(XDIAddress signerXDIAddress) throws GeneralSecurityException { // signer address if (signerXDIAddress == null) { signerXDIAddress = GraphUtil.getOwnerXDIAddress(this.getSecretKeyGraph()); } // signer entity XdiEntity signerXdiEntity = XdiCommonRoot.findCommonRoot(this.getSecretKeyGraph()).getXdiEntity(signerXDIAddress, false); signerXdiEntity = signerXdiEntity == null ? null : signerXdiEntity.dereference(); if (log.isDebugEnabled()) log.debug("Signer entity: " + signerXdiEntity + " in graph " + GraphUtil.getOwnerPeerRootXDIArc(this.getSecretKeyGraph())); if (signerXdiEntity == null) return null; // find secret key SecretKey secretKey = aesSecretKeyFromSecretKeyString(Keys.getSecretKey(signerXdiEntity)); // done return secretKey; }
public void testConnectLinkContract() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); GraphUtil.setOwnerXDIAddress(graph, XDIAddress.create("=markus")); assertEquals(GraphUtil.getOwnerXDIAddress(graph), XDIAddress.create("=markus")); ConnectLinkContract l = ConnectLinkContract.findConnectLinkContract(graph, true); assertNotNull(l); assertEquals(l.getXdiEntity().getXDIAddress(), XDIAddress.create("(=markus/$connect)$contract")); assertNotNull(ConnectLinkContract.findConnectLinkContract(graph, false)); assertTrue(LinkContract.fromXdiEntity(l.getXdiEntity()) instanceof ConnectLinkContract); assertEquals(l.getRequestingAuthority(), XDILinkContractConstants.XDI_ADD_CONNECT); assertEquals(l.getAuthorizingAuthority(), XDIAddress.create("=markus")); assertNull(l.getTemplateAuthorityAndId()); graph.close(); }
public static XdiCommonVariable fromXDIAddress(XDIAddress XDIaddress) { return fromContextNode(GraphUtil.contextNodeFromComponents(XDIaddress)); } }
public static void setOwnerPeerRootXDIArc(Graph graph, XDIArc ownerPeerRootXDIArc) { XDIAddress ownerXDIAddress = XdiPeerRoot.getXDIAddressOfPeerRootXDIArc(ownerPeerRootXDIArc); setOwnerXDIAddress(graph, ownerXDIAddress); }
Relation replacedRelation = GraphUtil.relationFromComponents(contextNodeXDIAddress, XDIaddress, replacedTargetXDIAddress);
@Override public RSAPrivateKey getPrivateKey(XDIAddress signerXDIAddress) throws GeneralSecurityException { // signer address if (signerXDIAddress == null) { signerXDIAddress = GraphUtil.getOwnerXDIAddress(this.getPrivateKeyGraph()); } // signer entity XdiEntity signerXdiEntity = XdiCommonRoot.findCommonRoot(this.getPrivateKeyGraph()).getXdiEntity(signerXDIAddress, false); signerXdiEntity = signerXdiEntity == null ? null : signerXdiEntity.dereference(); if (log.isDebugEnabled()) log.debug("Signer entity: " + signerXdiEntity + " in graph " + GraphUtil.getOwnerPeerRootXDIArc(this.getPrivateKeyGraph())); if (signerXdiEntity == null) return null; // find private key RSAPrivateKey privateKey = rsaPrivateKeyFromPrivateKeyString(Keys.getSignaturePrivateKey(signerXdiEntity)); // done return privateKey; }
public void testRootLinkContract() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); GraphUtil.setOwnerXDIAddress(graph, XDIAddress.create("=markus")); assertEquals(GraphUtil.getOwnerXDIAddress(graph), XDIAddress.create("=markus")); RootLinkContract l = RootLinkContract.findRootLinkContract(graph, true); assertNotNull(l); assertEquals(l.getXdiEntity().getXDIAddress(), XDIAddress.create("(=markus/=markus)$contract")); assertNotNull(RootLinkContract.findRootLinkContract(graph, false)); assertTrue(LinkContract.fromXdiEntity(l.getXdiEntity()) instanceof RootLinkContract); assertEquals(l.getRequestingAuthority(), XDIAddress.create("=markus")); assertEquals(l.getAuthorizingAuthority(), XDIAddress.create("=markus")); assertNull(l.getTemplateAuthorityAndId()); graph.close(); }
@Override public XDIArc getOwnerPeerRootXDIArc() { return GraphUtil.getOwnerPeerRootXDIArc(this.getGraph()); }
/** * Factory method that finds or creates an XDI root link contract for a graph. * @return The XDI root link contract. */ public static RootLinkContract findRootLinkContract(Graph graph, boolean create) { XDIAddress ownerXDIAddress = GraphUtil.getOwnerXDIAddress(graph); if (ownerXDIAddress == null) return null; RelationshipLinkContract relationshipLinkContract = RelationshipLinkContract.findRelationshipLinkContract(graph, ownerXDIAddress, ownerXDIAddress, null, null, create); if (relationshipLinkContract == null) return null; return fromXdiEntity(relationshipLinkContract.getXdiEntity()); } }
public static XdiAttributeInstanceOrdered fromXDIAddress(XDIAddress XDIaddress) { return fromContextNode(GraphUtil.contextNodeFromComponents(XDIaddress)); }
@Override protected XDILocalClientRoute routeInternal(XDIArc toPeerRootXDIArc) throws Xdi2AgentException { // check if we can provide the TO peer root if (toPeerRootXDIArc == null) { if (log.isDebugEnabled()) log.debug("Cannot route to unknown peer root. Skipping."); return null; } boolean ownsPeerRootXDIArc = false; if (ownsPeerRootXDIArc == false && this.getMessagingContainer() != null) ownsPeerRootXDIArc |= this.getMessagingContainer().ownsPeerRootXDIArc(toPeerRootXDIArc); if (ownsPeerRootXDIArc == false && this.getGraph() != null) ownsPeerRootXDIArc = GraphUtil.ownsPeerRootXDIArc(this.getGraph(), toPeerRootXDIArc); if (! ownsPeerRootXDIArc) { if (log.isDebugEnabled()) log.debug("Local messaging container " + (this.getMessagingContainer() == null ? null : this.getMessagingContainer().getClass().getSimpleName()) + " and graph " + (this.getGraph() == null ? null : this.getGraph().getClass().getSimpleName()) + " is no route to peer root " + toPeerRootXDIArc + " (" + ownsPeerRootXDIArc + "). Skipping."); return null; } // construct the route XDILocalClientRoute route = new XDILocalClientRoute(toPeerRootXDIArc, this.getMessagingContainer(), this.getGraph()); // add interceptors if supported if (this.getInterceptors() != null) { route.getInterceptors().addAll(this.getInterceptors()); } // done return route; }