001package usecase.auth; 002 003import javax.annotation.Priority; 004import javax.inject.Inject; 005import javax.interceptor.AroundInvoke; 006import javax.interceptor.Interceptor; 007import javax.interceptor.InvocationContext; 008 009/** 010 * Classe interceptor per confermare l'autenticazione 011 */ 012@Interceptor 013@AuthenticationRequired 014@Priority(Interceptor.Priority.APPLICATION+1) 015public class AuthenticationRequiredInterceptor { 016 @Inject private CurrentUser currentUser; 017 018 /** 019 * Verifica l'autenticazione 020 * @param invocationContext 021 * @return Oggetto che conferma la possibilità di procedere. 022 * @throws AuthenticationRequiredException 023 */ 024 @AroundInvoke 025 public Object checkAdmin(InvocationContext invocationContext) throws Exception{ 026 if(!currentUser.isLoggedIn()){ 027 throw new AuthenticationRequiredException(); 028 } 029 return invocationContext.proceed(); 030 } 031}