Using getTemplate in JSP requires user to be logged in? | Community
Skip to main content
Level 3
Aug 22, 2016 1:10 PM UTC
Solved

Using getTemplate in JSP requires user to be logged in?

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.
squid267Accepted solution
Level 3
Aug 22, 2016 2:07 PM UTC

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

joerghoh
Employee
Mar 13, 2019 8:50 PM UTC

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.

Translate
Level 3
Mar 13, 2019 9:51 AM UTC

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?

Translate
joerghoh
Employee
Mar 12, 2019 5:14 PM UTC

No :-)

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

Translate
Level 3
Mar 12, 2019 5:08 PM UTC

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

Translate
joerghoh
Employee
Mar 12, 2019 5:04 PM UTC

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

Translate
VeenaVikraman
New Participant
Mar 12, 2019 3:04 PM UTC

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.

Translate
Level 3
Mar 12, 2019 1:48 PM UTC

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?

Translate
Feike_Visser1
Employee
Aug 22, 2016 2:25 PM UTC

Basically: avoid using getTemplate()

Translate
smacdonald2008
Level 10
Aug 22, 2016 2:10 PM UTC

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. 

Translate
squid267AuthorAccepted solution
Level 3
Aug 22, 2016 2:07 PM UTC

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.

Translate