Using getTemplate in JSP requires user to be logged in? | Community
Skip to main content
Level 3
August 22, 2016
Solved

Using getTemplate in JSP requires user to be logged in?

  • August 22, 2016
  • 10 replies
  • 3432 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by squid267

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.

10 replies

squid267AuthorAccepted solution
Level 3
August 22, 2016

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.

smacdonald2008
Level 10
August 22, 2016

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. 

Feike_Visser1
Adobe Employee
Adobe Employee
August 22, 2016

Basically: avoid using getTemplate()

Level 3
March 12, 2019

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?

VeenaVikraman
Community Advisor
Community Advisor
March 12, 2019

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.

joerghoh
Adobe Employee
Adobe Employee
March 12, 2019

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

Level 3
March 12, 2019

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

joerghoh
Adobe Employee
Adobe Employee
March 12, 2019

No :-)

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

Level 3
March 13, 2019

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?

joerghoh
Adobe Employee
Adobe Employee
March 13, 2019

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.