@Test public void testHasAccess() throws MalformedXMLException, IOException, InternalSecurityException, CryptoException, SerializationException, AgentException, NodeException, AgentAccessDeniedException { LocalNode node = new LocalNodeManager().newNode(); UserAgentImpl adam = MockAgentFactory.getAdam(); adam.unlock("adamspass"); GroupAgentImpl group1 = MockAgentFactory.getGroup1(); group1.unlock(adam); GroupAgentImpl groupA = MockAgentFactory.getGroupA(); groupA.unlock(adam); GroupAgentImpl groupSuper = GroupAgentImpl.createGroupAgent(new AgentImpl[] { group1, groupA }); groupSuper.unlock(group1); try { node.storeAgent(group1); } catch (AgentAlreadyRegisteredException e) { } try { node.storeAgent(groupA); } catch (AgentAlreadyRegisteredException e) { } node.storeAgent(groupSuper); node.launch(); UserAgentImpl eve = MockAgentFactory.getEve(); eve.unlock("evespass"); AgentContext context = new AgentContext(node, eve); try { boolean result = context.hasAccess(group1.getIdentifier()); assertTrue(result); } catch (Exception e) { e.printStackTrace(); fail("exception thrown: " + e); } try { boolean result = context.hasAccess(groupA.getIdentifier()); assertFalse(result); } catch (Exception e) { e.printStackTrace(); fail("exception thrown: " + e); } try { boolean result = context.hasAccess(groupSuper.getIdentifier()); assertTrue(result); } catch (Exception e) { e.printStackTrace(); fail("exception thrown: " + e); } }
public boolean hasAccess(String agentId) throws AgentNotFoundException { if (agent.getIdentifier().equals(agentId)) { return true; } AgentImpl a; try { a = getAgent(agentId); } catch (AgentException e) { throw new AgentNotFoundException("Agent could not be found!", e); } if (a instanceof GroupAgentImpl) { return isMemberRecursive((GroupAgentImpl) a, agent.getIdentifier()); } return false; }
AgentContext implements AgentStorage { public boolean hasAccess(String agentId) throws AgentNotFoundException { if (agent.getIdentifier().equals(agentId)) { return true; } AgentImpl a; try { a = getAgent(agentId); } catch (AgentException e) { throw new AgentNotFoundException("Agent could not be found!", e); } if (a instanceof GroupAgentImpl) { return isMemberRecursive((GroupAgentImpl) a, agent.getIdentifier()); } return false; } }
AgentContext implements AgentStorage { public boolean hasAccess(String agentId) throws AgentNotFoundException { if (agent.getIdentifier().equals(agentId)) { return true; } AgentImpl a; try { a = getAgent(agentId); } catch (AgentException e) { throw new AgentNotFoundException("Agent could not be found!", e); } if (a instanceof GroupAgentImpl) { return isMemberRecursive((GroupAgentImpl) a, agent.getIdentifier()); } return false; } AgentContext(Node localNode, AgentImpl mainAgent); }
AgentContext implements AgentStorage { public boolean hasAccess(String agentId) throws AgentNotFoundException { if (agent.getIdentifier().equals(agentId)) { return true; } AgentImpl a; try { a = getAgent(agentId); } catch (AgentException e) { throw new AgentNotFoundException("Agent could not be found!", e); } if (a instanceof GroupAgentImpl) { return isMemberRecursive((GroupAgentImpl) a, agent.getIdentifier()); } return false; } AgentContext(Node localNode, AgentImpl mainAgent); void unlockMainAgent(String passphrase); AgentImpl getMainAgent(); GroupAgentImpl requestGroupAgent(String groupId); Agent requestAgent(String agentId); boolean hasAccess(String agentId); boolean isMemberRecursive(GroupAgentImpl groupAgent, String agentId); Node getLocalNode(); void touch(); long getLastUsageTimestamp(); @Override AgentImpl getAgent(String id); @Override boolean hasAgent(String id); static AgentContext getCurrent(); }
AgentContext implements AgentStorage { public boolean hasAccess(String agentId) throws AgentNotFoundException { if (agent.getIdentifier().equals(agentId)) { return true; } AgentImpl a; try { a = getAgent(agentId); } catch (AgentException e) { throw new AgentNotFoundException("Agent could not be found!", e); } if (a instanceof GroupAgentImpl) { return isMemberRecursive((GroupAgentImpl) a, agent.getIdentifier()); } return false; } AgentContext(Node localNode, AgentImpl mainAgent); void unlockMainAgent(String passphrase); AgentImpl getMainAgent(); GroupAgentImpl requestGroupAgent(String groupId); Agent requestAgent(String agentId); boolean hasAccess(String agentId); boolean isMemberRecursive(GroupAgentImpl groupAgent, String agentId); Node getLocalNode(); void touch(); long getLastUsageTimestamp(); @Override AgentImpl getAgent(String id); @Override boolean hasAgent(String id); static AgentContext getCurrent();  }