Package i5.las2peer.security
Class AgentContext
java.lang.Object
i5.las2peer.security.AgentContext
- All Implemented Interfaces:
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
ConstructorDescriptionAgentContext
(Node localNode, AgentImpl mainAgent) Creates a new (local) context. -
Method Summary
Modifier and TypeMethodDescriptionUses this context asAgentStorage
.static AgentContext
Gets the current las2peer context.long
Returns the time of the last usage of this context.Gives access to the local node.Gets the main agent of this context.boolean
Checks if the agent can be accessed (e.g.boolean
does this storage know the requested agent? Does not refer to the backup storage if applicableboolean
isMemberRecursive
(GroupAgentImpl groupAgent, String agentId) Checks if the given agent is transitive member of the given group.requestAgent
(String agentId) returns an unlocked instance of the requested AgentrequestGroupAgent
(String groupId) Tries to open the given id for this context.void
touch()
Mark the current time as the last usage.void
unlockMainAgent
(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(String passphrase) throws AgentAccessDeniedException, AgentOperationFailedException unlocks 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(String groupId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException Tries 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(String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException returns an unlocked instance of the requested Agent- Parameters:
agentId
- the requested agent- Returns:
- an unlocked agent instance
- Throws:
AgentOperationFailedException
AgentNotFoundException
AgentAccessDeniedException
-
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:
getAgent
in interfaceAgentStorage
- Parameters:
id
-- Returns:
- get the agent of the given id
- Throws:
AgentException
AgentNotFoundException
- If the agent is not found in this storage
-
hasAgent
Description copied from interface:AgentStorage
does this storage know the requested agent? Does not refer to the backup storage if applicable- Specified by:
hasAgent
in interfaceAgentStorage
- Returns:
- true, if this storage knows an agent of the given id
-
getCurrent
Gets the current las2peer context.- Returns:
- the current context
- Throws:
IllegalStateException
- called not in a las2peer execution thread
-