FISH-5769 RFC2253 format with Certificate HAM, fix role verification #5515
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is a bug fix.
The problem: When authenticated using @CertificateAuthenticationMechanismDefinition and IdentityStore @CertificateIdentityStoreDefinition, and when a role is mapped to a particular certificate principal in payara-web.xml, the role isn't assigned to the authenticated user. The role is applied if CLIENT_CERT login config mechanism is defined in web.xml.
Proposed solution in this PR:
JaccWebAuthorizationManager
, if the role isn’t granted (potentially because of the mismatch betweenPrincipalImpl
andCallerPrincipal
), check if the current principal class isCallerPrincipal
. If that's true, convert it toPrincipalImpl
and check for the role againCertificateCredentialImpl
, change how theCallerPrincipal
is created so that it contains the name in the sameRFC2253
thatPrincipalImpl
uses so that it’s equal with the one in the policy. This will ensure that thePrincipalImpl
created fromCallerPrincipal
is equal to the one in the policyImportant Info
Testing
Manually tested with the reproducer attached to FISH-5769
Testing Environment
Ubuntu
Notes for Reviewers
The policy in
JaccWebAuthorizationManager
contains the same role policies as in the working case (when using Servlet authentication). These are stored in the filegenerated/policy/payara-certificate-realm/payara-certificate-realm/granted.policy
. These policies are for principal classPrincipalImpl
but, if Jakarta Security authentication is used, the passedProtectionDomain
with the authenticated user contains a principal of typeCallerPrincipal
from Jakarta Security API. Thepolicy
object then refuses to add a policy for the role because it doesn’t match the authenticated user principal.There are more observations:
CallerPrincipal
class doesn’t overridehashCode
andequals
methods, therefore even 2 instances with the same principal name are not equal. So it doesn’t help if an additional role policy forCallerPrincipal
is added to thegranted.policy
fileCallerPrincipal
has a slightly different name than thePrincipalImpl
. Both contain the certificate's distinguished name but it's inRFC2253
format forPrincipalImpl
and inRFC1779
format forCallerPrincipal
. For this reason, even if we somehow convertedCallerPrincipal
toPrincipalImpl
, they wouldn't be equal unless we also convert the format of the principal's name. TheRFC1779
format contains more spaces between attributes and is obsolete.