Package i5.las2peer.security
Class AgentContext
java.lang.Object
i5.las2peer.security.AgentContext
- All Implemented Interfaces:
AgentStorage
public class AgentContext extends java.lang.Object implements AgentStorage
A context that can be created for an agent to perform operations in the network. Cached in the node for remembering
unlocked agents. Used for messaging and service calls.
-
Constructor Summary
Constructors Constructor Description AgentContext(Node localNode, AgentImpl mainAgent)Creates a new (local) context. -
Method Summary
Modifier and Type Method Description AgentImplgetAgent(java.lang.String id)Uses this context asAgentStorage.static AgentContextgetCurrent()Gets the current las2peer context.longgetLastUsageTimestamp()Returns the time of the last usage of this context.NodegetLocalNode()Gives access to the local node.AgentImplgetMainAgent()Gets the main agent of this context.booleanhasAccess(java.lang.String agentId)Checks if the agent can be accessed (e.g. unlocked) from this context.booleanhasAgent(java.lang.String id)does this storage know the requested agent?booleanisMemberRecursive(GroupAgentImpl groupAgent, java.lang.String agentId)Checks if the given agent is transitive member of the given group.AgentrequestAgent(java.lang.String agentId)returns an unlocked instance of the requested AgentGroupAgentImplrequestGroupAgent(java.lang.String groupId)Tries to open the given id for this context.voidtouch()Mark the current time as the last usage.voidunlockMainAgent(java.lang.String passphrase)unlocks the main agent of this context
-
Constructor Details
-
AgentContext
Creates a new (local) context.- Parameters:
mainAgent- The main agent for this context.localNode- The node this context is bound to.
-
-
Method Details
-
unlockMainAgent
public void unlockMainAgent(java.lang.String passphrase) throws AgentAccessDeniedException, AgentOperationFailedExceptionunlocks the main agent of this context- Parameters:
passphrase- Passphrase of the agent- Throws:
AgentAccessDeniedException- If the passphrase is invalid.AgentOperationFailedException- If the agent's private key can not be deserialized.
-
getMainAgent
Gets the main agent of this context.- Returns:
- the agent of this context
-
requestGroupAgent
public GroupAgentImpl requestGroupAgent(java.lang.String groupId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedExceptionTries to open the given id for this context.- Parameters:
groupId- The group id to fetch and unlock- Returns:
- the unlocked GroupAgent of the given id
- Throws:
AgentAccessDeniedException- If the group agent can not be unlockedAgentNotFoundException- If the group agent could not be found or is not a group agentAgentOperationFailedException- If the agent's keys can not be deserialized
-
requestAgent
public Agent requestAgent(java.lang.String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedExceptionreturns an unlocked instance of the requested Agent- Parameters:
agentId- the requested agent- Returns:
- an unlocked agent instance
- Throws:
AgentOperationFailedExceptionAgentNotFoundExceptionAgentAccessDeniedException
-
hasAccess
Checks if the agent can be accessed (e.g. unlocked) from this context.- Parameters:
agentId- The agent to be accessed- Returns:
- true if the given agent can be unlocked.
- Throws:
AgentNotFoundException- If the agent does not exist
-
isMemberRecursive
Checks if the given agent is transitive member of the given group.- Parameters:
groupAgent- The groupagentId- the agent to check if its member of the group- Returns:
- true if it is a transitive member of the group.
-
getLocalNode
Gives access to the local node.- Returns:
- the local P2P node
-
touch
public void touch()Mark the current time as the last usage. -
getLastUsageTimestamp
public long getLastUsageTimestamp()Returns the time of the last usage of this context.- Returns:
- the timestamp of the last usage
-
getAgent
Uses this context asAgentStorage. Returns agents that are unlocked in this context first. E.g. necessary for opening a receivedMessage.- Specified by:
getAgentin interfaceAgentStorage- Parameters:
id-- Returns:
- get the agent of the given id
- Throws:
AgentExceptionAgentNotFoundException- If the agent is not found in this storage
-
hasAgent
public boolean hasAgent(java.lang.String id)Description copied from interface:AgentStoragedoes this storage know the requested agent? Does not refer to the backup storage if applicable- Specified by:
hasAgentin interfaceAgentStorage- Returns:
- true, if this storage knows an agent of the given id
-
getCurrent
Gets the current las2peer context.- Returns:
- the current context
- Throws:
java.lang.IllegalStateException- called not in a las2peer execution thread
-