@Test public void testRequestAgent() 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 { GroupAgentImpl a = (GroupAgentImpl) context.requestAgent(group1.getIdentifier()); assertEquals(a.getIdentifier(), group1.getIdentifier()); } catch (Exception e) { e.printStackTrace(); fail("exception thrown: " + e); } try { context.requestAgent(groupA.getIdentifier()); fail("exception expected"); } catch (Exception e) { } try { GroupAgentImpl a = (GroupAgentImpl) context.requestAgent(groupSuper.getIdentifier()); assertEquals(a.getIdentifier(), groupSuper.getIdentifier()); } catch (Exception e) { e.printStackTrace(); fail("exception thrown: " + e); } }
public Agent requestAgent(String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException { if (agentId.equalsIgnoreCase(getMainAgent().getIdentifier())) { return getMainAgent(); } else { try { return requestGroupAgent(agentId); } catch (AgentAccessDeniedException e) { throw new AgentAccessDeniedException("Access to agent denied!", e); } } }
AgentContext implements AgentStorage { public Agent requestAgent(String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException { if (agentId.equalsIgnoreCase(getMainAgent().getIdentifier())) { return getMainAgent(); } else { try { return requestGroupAgent(agentId); } catch (AgentAccessDeniedException e) { throw new AgentAccessDeniedException("Access to agent denied!", e); } } } }
AgentContext implements AgentStorage { public Agent requestAgent(String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException { if (agentId.equalsIgnoreCase(getMainAgent().getIdentifier())) { return getMainAgent(); } else { try { return requestGroupAgent(agentId); } catch (AgentAccessDeniedException e) { throw new AgentAccessDeniedException("Access to agent denied!", e); } } } AgentContext(Node localNode, AgentImpl mainAgent); }
AgentContext implements AgentStorage { public Agent requestAgent(String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException { if (agentId.equalsIgnoreCase(getMainAgent().getIdentifier())) { return getMainAgent(); } else { try { return requestGroupAgent(agentId); } catch (AgentAccessDeniedException e) { throw new AgentAccessDeniedException("Access to agent denied!", e); } } } 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 Agent requestAgent(String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException { if (agentId.equalsIgnoreCase(getMainAgent().getIdentifier())) { return getMainAgent(); } else { try { return requestGroupAgent(agentId); } catch (AgentAccessDeniedException e) { throw new AgentAccessDeniedException("Access to agent denied!", e); } } } 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();  }