播放框架:如何要求登录某些操作,但不是全部

Bra*_*ace 5 authentication controller playframework

添加@With(Secure.class)到控制器会阻止所有未经身份验证的访问.有没有办法只为某些操作启用它,或者在控制器上启用某些操作后除外?

Loï*_*ois 9

您无法使用安全模块执行此操作.正如Niels所说,安全模块不仅仅是一个解决方案.您可以使用@Before注释构建自己的安全系统.这是一个例子:

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
}
Run Code Online (Sandbox Code Playgroud)

我建议你阅读安全模块的源代码.