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
11
12 @Interceptor
13 @AdminsOnly
14 @Priority(Interceptor.Priority.APPLICATION+3)
15 public class AdminsOnlyInterceptor {
16 @Inject private CurrentUser currentUser;
17
18
19
20
21
22
23
24 @AroundInvoke
25 public Object checkAdmin(InvocationContext invocationContext) throws Exception{
26 if(!currentUser.isLoggedIn() || !currentUser.isAdmin()){
27 throw new AuthorizationException();
28 }
29 return invocationContext.proceed();
30 }
31 }