class ContextsStorageSecurityAspect {

    @Before("execution(* ContextDataStorage.update(java.util.UUID, com.jaspersoft.jasperserver.remote.connection.storage.ContextDataPair)) ||" +
            "execution(* ContextDataStorage.get(java.util.UUID)) ||" +
            "execution(* ContextDataStorage.delete(java.util.UUID))"
    )
    public void checkOwner(JoinPoint joinPoint){
        final UUID uuid = (UUID) joinPoint.getArgs()[0];
        final Element element = getElement(uuid);
        if(element != null){
            final Object pair = element.getObjectValue();
            if(pair != null){
                if(!(pair instanceof OwnedContextDataPair &&
                        getCurrentUserQualifiedName().equals(((OwnedContextDataPair) pair).getOwner()))){
                    // throw exception if pair isn't null and it has another owner, than current user or doesn't
                    // have owner at all
                    throw new AccessDeniedException(uuid.toString());
                }
            }
        }
    }

}