Package org.kiwiproject.beta.dao
Class AllowedFields
- java.lang.Object
-
- org.kiwiproject.beta.dao.AllowedFields
-
@Beta public class AllowedFields extends Object
Extremely simply way to whitelist fields, e.g. from a web form.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertAllowed(String fieldName)Checks that the field name is an allowed field.voidassertPrefixedAllowed(String prefixedFieldName)Checks that the prefixed field name is allowed.StringgetPrefixedFieldName(String fieldName)Find the prefixed field name for the given (unprefixed) field name.booleanisAllowed(String fieldName)Checks whether the field name is allowedbooleanisPrefixedAllowed(String prefixedFieldName)Checks whether the prefixed field name is allowed.static AllowedFieldsof(String... fieldNames)Create a new instance from the given field names.static AllowedFieldsof(Collection<String> fieldNames)Create a new instance from the collection of field names.
-
-
-
Method Detail
-
of
public static AllowedFields of(String... fieldNames)
Create a new instance from the given field names.Permits simple or prefixed field names in the format [prefix.optionally.with.multiple.parts.]fieldName. If the given name is dot-separated, then the field name is extracted as the part after the last dot, while the part before the last dot is considered the prefix.
Examples: firstName, u.firstName, user.firstName, account.user.firstName
- Parameters:
fieldNames- the field names to allow- Returns:
- a new instance
-
of
public static AllowedFields of(Collection<String> fieldNames)
Create a new instance from the collection of field names.Permits simple or prefixed field names in the format [prefix.optionally.with.multiple.parts.]fieldName. If the given name is dot-separated, then the field name is extracted as the part after the last dot, while the part before the last dot is considered the prefix.
Examples: firstName, u.firstName, user.firstName, account.user.firstName
- Parameters:
fieldNames- the field names to allow- Returns:
- a new instance
- See Also:
of(String...)
-
isAllowed
public boolean isAllowed(String fieldName)
Checks whether the field name is allowed- Parameters:
fieldName- the field name- Returns:
- true if the given field name is allowed, false otherwise
-
isPrefixedAllowed
public boolean isPrefixedAllowed(String prefixedFieldName)
Checks whether the prefixed field name is allowed.- Parameters:
prefixedFieldName- the prefixed field name- Returns:
- true if the given prefixed field name is allowed, false otherwise
-
assertAllowed
public void assertAllowed(String fieldName)
Checks that the field name is an allowed field.- Parameters:
fieldName- the field name to check- Throws:
IllegalArgumentException- if the given field name is not allowed
-
assertPrefixedAllowed
public void assertPrefixedAllowed(String prefixedFieldName)
Checks that the prefixed field name is allowed.- Parameters:
prefixedFieldName- the prefixed field name to check- Throws:
IllegalArgumentException- if the given prefixed field name is not allowed
-
-