Skip to content

Conversation

@cklein05
Copy link
Contributor

Add support for additional user attributes to the TomcatPrincipal interface and the GenericPrincipal class.

Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first and foremost question I have: Is this save to be backported to previous Tomcat versions?

* <p>
* Attribute names and naming conventions are maintained by the Tomcat
* components that contribute to this map, like some of the Realm
* implementations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those really maintained? I thought the dev/admin requests the realm to load attribute values. So the attribute names are not necessarily mandated?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know whether it's really the exact word. However, every attribute provider (aka Realm) can use it's own naming schema and conventions. Some may use prefixes (user.displayName) others may not, who knows. We make no rules or assumptions here but only refer to the each attribute provider's documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, when querying an attribute named "displayName", a Realm could add this under a key like "realm.displayName" or "user.displayName". For that, the (maybe custom) Realm may have a config option userAttributePrefix or this could even be hard-coded.

Such prefixes might make sense, if, in the future, for example, several components could contribute to the Principal's attributes (like the Authenticator or a new component SocialUserDataProvider querying user information from Facebook etc.).

@cklein05
Copy link
Contributor Author

Is this save to be backported to previous Tomcat versions?

It should be. I do not see any reasons why this cannot be backported.

@michael-o
Copy link
Member

Is this save to be backported to previous Tomcat versions?

It should be. I do not see any reasons why this cannot be backported.

The big question is here is whether the TomcatPrincipal is truly limited to our Realms and not intended to be used in custom Realms. Because if custom Realm will use this interface a mere Tomcat will break their implementations. @markt-asf Can we make this assumption that this is Tomcat private?

@cklein05
Copy link
Contributor Author

We could always remove the new attributes methods from the TomcatPricipal interface and work with class GenericPrincipal only. In other words, having these methods declared on the interface is not crucial for the enhancement. In that case, we just need to update the instanceof check in the modified JSP example at /examples/jsp/security/protected as well as the documentation (and example code) under Common Features / Additional User Attributes in realm-howto.xml (both not yet committed).

BTW, shouldn't we commit/merge the example mentioned above with this PR? Listing the Principal's additional attributes is completely independent from the Realm implementations. The same is likely true for the new Common Features / Additional User Attributes section in realm-howto.xml.

@markt-asf
Copy link
Contributor

If we limit the back-port to Tomcat 9+, we are on Java 8 and can use default methods to maintain compatibility.

@cklein05
Copy link
Contributor Author

If we limit the back-port to Tomcat 9+, we are on Java 8 and can use default methods to maintain compatibility.

I guess, that's the way to go. Shall I implement these in my branch already? However, I will commit all changes only after we've agreed on all open questions.

@michael-o
Copy link
Member

@cklein05 Please apply all requested changes. I want to merge with main and proceed with Tomcat 9+ as @markt-asf has written.

@cklein05
Copy link
Contributor Author

cklein05 commented Feb 7, 2022

What about the example JSP application? Shouldn't we add support for dumping user attributes with this commit? See #463 (comment) (2nd paragraph)

@michael-o
Copy link
Member

michael-o commented Feb 7, 2022

What about the example JSP application? Shouldn't we add support for dumping user attributes with this commit? See #463 (comment) (2nd paragraph)

Personally, I wouldn't do this. This will limit the semantics of your PR, taking away to work with interface only. My custom principal uses this one as well so Tomcat can internally use the provided methods otherwise it feels foreign to Tomcat.

@cklein05
Copy link
Contributor Author

cklein05 commented Feb 7, 2022

I'm not talking about removing methods from the interface. In the 2nd paragraph of this comment I was asking whether to include the additions to Tomcat's example JSP application located under /examples/jsp/security/protected. The modified example application supports showing any additional user attributes of the authenticated Principal.

@michael-o
Copy link
Member

I'm not talking about removing methods from the interface. In the 2nd paragraph of this comment I was asking whether to include the additions to Tomcat's example JSP application located under /examples/jsp/security/protected. The modified example application supports showing any additional user attributes of the authenticated Principal.

My bad, yes. Please reuse the example as well.

@cklein05
Copy link
Contributor Author

cklein05 commented Feb 7, 2022

Done.

@michael-o
Copy link
Member

@cklein05 The default methods are on not required on main since it is still bleeding edge, we can break API here. Default methods are required for backports to 9 and 10 only.

@cklein05
Copy link
Contributor Author

cklein05 commented Feb 7, 2022

Removed

@cklein05
Copy link
Contributor Author

cklein05 commented Feb 7, 2022

@michael-o Will provide a fix for Travis CI failed ASAP.

@michael-o
Copy link
Member

@michael-o Will provide a fix for Travis CI failed ASAP.

Thanks, will then run it locally.

@cklein05
Copy link
Contributor Author

cklein05 commented Feb 7, 2022

@michael-o Should be fine now.

michael-o pushed a commit to michael-o/tomcat that referenced this pull request Feb 8, 2022
@michael-o michael-o closed this in c3edf43 Feb 8, 2022
michael-o pushed a commit to michael-o/tomcat that referenced this pull request Feb 8, 2022
@michael-o
Copy link
Member

@cklein05 Please provide backport PRs for 10.0.x and 9.0.x with default methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants