Skip to content

Instantly share code, notes, and snippets.

@dilnei
Created July 25, 2015 01:13
Show Gist options
  • Select an option

  • Save dilnei/ec8ed6daa28e1d0fcbf8 to your computer and use it in GitHub Desktop.

Select an option

Save dilnei/ec8ed6daa28e1d0fcbf8 to your computer and use it in GitHub Desktop.
package br.com.weblog.web.component;
import javax.inject.Inject;
import br.com.caelum.vraptor.Accepts;
import br.com.caelum.vraptor.AfterCall;
import br.com.caelum.vraptor.AroundCall;
import br.com.caelum.vraptor.BeforeCall;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.controller.ControllerMethod;
import br.com.caelum.vraptor.interceptor.SimpleInterceptorStack;
import br.com.weblog.web.controller.admin.AdminController;
import br.com.weblog.web.controller.login.LoginController;
@Intercepts
public class SecurityInterceptor {
private final Result result;
private final UsuarioLogado usuarioLogado;
public SecurityInterceptor() {
this(null, null);
}
@Inject
public SecurityInterceptor(UsuarioLogado usuarioLogado, Result result) {
this.result = result;
this.usuarioLogado = usuarioLogado;
}
@Accepts
public boolean ehRestrito(ControllerMethod method) {
return method.getController().getType().equals(AdminController.class);
}
@BeforeCall
public void before() {
}
@AfterCall
public void after() {
}
@AroundCall
public void intercept(SimpleInterceptorStack stack) {
if (usuarioLogado.isLogado()) {
stack.next();
} else {
result.redirectTo(LoginController.class).login();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment