Please give me a clue how to solve this problem

I have solved the first problem: check whether user has access to resource
you can see in above picture,web page node have connection with resources. user A is authorized to access resource 2,3,4. and those resource will be exhibited in web page 1 and 2,but web page 3 is the parent page of page2. And How should I get the web page tree that a user can access?

Hmm how deep can the webpages get ? Or it’s unbounded ?

theoretically the depth is unlimited,but I can restrict it with 5

Hmm okay, will try to come up with something