{"record":{"id":"3c9dddb1069b11da","repo":"apereo/cas","slug":"metadata-directory-location-cannot-be-located-cre","errorCode":null,"errorMessage":"Metadata directory location  cannot be located/created","messagePattern":"Metadata directory location  cannot be located/created","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"critical","filePath":"support/cas-server-support-saml-idp-core/src/main/java/org/apereo/cas/support/saml/idp/metadata/locator/FileSystemSamlIdPMetadataLocator.java","lineNumber":139,"sourceCode":"        }\n        initializeMetadataDirectory();\n        val resource = ResourceUtils.toFileSystemResource(new File(this.metadataLocation, artifactName));\n        if (resource.exists() && resource.isReadable()) {\n            val content = FileUtils.readFileToString(resource.getFile(), StandardCharsets.UTF_8);\n            if (StringUtils.isNotBlank(content)) {\n                return resolveContentToResource(content);\n            }\n            LOGGER.warn(\"Metadata artifact at [{}] is empty and invalid and will be deleted\", resource);\n            FileUtils.deleteQuietly(resource.getFile());\n        }\n        return ResourceUtils.toFileSystemResource(resource.getFile());\n    }\n\n    protected void initializeMetadataDirectory() {\n        if (!this.metadataLocation.exists()) {\n            LOGGER.debug(\"Metadata directory [{}] does not exist. Creating...\", this.metadataLocation);\n            if (!this.metadataLocation.mkdir()) {\n                throw new IllegalArgumentException(\"Metadata directory location \" + this.metadataLocation + \" cannot be located/created\");\n            }\n        }\n    }\n}\n","sourceCodeStart":121,"sourceCodeEnd":144,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-saml-idp-core/src/main/java/org/apereo/cas/support/saml/idp/metadata/locator/FileSystemSamlIdPMetadataLocator.java#L121-L144","documentation":"FileSystemSamlIdPMetadataLocator.initializeMetadataDirectory() ensures the configured on-disk metadata directory exists. If the directory does not exist and File.mkdir() fails (e.g. parent missing, permissions), it throws IllegalArgumentException stating the location cannot be located or created. Called from initialize() and getMetadataArtifact().","triggerScenarios":"metadataLocation (cas.authn.samlIdp.metadata.file-system.location) does not exist and mkdir() returns false — parent directory absent (mkdir is not mkdirs), insufficient write permission, or path is a file.","commonSituations":"Configured location points several levels deep where no parent exists; running CAS as a non-root user without write access to the path; container volume not mounted; path accidentally set to a file.","solutions":["Pre-create the directory including parents: mkdir -p /path/to/metadata, and ensure the CAS process user owns/can write it.","Set the location to an existing, writable directory in cas.authn.samlIdp.metadata.file-system.location.","If running in a container, verify the volume mount exists and its permissions allow the CAS user to write.","Check the path isn't an existing regular file; remove/rename it so the directory can be created."],"exampleFix":"// before\ncas.authn.samlIdp.metadata.file-system.location=/etc/cas/saml/metadata/idp   // parents missing, no perms\n\n// after\nsudo mkdir -p /etc/cas/saml/metadata/idp && sudo chown cas:cas /etc/cas/saml/metadata/idp\ncas.authn.samlIdp.metadata.file-system.location=/etc/cas/saml/metadata/idp","handlingStrategy":"validation","validationCode":"// before starting CAS / configuring the locator\nPath loc = Path.of(location);\nif (!Files.isDirectory(loc)) {\n    Files.createDirectories(loc); // creates parents, fails loudly on permission issues\n}\nif (!Files.isWritable(loc)) throw new IllegalStateException(\"Metadata dir not writable: \" + loc);","typeGuard":null,"tryCatchPattern":"try {\n    locator.initialize();\n} catch (IllegalArgumentException e) {\n    logger.error(\"Fix metadata dir at {}: {}\", configuredLocation, e.getMessage());\n}","preventionTips":["Provision the metadata directory in deployment scripts (mkdir -p + chown to CAS user).","Verify volume mounts in containers point at writable host paths.","Keep the configured path shallow and dedicated to metadata only."],"tags":["saml","idp","metadata","filesystem","mkdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}