NPE with 500 when generating zosmf token with client certificate authentication
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 92
- Forks
- 81
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 46
Description
Describe the bug
When integration test org.zowe.apiml.integration.zaas.ZosmfTokensTest.WhenGeneratingZosmfTokens_returnValidZosmfToken#givenX509Certificate
is executed in negative scenario - with a client certificate that is trusted, but not mapped to a user, a NPE occurs resulting in 500 return code.
Steps to Reproduce
- Prepare a trusted certificate, that is not mapped to a user.
- Update the environment configuration to use trusted, but unmapped certificate
- Run the integration test
Expected behavior
401 is expected
Logs
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.JwtAuthSourceService)) Getting JWT token from request.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.JwtAuthSourceService)) JWT token not found in request.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.PATAuthSourceService)) Getting JWT token from request.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.PATAuthSourceService)) JWT token not found in request.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.OIDCAuthSourceService)) Getting JWT token from request.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.OIDCAuthSourceService)) JWT token not found in request.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.X509AuthSourceService)) Getting X509 client certificate from custom attribute 'client.auth.X509Certificate'.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.X509AuthSourceService)) Validating X509 client certificate.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.X509AuthSourceService)) X509 client certificate found in request.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.DefaultAuthSourceService)) Authentication request towards the southbound service /zaas/scheme/zosmf using the auth source CLIENT_CERT
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.X509AuthSourceService)) Parsing X509 client certificate.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-
0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.X509AuthSourceService)) Validating X509 client certificate.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.m.NativeMapper)) CertificateResponse(userId=, rc=-1, errno=143, errno2=318833740)
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.s.s.X509AuthSourceService)) Validating X509 client certificate.
2025-01-13 12:38:14.775 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.s.s.w.FilterChainProxy)) Secured POST /zaas/scheme/zosmf
2025-01-13 12:38:14.776 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.l.Providers)) z/OSMF registered with the Discovery Service and propagated to ZAAS: true
2025-01-13 12:38:14.776 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.TokenCreationService)) ZOSMF is available and used. Attempt to authenticate with PassTicket
2025-01-13 12:38:14.776 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.s.s.TokenCreationService)) Generating PassTicket for user: null and ZOSMF applid: IZUDFLT
2025-01-13 12:38:14.776 <ZWEAZS1:https-jsse-nio-0.0.0.0-10018-exec-2:67174549> [35mZWESVUSR[0;39m [36mDEBUG[0;39m ((o.z.a.z.z.ZaasExceptionHandler)) Unexpected internal error
java.lang.NullPointerException: Cannot invoke "java.lang.String.toUpperCase()" because "userId" is null
at org.zowe.apiml.passticket.PassTicketService.generate(PassTicketService.java:50)
at org.zowe.apiml.zaas.security.service.TokenCreationService.generatePassTicket(TokenCreationService.java:105)
at org.zowe.apiml.zaas.security.service.TokenCreationService.createZosmfTokensWithoutCredentials(TokenCreationService.java:76)
at org.zowe.apiml.zaas.security.service.zosmf.ZosmfService.exchangeAuthenticationForZosmfToken(ZosmfService.java:244)
at jdk.internal.reflect.GeneratedMethodAccessor85.invoke(Unknown Source)
Details
- Version and build number: v3
- Test environment: miniplex
Additional context
Found during miniplex setup for integration tests
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with integration-tests/src/test/resources/environment-configuration.yml and org.zowe.apiml.integration.zaas.ZosmfTokensTest.WhenGeneratingZosmfTokens_returnValidZosmfToken#givenX509Certificate. Trace the unmapped certificate path through X509AuthSourceService, TokenCreationService, and PassTicketService.generate; run the integration test and confirm it returns 401 instead of a 500 caused by the null userId.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100