[MGNLSTK-533] pur integration in templating kit breaks with external users. Created: 20/Nov/09  Updated: 17/Dec/10  Resolved: 17/Dec/10

Status: Closed
Project: Magnolia Standard Templating Kit (closed)
Component/s: paragraphs
Affects Version/s: None
Fix Version/s: 1.2.2, 1.2.3, 1.3

Type: Bug Priority: Major
Reporter: Rico Jansen Assignee: Federico Grilli
Resolution: Outdated Votes: 0
Labels: vpro
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Attachments: Text File freemarker-user-unsupportedexception.patch     File link-ftl.patch     File user-model.patch    
Issue Links:
relation
is related to MGNLSTK-727 Freemarker exception for demo-project... Closed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
MGNLSTK-568 Revert MGNLSTK-533 for 1.3 Sub-task Closed Federico Grilli  
Template:
Acceptance criteria:
Empty
Date of First Response:

 Description   

I have an issue with an exception that occurs when I log in with an LDAP account,
the adminInterface works fine , but the site gives an exception:

2009-11-20 11:00:31,969 ERROR freemarker.runtime :
Method public java.lang.String info.magnolia.cms.security.ExternalUser.getProperty(java.lang.String) threw an exception when invoked on info.magnolia.cms.security.ExternalUser@11fde0
The problematic instruction:
----------
==> assignment: userFullName=ctx.user.getProperty("title")!userName [on line 4, column 1 in templating-kit/paragraphs/pur/link.ftl]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Method public java.lang.String info.magnolia.cms.security.ExternalUser.getProperty(java.lang.String) threw an exception when invoked on info.magnolia.cms.security.ExternalUser@11fde0
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.DefaultToExpression._getAsTemplateModel(DefaultToExpression.java:100)

Caused by: java.lang.UnsupportedOperationException: not implemented for this ExternalUser
at info.magnolia.cms.security.ExternalUser.getProperty(ExternalUser.java:155)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

It seems that the / templating-kit/paragraphs/pur/link.ftl tries to get the fullname from an external user:

assign userFullName = ctx.user.getProperty("title")!userName

But ExternalUser has this as
its getProperty:

public String getProperty(String propertyName)

{ throw new UnsupportedOperationException("not implemented for this ExternalUser"); }

I am currently runing Magnolia Enterprise Edition 4.1RC1 and
Templating Kit Standard 1.2RC2 , Extended 1.2RC1



 Comments   
Comment by Philipp Bärfuss [ 12/Jan/10 ]

I will change the paragraph in a way that the UnsupportedOperationException is handled nicely (falling back on the username instead).

Note: You could implement an ExternalUser subclass which would support reading this information from the LDAP server.

Comment by Rico Jansen [ 12/Jan/10 ]

That will do the trick.

About implementing my own ExternalUser subclass, it looks that would imply creating my own ExternalUserManager as well.
Which would require some ldap support class to do the extra attribute fetches.

Comment by Magnolia International [ 25/Jan/10 ]

For the record, ctx.user.title should work just as well as ctx.user.getProperty('title'), thanks to info.magnolia.freemarker.models.UserModel. I don't suppose this will handle the UnsupportedOperationException any better, though.

edit: we could modify info.magnolia.freemarker.models.UserModel so that it handles these UnsupportedOperationException.. (so you could do ctx.user.title!ctx.user.name in this case), but I'm afraid that would only hide the problem further. On the other hand, it would simplify the templates, and wouldn't require a templating model class just for the sake of getting a user's full name.

Comment by Magnolia International [ 25/Jan/10 ]

Here's patch for the above - if we go for this solution - copy/move issue to MAGNOLIA with appropriate description. If we want this in STK 1.2.2, we'll need to merge this into the 4.2 branch as well. (should not be an issue)

Comment by Federico Grilli [ 25/Jan/10 ]

Another way to do this would be to have a model class (something like info.magnolia.module.templatingkit.paragraphs.UserModel) in stk for stkPURLink paragraph which would handle the exception in a graceful manner. However, this would imply also to change the link.ftl template and replace all occurrences of ctx.user with model. I'm going to attach a couple of patches for this.

Comment by Magnolia International [ 25/Jan/10 ]

Okay, those approaches are not mutually exclusive, so please apply those patches (along with the necessary update tasks) on the 1.2 branch and the trunk - the change I'm proposing would require re-releasing the main Magnolia project and bundles from the 4.2 branches, which isn't planned for now.

edit:
------

  • user-model.patch : please rename the class to something less ambiguous - UserAwareModel ? Please rename get*() methods to getUser*() - to avoid confusion, especially if this class gets extended
  • link-ftl.patch - how can model.title work? According to the patch above, it should be model.getProperty('title'), no?
  • please outline any duplication we could get rid of at a later stage (I'm pretty sure there is at least one implementation of an isAnonymous() method somewhere, rendering this {{[if .name == "anonymous"]} redundant.)
Comment by Federico Grilli [ 27/Jan/10 ]

returns the username in case a User implementation throws a UnsupportedOperationException when calling user.getProperty("title")

Comment by Rico Jansen [ 29/Jan/10 ]

Updated our pom's and tested it. It works like a charm.

Comment by Magnolia International [ 29/Jan/10 ]

We need to re-fix this. Updates will work (update task will add the modelClass), but fresh install will break! (we forgot to update the bootstrap file!)

Comment by Nils Breunese [ 29/Jan/10 ]

Yep, it works on updates, not on fresh installs. Just ran into that problem...

Comment by Nils Breunese [ 03/Feb/10 ]

After upgrading to STK 1.2.3 this problem still seems to be present when using the commenting module with external users (LDAP).


Method public java.lang.String info.magnolia.cms.security.ExternalUser.getProperty(java.lang.String) threw an exception when invoked on info.magnolia.cms.security.ExternalUser@1d5d81a
The problematic instruction:
----------
==> ${ctx.user.getProperty('email')!''} [on line 93, column 89 in info/magnolia/module/commenting/frontend/comment.inc.ftl]
in user-directive messageform [on line 60, column 5 in info/magnolia/module/commenting/frontend/commentPreview.ftl]
----------

(...)

Caused by: java.lang.UnsupportedOperationException: not implemented for this ExternalUser

Comment by Magnolia International [ 03/Feb/10 ]

Hi Nils,

Argh. Good catch.
This is actually fixed more generally on the trunk, for 4.3. Not sure if we'll do a backport and re-release the 4.2 branch just yet.
If you felt adventurous, you could implement a info.magnolia.freemarker.models.MagnoliaModelFactory, register it under /server/rendering/freemarker/modelFactories. You could implement such a factory/modelwrapper based on the current trunk info.magnolia.freemarker.models.UserModel - by just copying that class, and making its factory class non-anonymous, you should be able to configure it.

I'll try to come back to you in a couple of days to see if we can fix this in the 4.2 branch and potentially re-release it - don't hesitate to ping us about it.

Comment by Nils Breunese [ 04/Feb/10 ]

According to my colleague (who is working on the commenting, but not at work today) the email field should be mapped from LDAP, so it's too bad that the method throws an UnsupportedOperationException.

We plan on going live with our first Magnolia-powered site in March and it would be nice if this could be fixed before then...

Comment by Magnolia International [ 04/Feb/10 ]

Nils, let's take this discussion to the users list

Comment by Teresa Miyar [ 21/Apr/10 ]

Seems is not fixed for 4.3.1, stk 1.3, problem reported by rtr

Method public java.lang.String info.magnolia.cms.security.ExternalUser.getProperty(java.lang.String) threw an exception when invoked on info.magnolia.cms.security.ExternalUser@1db2f57
The problematic instruction:
==> assignment: userFullName=ctx.user.getProperty("title")!userName [on line 4, column 1 in templating-kit/paragraphs/pur/link.ftl]

Comment by Teresa Miyar [ 21/Apr/10 ]

the problem i think, info.magnolia.freemarker.models.MagnoliaModelFactory, is never registered, never used

Comment by Magnolia International [ 21/Apr/10 ]

This has been solved "properly" by MGNLSTK-568 / MAGNOLIA-3037. The fix here was only a temporary workaround.

MagnoliaModelFactory is an interface; its implementations are used by i.m.freemarker.models.MagnoliaObjectWrapper.

... but that's correct. ${ctx.user.getProperty("foobar")!'default value'} still causes exceptions. With MAGNOLIA-3037, one can now do ${ctx.user.foobar!'default value'}. As of now, I'm sure if we should re-fix MAGNOLIA-3037 to handle the method call case too, or if we should fix the template.

Comment by Magnolia International [ 17/Dec/10 ]

See MGNLSTK-727

Generated at Mon Feb 12 07:27:57 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.