{"record":{"id":"b9c02cbc8b4b64d7","repo":"spring-projects/spring-security","slug":"unable-to-resolve-builder-for-b9c02c","errorCode":null,"errorMessage":"Unable to resolve Builder for ","messagePattern":"Unable to resolve Builder for ","errorType":"exception","errorClass":"Saml2Exception","httpStatus":null,"severity":"error","filePath":"saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/web/authentication/OpenSaml5Template.java","lineNumber":132,"sourceCode":"import org.springframework.security.saml2.core.Saml2ParameterNames;\nimport org.springframework.security.saml2.core.Saml2X509Credential;\nimport org.springframework.util.Assert;\nimport org.springframework.web.util.UriComponentsBuilder;\nimport org.springframework.web.util.UriUtils;\n\n/**\n * For internal use only. Subject to breaking changes at any time.\n */\n@NullMarked\nfinal class OpenSaml5Template implements OpenSamlOperations {\n\n\tprivate static final Log logger = LogFactory.getLog(OpenSaml5Template.class);\n\n\t@Override\n\tpublic <T extends XMLObject> T build(QName elementName) {\n\t\tXMLObjectBuilder<?> builder = XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(elementName);\n\t\tif (builder == null) {\n\t\t\tthrow new Saml2Exception(\"Unable to resolve Builder for \" + elementName);\n\t\t}\n\t\treturn (T) builder.buildObject(elementName);\n\t}\n\n\t@Override\n\tpublic <T extends XMLObject> T deserialize(String serialized) {\n\t\treturn deserialize(new ByteArrayInputStream(serialized.getBytes(StandardCharsets.UTF_8)));\n\t}\n\n\t@Override\n\tpublic <T extends XMLObject> T deserialize(InputStream serialized) {\n\t\ttry {\n\t\t\tParserPool pool = XMLObjectProviderRegistrySupport.getParserPool();\n\t\t\tAssert.notNull(pool, \"ParserPool must be configured\");\n\t\t\tDocument document = pool.parse(serialized);\n\t\t\tElement element = document.getDocumentElement();\n\t\t\tUnmarshallerFactory factory = XMLObjectProviderRegistrySupport.getUnmarshallerFactory();\n\t\t\tUnmarshaller unmarshaller = factory.getUnmarshaller(element);","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/web/authentication/OpenSaml5Template.java#L114-L150","documentation":"OpenSaml5Template.build() looks up an OpenSAML XMLObjectBuilder for the given element QName via the global XMLObjectProviderRegistry. OpenSAML throws this Saml2Exception when no builder has been registered for that element name, meaning the corresponding OpenSAML module's ObjectProvider init was never run or the QName is not a recognized SAML element. Spring Security cannot construct the requested XMLObject, so it fails fast instead of returning null.","triggerScenarios":"Calling OpenSaml5Template.build(QName) with an element name for which XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(elementName) returns null — e.g. a QName whose namespace/qualified name does not match any registered SAML object provider.","commonSituations":"Using a custom or misspelled QName; calling build() before OpenSAML's InitializationService/global registry was initialized (typically done by OpenSamlInitializationService.initialize()); mixing OpenSAML 4 and 5 jars on the classpath so providers register under a different registry; using an element from a SAML profile (e.g. ECP, metadata extensions) whose module is not initialized.","solutions":["Call OpenSamlInitializationService.initialize() (or ensure the OpenSAML InitializationService runs) before using OpenSaml5Template so all default object providers are registered.","Verify the QName's namespace URI and local part exactly match a SAML element (e.g. Assertion.DEFAULT_ELEMENT_NAME) rather than a hand-built QName.","Check for conflicting OpenSAML versions on the classpath (only opensaml-core/opensaml-xmlsec etc. v5 should be present) and re-run the provider registration.","If using a custom element, register its builder via the XMLObjectProviderRegistry (XMLObjectProviderRegistrySupport.getRegistry().registerObjectProvider(...))."],"exampleFix":"// before\nQName name = new QName(\"Assertion\"); // no namespace -> unresolvable\nAssertion a = template.build(name);\n\n// after\nOpenSamlInitializationService.initialize();\nAssertion a = template.build(Assertion.DEFAULT_ELEMENT_NAME); // canonical QName with SAML namespace","handlingStrategy":"validation","validationCode":"OpenSamlInitializationService.initialize();\nif (XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(elementName) == null) {\n    throw new IllegalStateException(\"No OpenSAML builder registered for \" + elementName);\n}","typeGuard":null,"tryCatchPattern":"try { T obj = template.build(elementName); } catch (Saml2Exception ex) { log.error(\"Builder missing for {}\", elementName, ex); throw ex; }","preventionTips":["Call OpenSamlInitializationService.initialize() at application startup","Always use *.DEFAULT_ELEMENT_NAME constants instead of hand-built QNames","Keep a single OpenSAML 5 version on the classpath"],"tags":["saml","opensaml","spring-security","initialization","builder-lookup"],"backgroundTag":"module-init-failed","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}