concept strategy in category scalatra

This is an excerpt from Manning's book Scalatra in Action.
Like Warden, Scentry is structured around the concept of authentication strategies. A strategy is a self-contained piece of logic for checking whether an authentication attempt should succeed or fail. Strategies can run additional code after authentication or logout takes place, allowing you to take care of things like giving the user a session or destroying cookies on logout.
The way the code is set up right now, UserPasswordStrategy will run in full every time the scentry.authenticate() method is called. But sometimes you won’t want this to happen, depending on your application state. Let’s see how you can tell Scentry to not bother running a strategy under certain conditions. The key to this is Scentry’s isValid() method.
The isValid() method determines whether a strategy should run or not. It returns a Boolean, and you can use override in your strategies to determine the conditions under which they will run (or not).
Let’s try it. You want the UserPasswordStrategy to run if and only if the strategy has received username and password params. Add the following code to UserPasswordStrategy.