Filip,

After refactoring my code about a dozen times your suggestion (and
my original code) did the trick.

Thanks!
Andreas Pardeike

On 11 mar 2008, at 13.11, Filip S. Adamsen wrote:

Cordenier, that's a VERY complicated way to get the class, when, in fact, getClass() on the Component returned by ComponentSource works just fine.

So that's not the problem. No, I think Andreas forgot to add @Retention(RetentionPolicy.RUNTIME) to his annotation, simple as that.

Hope this helps. :)

-Filip

Cordenier Christophe skrev:

To resolve the class of a component, you have to use the "ComponentResources" class. It contains the componentModel that allows you to the class of the "coreComponent" by using the method "getComponentClassName". With this method you can resolve the "Real" class of your component or page. There is also the ComponentClassResolver service that allows you to access information on the component class. Check for example the code of "PageElementFactoryImpl" that uses this service to instantiate components.
-----Message d'origine-----
De : Andreas Pardeike [mailto:[EMAIL PROTECTED]
Envoyé : mardi 11 mars 2008 11:10
À : Tapestry users
Objet : Page class annotations (was Re: Checking for a logged in user globally) Great. One question though. I tried to create my own annotation Access
@PageAccess(Access.PUBLIC)
public class Start
{
    ...
}
but
Class<? extends Component> pageClass = page.getClass();
PageAccess access = pageClass.getAnnotation(PageAccess.class);
fails because there are no annotations in 'page'. What am I doing wrong?
/Andreas
On 10 mar 2008, at 20.20, Filip S. Adamsen wrote:

Hi,

The logical page name is available in the parameters passed to your
filter. You can then use the ComponentSource to get at the actual
class using the logical page name and extract whatever info you'd
like - I use this service along with annotations on my page classes:

public class PageAccessCheckerImpl
  implements PageAccessChecker {

private final SecurityService securityService;
private final ComponentSource componentSource;

public PageAccessCheckerImpl(SecurityService securityService,
ComponentSource componentSource) {
  this.securityService = securityService;
  this.componentSource = componentSource;
}

public void checkPageAccess(PageRenderRequestParameters parameters) {
  checkPageAccess(parameters.getLogicalPageName());
}

public void checkPageAccess(ComponentEventRequestParameters
parameters) {
  checkPageAccess(parameters.getActivePageName());
}

private void checkPageAccess(String pageName) {
  Component page = componentSource.getPage(pageName);
  Secured secured = page.getClass().getAnnotation(Secured.class);

  if (null == secured) return;
  if (!securityService.isUserLoggedIn()) throw new
LoginRequiredException();
  if (!securityService.isUserInRole(secured.value())) throw new
AccessForbiddenException();
}
}

I then handle the exceptions in my handlers and redirect to another
page if necessary.

-Filip

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to