Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework: How to require login for some actions, but not all

Adding @With(Secure.class) to a controller blocks all unauthenticated access. Is there a way to enabled it only for certain actions, or to except certain actions after it's enabled on a controller?

like image 736
Brad Mace Avatar asked Dec 01 '10 19:12

Brad Mace


1 Answers

You can't do that with the secure module. As Niels said the secure module is more an example than a solution. You can build your own security system with the @Before annotation. Here is an example:

public class Admin extends Controller {

@Before(unless={"login", "authenticate", "logout", "otherMethod"})
void checkAccess() {
    // check the cookie
}

public void login() {
    render();
}

public void authenticate(String email, String password) {
    // check the params and set a value in the cookie
}

public void logout() {
    // delete cookie
}

I recommend you to read the source code of the secure module.

like image 87
Loïc Guillois Avatar answered Nov 13 '22 10:11

Loïc Guillois