Class 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
    • Constructor Detail

      • UserRoleActivationStrategy

        public UserRoleActivationStrategy()
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: ActivationStrategy
        A human readable name of the strategy. This name is used to in the admin console to represent the strategy.
        Specified by:
        getName in interface ActivationStrategy
      • isActive

        public boolean isActive​(FeatureState state,
                                FeatureUser user)
        Description copied from interface: ActivationStrategy
        This 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:
        isActive in interface ActivationStrategy
        Parameters:
        state - The feature state which represents the current configuration of the feature. The implementation of the method typically uses FeatureState.getParameter(String) to access custom configuration parameter values.
        user - The user for which to decide whether the feature is active. May be null if the user could not be identified by the UserProvider.
        Returns:
        true if the feature should be active, else false
      • getParameters

        public Parameter[] getParameters()
        Description copied from interface: ActivationStrategy

        Returns the list of configuration parameter definitions for the strategy. Parameters are typically built using a ParameterBuilder class but users can also create custom implementations of the Parameter interface.

        Example:

         public Parameter[] getParameters() {
             return new Parameter[] {
                     ParameterBuilder.create("country").label("Country Code").matching("[A-Z]+")
             };
         }
         
        Specified by:
        getParameters in interface ActivationStrategy
        See Also:
        ParameterBuilder