Skip to content

Using the "secure" module

pramode edited this page Jun 29, 2011 · 2 revisions

Using secure module

Check official documentation

Allowing only certain users to execute a controller action

Suppose you want only user "pce" to execute a controller action. Here is what you do:

First, annotate the controller action:

    @Check("pce")
    public static void index() {
        render();
    }   

Now, define a class Security.java (in the "controllers" folder):

   package controllers;

   public class Security extends Secure.Security {
      static boolean authenticate(String username, String password)
      {
          return (username.equals("admin") || username.equals("pce")) && password.equals("asdfgh");
      }

      static boolean check(String profile)
      {
          return profile.equals(Security.connected());
      }
    }

The @Check annotation results in the function "check" being called with the annotation parameter as argument to the function ("profile"). If the function returns FALSE, the annotated controller action is disallowed.