View Javadoc
1   package usecase.auth;
2   
3   import javax.annotation.Priority;
4   import javax.inject.Inject;
5   import javax.interceptor.AroundInvoke;
6   import javax.interceptor.Interceptor;
7   import javax.interceptor.InvocationContext;
8   
9   /**
10   * Classe interceptor per confermare l'autenticazione
11   */
12  @Interceptor
13  @AuthenticationRequired
14  @Priority(Interceptor.Priority.APPLICATION+1)
15  public class AuthenticationRequiredInterceptor {
16      @Inject private CurrentUser currentUser;
17  
18      /**
19       * Verifica l'autenticazione
20       * @param invocationContext
21       * @return Oggetto che conferma la possibilità di procedere.
22       * @throws AuthenticationRequiredException
23       */
24      @AroundInvoke
25      public Object checkAdmin(InvocationContext invocationContext) throws Exception{
26          if(!currentUser.isLoggedIn()){
27              throw new AuthenticationRequiredException();
28          }
29          return invocationContext.proceed();
30      }
31  }