Package org.togglz.core.activation
Class UserRoleActivationStrategy
- java.lang.Object
-
- org.togglz.core.activation.UserRoleActivationStrategy
-
- All Implemented Interfaces:
ActivationStrategy
public class UserRoleActivationStrategy extends Object implements ActivationStrategy
ActivationStrategy implementation based on roles of the current user. As far as user has at least one of configured roles then feature will be active. Please note this activation strategy is not coupled to any particular security framework and will work with any framework as far as current user has "roles" attribute populated with a set of granted authorities. This is usually a responsibility of an UserProvider.- Author:
- Vasily Ivanov
-
-
Field Summary
Fields Modifier and Type Field Description static StringIDstatic StringNAMEstatic StringPARAM_ROLES_DESCstatic StringPARAM_ROLES_LABELstatic StringPARAM_ROLES_NAMEstatic StringUSER_ATTRIBUTE_ROLES
-
Constructor Summary
Constructors Constructor Description UserRoleActivationStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetId()A unique id for this strategy.StringgetName()A human readable name of the strategy.Parameter[]getParameters()Returns the list of configuration parameter definitions for the strategy.booleanisActive(FeatureState state, FeatureUser user)This method is responsible to decide whether a feature is active or not.
-
-
-
Field Detail
-
ID
public static final String ID
- See Also:
- Constant Field Values
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
PARAM_ROLES_NAME
public static final String PARAM_ROLES_NAME
- See Also:
- Constant Field Values
-
PARAM_ROLES_LABEL
public static final String PARAM_ROLES_LABEL
- See Also:
- Constant Field Values
-
PARAM_ROLES_DESC
public static final String PARAM_ROLES_DESC
- See Also:
- Constant Field Values
-
USER_ATTRIBUTE_ROLES
public static final String USER_ATTRIBUTE_ROLES
- See Also:
- Constant Field Values
-
-
Method Detail
-
getId
public String getId()
Description copied from interface:ActivationStrategyA unique id for this strategy. This id is used to persist the selected strategy in theStateRepository.- Specified by:
getIdin interfaceActivationStrategy
-
getName
public String getName()
Description copied from interface:ActivationStrategyA human readable name of the strategy. This name is used to in the admin console to represent the strategy.- Specified by:
getNamein interfaceActivationStrategy
-
isActive
public boolean isActive(FeatureState state, FeatureUser user)
Description copied from interface:ActivationStrategyThis method is responsible to decide whether a feature is active or not. The implementation can use the custom configuration parameters of the strategy stored in the feature state and information from the currently acting user to find a decision.- Specified by:
isActivein interfaceActivationStrategy- Parameters:
state- The feature state which represents the current configuration of the feature. The implementation of the method typically usesFeatureState.getParameter(String)to access custom configuration parameter values.user- The user for which to decide whether the feature is active. May benullif the user could not be identified by theUserProvider.- Returns:
trueif the feature should be active, elsefalse
-
getParameters
public Parameter[] getParameters()
Description copied from interface:ActivationStrategyReturns the list of configuration parameter definitions for the strategy. Parameters are typically built using a
ParameterBuilderclass but users can also create custom implementations of theParameterinterface.Example:
public Parameter[] getParameters() { return new Parameter[] { ParameterBuilder.create("country").label("Country Code").matching("[A-Z]+") }; }- Specified by:
getParametersin interfaceActivationStrategy- See Also:
ParameterBuilder
-
-