Package org.astrogrid.samp.web
Class ListMessageRestriction
- java.lang.Object
-
- org.astrogrid.samp.web.ListMessageRestriction
-
- All Implemented Interfaces:
MessageRestriction
public class ListMessageRestriction extends java.lang.Object implements MessageRestriction
General purpose implementation of MessageRestriction. It allows to either whitelist or blacklist a given list of MType patterns, with the option for client subscriptions to override this policy by setting the "x-samp.mostly-harmless" key in the annotation map corresponding to a given MType subscription.- Since:
- 23 Nov 2011
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description static MessageRestriction
ALLOW_ALL
MessageRestriction that permits all MTypes, except as overridden byx-samp.mostly-harmless
annotations.static MessageRestriction
DEFAULT
Default MessageRestriction implementation.static java.lang.String[]
DEFAULT_SAFE_MTYPES
Default list of MType patterns returned bygetSafeMTypes()
.static MessageRestriction
DENY_ALL
MessageRestriction that blocks all MTypes, except as overridden byx-samp.mostly-harmless
annotations.static java.lang.String
SAFE_MTYPE_PROP
System property used to specify a default list of known safe MTypes, which theDEFAULT
policy will permit.
-
Constructor Summary
Constructors Constructor Description ListMessageRestriction(boolean allow, java.lang.String[] mtypes, boolean useSubsInfo)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String[]
getSafeMTypes()
Returns a list of MType patterns which are permitted by the DEFAULT policy.boolean
permitSend(java.lang.String mtype, java.util.Map subsInfo)
Indicates whether a message covered by a given MType subscription may be sent.java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_SAFE_MTYPES
public static java.lang.String[] DEFAULT_SAFE_MTYPES
Default list of MType patterns returned bygetSafeMTypes()
.
-
SAFE_MTYPE_PROP
public static final java.lang.String SAFE_MTYPE_PROP
System property used to specify a default list of known safe MTypes, which theDEFAULT
policy will permit. The value is a comma-separated list of MType patterns.- See Also:
- Constant Field Values
-
DEFAULT
public static final MessageRestriction DEFAULT
Default MessageRestriction implementation. The current implementation allows a list of MTypes believed to be safe, as given by callinggetSafeMTypes()
, and blocks all others. However, client subscriptions may override this by annotating their subscriptions with an entry having the key "x-samp.mostly-harmless
". If this has the value "1" the MType thus annotated is allowed, and if it has the value "0" it is blocked, regardless of the safe list.
-
ALLOW_ALL
public static final MessageRestriction ALLOW_ALL
MessageRestriction that permits all MTypes, except as overridden byx-samp.mostly-harmless
annotations.
-
DENY_ALL
public static final MessageRestriction DENY_ALL
MessageRestriction that blocks all MTypes, except as overridden byx-samp.mostly-harmless
annotations.
-
-
Constructor Detail
-
ListMessageRestriction
public ListMessageRestriction(boolean allow, java.lang.String[] mtypes, boolean useSubsInfo)
Constructor.- Parameters:
allow
- whether the sense of the mtypes list is those that should be allowed (true) or blocked (false)mtypes
- mtype patterns to be allowed or blockeduseSubsInfo
- if true, honour x-samp.mostly-harmless subscription annotations
-
-
Method Detail
-
permitSend
public boolean permitSend(java.lang.String mtype, java.util.Map subsInfo)
Description copied from interface:MessageRestriction
Indicates whether a message covered by a given MType subscription may be sent.- Specified by:
permitSend
in interfaceMessageRestriction
- Parameters:
mtype
- the MType string to be sentsubsInfo
- the annotation map corresponding to the MType subscription (the value from the Subscriptions map corresponding to themtype
key)- Returns:
- true if the message may be sent, false if it is blocked
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getSafeMTypes
public static java.lang.String[] getSafeMTypes()
Returns a list of MType patterns which are permitted by the DEFAULT policy. If the System Property "jsamp.mtypes.safe" exists, its value is taken as a comma-separated list of known permitted MType patterns. Otherwise, theDEFAULT_SAFE_MTYPES
array is returned.- Returns:
- list of MTypes treated as harmless by default
-
-