Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Using getTemplate in JSP requires user to be logged in?

Avatar

Level 4

Hi

I know business logic in JSPs is bad, but I need to come up with a solution quickly with how the codebase was setup. Anyways, I wanted to execute code only on a certain template so I'm using 

currentPage.getTemplate().getTitle().equals("SomeTemplate")

 I could provide code context but I think its more of permissions issue than a code issue. It only works when I log in, and if I'm not logged in it breaks. What permission do I need to edit to fix this.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Feike Visser wrote...

This is a much easier way, without changing permissions:

  1. page.getProperties().get("cq:template","")

best,
Feike

 

 

Found this response in a different thread. Much better solution, and doesn't involve editing permissions.

View solution in original post

10 Replies

Avatar

Correct answer by
Level 4

Feike Visser wrote...

This is a much easier way, without changing permissions:

  1. page.getProperties().get("cq:template","")

best,
Feike

 

 

Found this response in a different thread. Much better solution, and doesn't involve editing permissions.

Avatar

Level 10

I know business logic in JSPs is bad

That is not necessarily the case - AEM gives you choice to use HTML Template Language or JSP.  It does not force you to use HTL. 

Avatar

Employee

Basically: avoid using getTemplate()

Avatar

Level 3

Hi guys, I realise this is an old post but I have encountered the same problem and I need a steer. Of course, the replacement of getTemplate() is the best solution but we have a site with an older code base that uses it extensively.

We have just implemented a user log-in system via Okta (which works well with SAML) but the Okta authenticated user immediately encounters problems with pages using any derivation of the getTemplate method.

Interestingly, our anonymous user does not have this issue. The Okta user is also added to the "everyone" group, just like the anonymous user.

What permissions would I need to add to the Okta user for them to access to this getTemplate() method?

Avatar

Community Advisor

If they are added to everyone , I assume , they have all the permissions available for anonymous user. Not sure what might be going wrong. Its been ages I have used getTemplate last time.

Avatar

Employee Advisor

you need to have read access to /apps, potentially read access to /libs as well.

Avatar

Level 3

OK, thank you so much for your reply! Is that "safe" do you think?

Avatar

Employee Advisor

No :-)

The lock down of /apps (anonymous is not allowed to read from there) in the product has been done for a reason.

Avatar

Level 3

OK! Thanks again for your continued support.

As a test, I have added the Okta user to read /apps on a non-production environment and it does the trick. But, from what you say, this is not a situation that should exist on Live.

What is the practical technical impact of the anonymous user have read access to apps?

Avatar

Employee Advisor

In practice I don't think that it has a huge impact (disclaimer: I am not a security guy, they will possibly see this much different). But it's always good to adhere to the guidelines of the product.