Skip to content

Commit

Permalink
SecAgent: Refuse handling messages after shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
kj-actoron committed Jun 1, 2021
1 parent 2254d9e commit f794619
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import jadex.base.Starter;
import jadex.bridge.ClassInfo;
import jadex.bridge.ComponentIdentifier;
import jadex.bridge.ComponentTerminatedException;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
Expand All @@ -56,6 +57,7 @@
import jadex.bridge.service.annotation.Security;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.search.ServiceRegistry;
import jadex.bridge.service.types.cms.IComponentDescription;
import jadex.bridge.service.types.security.ISecurityInfo;
import jadex.bridge.service.types.security.ISecurityService;
import jadex.bridge.service.types.settings.IPlatformSettings;
Expand Down Expand Up @@ -251,6 +253,9 @@ public class SecurityAgent implements ISecurityService, IInternalService
/** The list of network names (used by all service identifiers). */
protected Set<String> networknames;

/** Flag if terminating. */
protected boolean terminating;

/**
* Initialization.
*/
Expand Down Expand Up @@ -646,9 +651,14 @@ public IFuture<byte[]> encryptAndSign(final IMsgHeader header, final byte[] cont
{
public IFuture<byte[]> execute(IInternalAccess ia)
{
doCleanup();

final Future<byte[]> ret = new Future<byte[]>();
if (terminating)
{
ret.setException(new ComponentTerminatedException());
return ret;
}

doCleanup();

if (isSecurityMessage(header))
{
Expand Down Expand Up @@ -759,10 +769,16 @@ public IFuture<Tuple2<ISecurityInfo,byte[]>> decryptAndAuth(final IComponentIden
{
public IFuture<Tuple2<ISecurityInfo, byte[]>> execute(IInternalAccess ia)
{
doCleanup();

final Future<Tuple2<ISecurityInfo, byte[]>> ret = new Future<Tuple2<ISecurityInfo,byte[]>>();

if (terminating)
{
ret.setException(new ComponentTerminatedException());
return ret;
}

doCleanup();

if (content.length > 0 && content[0] == -1)
{
// Security message
Expand Down Expand Up @@ -2466,7 +2482,11 @@ public Map<String, Object> getPropertyMap()
* Shutdown the service.
* @return A future that is done when the service has completed its shutdown.
*/
public IFuture<Void> shutdownService() {return IFuture.DONE;}
public IFuture<Void> shutdownService()
{
terminating = true;
return IFuture.DONE;
}

/**
* Sets the access for the component.
Expand Down

0 comments on commit f794619

Please sign in to comment.