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 negare un'operazione ad un utente bannato.
11   */
12  @Interceptor
13  @DenyBannedUsers
14  @Priority(Interceptor.Priority.APPLICATION+2)
15  public class DenyBannedUsersInterceptor {
16      @Inject private CurrentUser currentUser;
17  
18      @AroundInvoke
19      public Object checkAdmin(InvocationContext invocationContext) throws Exception{
20          if(currentUser.isLoggedIn() && currentUser.getBanDuration() != null){
21              throw new BannedUserException(currentUser.getBanDuration());
22          }
23          return invocationContext.proceed();
24      }
25  }