Created
July 25, 2015 01:13
-
-
Save dilnei/ec8ed6daa28e1d0fcbf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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