{"record":{"id":"98cec57814fa056c","repo":"spring-projects/spring-security","slug":"registration-not-found-98cec5","errorCode":null,"errorMessage":"registration not found","messagePattern":"registration not found","errorType":"exception","errorClass":"Saml2Exception","httpStatus":500,"severity":"error","filePath":"saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/metadata/RequestMatcherMetadataResponseResolver.java","lineNumber":127,"sourceCode":"\t\t}\n\t\tif (this.registrations instanceof IterableRelyingPartyRegistrationRepository iterable) {\n\t\t\treturn responseByIterable(request, iterable);\n\t\t}\n\t\tif (this.registrations instanceof Iterable<?>) {\n\t\t\tIterable<RelyingPartyRegistration> registrations = (Iterable<RelyingPartyRegistration>) this.registrations;\n\t\t\treturn responseByIterable(request, registrations);\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate @Nullable Saml2MetadataResponse responseByRegistrationId(HttpServletRequest request,\n\t\t\t@Nullable String registrationId) {\n\t\tif (registrationId == null) {\n\t\t\treturn null;\n\t\t}\n\t\tRelyingPartyRegistration registration = this.registrations.findByRegistrationId(registrationId);\n\t\tif (registration == null) {\n\t\t\tthrow new Saml2Exception(\"registration not found\");\n\t\t}\n\t\treturn responseByIterable(request, Collections.singleton(registration));\n\t}\n\n\tprivate Saml2MetadataResponse responseByIterable(HttpServletRequest request,\n\t\t\tIterable<RelyingPartyRegistration> registrations) {\n\t\tMap<String, RelyingPartyRegistration> results = new LinkedHashMap<>();\n\t\tfor (RelyingPartyRegistration registration : registrations) {\n\t\t\tRelyingPartyRegistrationPlaceholderResolvers.UriResolver uriResolver = RelyingPartyRegistrationPlaceholderResolvers\n\t\t\t\t.uriResolver(request, registration);\n\t\t\tString entityId = Objects.requireNonNull(uriResolver.resolve(registration.getEntityId()));\n\t\t\tresults.computeIfAbsent(entityId, (e) -> {\n\t\t\t\tString ssoLocation = uriResolver.resolve(registration.getAssertionConsumerServiceLocation());\n\t\t\t\tssoLocation = Objects.requireNonNull(ssoLocation);\n\t\t\t\tString sloLocation = uriResolver.resolve(registration.getSingleLogoutServiceLocation());\n\t\t\t\tString sloResponseLocation = uriResolver.resolve(registration.getSingleLogoutServiceResponseLocation());\n\t\t\t\treturn registration.mutate()\n\t\t\t\t\t.entityId(entityId)","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/metadata/RequestMatcherMetadataResponseResolver.java#L109-L145","documentation":"RequestMatcherMetadataResponseResolver.responseByRegistrationId looks up a RelyingPartyRegistration by the id matched from the metadata request URL. If the RelyingPartyRegistrationRepository has no such registration, it throws Saml2Exception('registration not found') instead of returning a null/404 response.","triggerScenarios":"A GET to the metadata endpoint (e.g. /saml2/service-provider-metadata/{registrationId}) whose registrationId path variable is not found via this.registrations.findByRegistrationId(registrationId), which returns null.","commonSituations":"Typo or wrong case in the metadata URL; metadata endpoint cached/bookmarked after the registration was renamed or removed; metadata published for an IdP-specific registration id that isn't configured; load balancer routing to an instance with different config.","solutions":["Correct the registrationId in the metadata URL to exactly match one configured in your RelyingPartyRegistrationRepository.","Add the missing RelyingPartyRegistration to the repository or use the no-arg/iterable resolve path so metadata is generated for all registrations.","If the registration was intentionally removed, update the IdP or clients requesting that metadata URL.","Wrap the metadata resolver in a handler that converts this exception to HTTP 404 for cleaner client behavior."],"exampleFix":"// before: URL requests an unconfigured id\n// GET /saml2/service-provider-metadata/idp-b (only 'idp-a' configured)\n// after: add or correct\nRelyingPartyRegistration idpB = RelyingPartyRegistration.withRegistrationId(\"idp-b\")\n        .entityId(\"https://idp.example.com/metadata\")\n        .singleSignOnServiceLocation(\"https://idp.example.com/SSO\")\n        .build();","handlingStrategy":"validation","validationCode":"String registrationId = /* extracted from metadata URL */;\nif (repository.findByRegistrationId(registrationId) == null) {\n    throw new ResponseStatusException(HttpStatus.NOT_FOUND, \"unknown registration \" + registrationId);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return metadataResolver.resolve(request);\n} catch (Saml2Exception ex) {\n    response.sendError(HttpServletResponse.SC_NOT_FOUND);\n    return null;\n}","preventionTips":["Generate metadata URLs from the configured registrationIds, never hardcode them.","Add a startup check that each expected registration resolves from the repository.","Purge cached/bookmarked metadata URLs after renaming registrations."],"tags":["saml2","spring-security","metadata","configuration"],"backgroundTag":"entity-not-found","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}